Skip to content

Commit

Permalink
Changes necessary to compile on arch linux (py38)
Browse files Browse the repository at this point in the history
To solve issue 39:

Removed old Find*.cmake files to use the ones provided by the
system libraries, and made necessary changes to multiple
CMakeLists.txt to use those. Switched to imported targets.

Changed imports of numpy in cpp files to be compatible with default
folder structure.

To solve issue37:

Modified setup.py to be compatible with pip 20.

Signed-off-by: Christian Aßfalg <cassfalg@users.noreply.github.com>
  • Loading branch information
cassfalg committed Sep 17, 2020
1 parent 697c09a commit e08b018
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
__pycache__/
27 changes: 2 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.14)
project(pptk)

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_CURRENT_SOURCE_DIR})

find_package(PythonLibs 2.7 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Numpy REQUIRED)
find_package(TBB REQUIRED)
find_package(Eigen REQUIRED)
find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets Network OpenGL Core)
find_package(OpenMP)

# get root Qt5 folder (i.e. contains bin, lib, plugins, etc.)
get_target_property(Qt5_DIR Qt5::qmake LOCATION)
get_filename_component(Qt5_DIR ${Qt5_DIR} DIRECTORY)
get_filename_component(Qt5_DIR ${Qt5_DIR} DIRECTORY)
set(Qt5_PLUGINS_DIR ${Qt5_DIR}/plugins)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

# localize all dependencies (.dll, .so, or .dylib) in the following folder
set(PPTK_LIBS_DIR ${PROJECT_BINARY_DIR}/pptk/libs)

# use the following variable to store a list of .dll paths required by targets
# built in pptk; this is useful only for building on Windows platform
get_filename_component(TBB_RUNTIME_DIR ${TBB_tbb_RUNTIME} DIRECTORY)
set(PPTK_DLL_DIRS
${TBB_RUNTIME_DIR}
${Qt5_DIR}/bin
CACHE INTERNAL "Additional folder paths for finding .dll's")

# use patchelf to modify binary RPATH when building pptk on Linux
if(UNIX AND NOT APPLE)
find_program(PPTK_PATCHELF patchelf)
Expand Down
5 changes: 0 additions & 5 deletions cmake/FindEigen.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions cmake/FindNumpy.cmake

This file was deleted.

16 changes: 0 additions & 16 deletions cmake/FindTBB.cmake

This file was deleted.

22 changes: 13 additions & 9 deletions cmake/UsefulMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ function(copy_target_dependencies x)
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${CMAKE_CURRENT_BINARY_DIR}/${_target_file_name} ${PPTK_LIBS_DIR})
elseif(UNIX)
find_file(helper_script CopyLinuxDependencies.cmake
PATHS ${CMAKE_MODULE_PATH} REQUIRED)
add_custom_command(TARGET ${x} POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyLinuxDependencies.cmake
COMMAND ${CMAKE_COMMAND} -P ${helper_script}
${_target_file}
${CMAKE_CURRENT_BINARY_DIR}/${_target_file_name}
${PPTK_LIBS_DIR} ${PPTK_PATCHELF})
unset(helper_script CACHE) # find_file creates a cache variable, this is temporary
endif()
endfunction()

Expand All @@ -65,22 +67,24 @@ endmacro()
function(copy_file x)
# x should be a file path, and should not be a variable
# i.e. copy_file(${var}), not copy_file(var)
get_filename_component(name ${x} NAME)
file(RELATIVE_PATH temp ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT (temp STREQUAL ""))
string(REGEX REPLACE "(/|\\\\)" "." temp "${temp}")
string(CONCAT name "${temp}" "." "${name}")
get_filename_component(filename ${x} NAME)
file(RELATIVE_PATH rel_path ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT (rel_path STREQUAL ""))
string(REGEX REPLACE "(/|\\\\)" "." rel_path "${rel_path}")
string(CONCAT target_name "${rel_path}" "." "${filename}")
else()
string(CONCAT target_name "${PROJECT_NAME}" "." "${filename}")
endif()
if (ARGC EQUAL 2)
set(${ARGV1} ${name} PARENT_SCOPE)
set(${ARGV1} ${target_name} PARENT_SCOPE)
endif()
if (NOT IS_ABSOLUTE ${x})
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${x})
else()
set(src ${x})
endif()
set(dst ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(${name} ALL
add_custom_target(${target_name} ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
COMMENT "Copying ${src} to ${dst}")
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion pptk/include/python_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstdint>
#include <vector>
#include "Python.h"
#include "arrayobject.h"
#include "numpy/arrayobject.h"

struct Array2D {
const unsigned char* data;
Expand Down
23 changes: 9 additions & 14 deletions pptk/kdtree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# # Uncomment the following lines to run as standalone cmake script
# cmake_minimum_required(VERSION 3.0)
# project(kdtree)
cmake_minimum_required(VERSION 3.14)
project(kdtree)

# set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake" ${CMAKE_CURRENT_SOURCE_DIR})
# find_package(PythonLibs 2.7 REQUIRED)
# find_package(Numpy REQUIRED)
# find_package(TBB REQUIRED)
# include(UsefulMacros)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(Python3 COMPONENTS Interpreter Development NumPy)
find_package(TBB COMPONENTS tbb tbbmalloc REQUIRED)
include(UsefulMacros)

add_library(kdtree SHARED kdtree_wrapper.cpp)
set_target_python_module_name(kdtree)
Expand All @@ -24,12 +23,8 @@ target_compile_definitions(kdtree PRIVATE -DUSE_TBB)
target_include_directories(kdtree PRIVATE
../include # for python_util.h
src # for k-d tree source code
${TBB_INCLUDE_DIR}
${PYTHON_INCLUDE_DIR}
${Numpy_INCLUDE_DIR} )
target_link_libraries(kdtree
${TBB_tbb_LIBRARY}
${TBB_tbbmalloc_LIBRARY})
)
target_link_libraries(kdtree Python3::NumPy TBB::tbb TBB::tbbmalloc)
copy_target(kdtree)
copy_target_dependencies(kdtree)
copy_file(__init__.py)
Expand Down
21 changes: 11 additions & 10 deletions pptk/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function(copy_system_file x)
if(ARGC EQUAL 2)
set(y ${ARGV1})
endif()
find_file(temp ${x} ${y})
copy_file(${temp} _target)
find_file(file_loc ${x} PATHS ${y} REQUIRED)
copy_file(${file_loc} _target)
if(UNIX AND NOT APPLE)
add_custom_command(TARGET ${_target} POST_BUILD COMMAND
${PPTK_PATCHELF} --set-rpath \\\$\$ORIGIN
${CMAKE_CURRENT_BINARY_DIR}/${x})
endif()
unset(temp CACHE)
unset(file_loc CACHE) # find_file creates a cache variable, this is temporary
endfunction()

function(copy_import_target x)
Expand All @@ -35,13 +35,14 @@ elseif (APPLE)
elseif (UNIX)
# create local copies of system libraries that are required by pptk targets
# but not provided by a bare bone manylinux1 platform, as specified in PEP 513
if (CMAKE_LIBRARY_ARCHITECTURE)
set(_paths
/lib/${CMAKE_LIBRARY_ARCHITECTURE}
/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE})
endif()
copy_system_file(libgomp.so.1 "${_paths}")
copy_system_file(libz.so.1 "${_paths}")
find_package(OpenMP REQUIRED)
get_filename_component(gomp_file ${OpenMP_gomp_LIBRARY} NAME)
get_filename_component(gomp_path ${OpenMP_gomp_LIBRARY} DIRECTORY)
copy_system_file(${gomp_file} ${gomp_path})
find_package(ZLIB REQUIRED)
get_filename_component(zlib_file ${ZLIB_LIBRARY} NAME)
get_filename_component(zlib_path ${ZLIB_LIBRARY} DIRECTORY)
copy_system_file(${zlib_file} ${zlib_path})
endif()

add_subdirectory(qt_plugins)
4 changes: 3 additions & 1 deletion pptk/libs/qt_plugins/platforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ if(WIN32)
elseif (APPLE)
copy_file_with_dependencies(${Qt5_PLUGINS_DIR}/platforms/libqcocoa.dylib)
elseif (UNIX)
copy_file_with_dependencies(${Qt5_PLUGINS_DIR}/platforms/libqxcb.so)
find_package(Qt5 COMPONENTS Gui REQUIRED)
get_target_property(xcb_loc Qt5::QXcbIntegrationPlugin LOCATION)
copy_file_with_dependencies(${xcb_loc})
endif()
9 changes: 5 additions & 4 deletions pptk/libs/qt_plugins/xcbglintegrations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if(UNIX AND NOT APPLE)
copy_file_with_dependencies(
${Qt5_PLUGINS_DIR}/xcbglintegrations/libqxcb-egl-integration.so)
copy_file_with_dependencies(
${Qt5_PLUGINS_DIR}/xcbglintegrations/libqxcb-glx-integration.so)
find_package(Qt5 COMPONENTS Gui REQUIRED)
get_target_property(xcb_egl_loc Qt5::QXcbEglIntegrationPlugin LOCATION)
copy_file_with_dependencies(${xcb_egl_loc})
get_target_property(xcb_glx_loc Qt5::QXcbGlxIntegrationPlugin LOCATION)
copy_file_with_dependencies(${xcb_glx_loc})
endif()
30 changes: 13 additions & 17 deletions pptk/processing/estimate_normals/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# # Uncomment the following lines to run as standalone cmake script
# cmake_minimum_required(VERSION 3.0)
# project(estimate_normals)
cmake_minimum_required(VERSION 3.14)
project(estimate_normals)

# set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_CURRENT_SOURCE_DIR})
# find_package(PythonLibs 2.7 REQUIRED)
# find_package(Numpy REQUIRED)
# find_package(TBB REQUIRED)
# find_package(Eigen REQUIRED)
# include(UsefulMacros)
# include(FindOpenMP)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(Python3 COMPONENTS Interpreter Development NumPy)
find_package(Eigen3 REQUIRED)
find_package(TBB COMPONENTS tbb tbbmalloc REQUIRED)
find_package(OpenMP REQUIRED)
include(UsefulMacros)

add_library(estimate_normals SHARED estimate_normals.cpp)
set(_link_flags ${OpenMP_CXX_FLAGS})
Expand All @@ -24,16 +23,13 @@ set_target_properties(estimate_normals PROPERTIES
LINK_FLAGS ${_link_flags})
set_target_python_module_name(estimate_normals)
target_compile_definitions(estimate_normals PRIVATE -DUSE_TBB)
target_link_libraries(estimate_normals
${TBB_tbb_LIBRARY}
${TBB_tbbmalloc_LIBRARY})
target_link_libraries(estimate_normals Python3::NumPy Eigen3::Eigen
TBB::tbb TBB::tbbmalloc
)
target_include_directories(estimate_normals PRIVATE
../../include # for python_util.h
../../kdtree/src # for kdtree.h
${Eigen_INCLUDE_DIR}
${PYTHON_INCLUDE_DIR}
${TBB_INCLUDE_DIR}
${Numpy_INCLUDE_DIR})
)
copy_target(estimate_normals)
copy_target_dependencies(estimate_normals)
copy_file(__init__.py)
Expand Down
2 changes: 1 addition & 1 deletion pptk/processing/estimate_normals/estimate_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <limits>
#include <vector>
#include "Python.h"
#include "arrayobject.h"
#include "numpy/arrayobject.h"
#include "kdtree.h"
#include "progress_bar.h"
#include "python_util.h"
Expand Down
20 changes: 9 additions & 11 deletions pptk/vfuncs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# # Uncomment the following lines to run as standalone cmake script
# cmake_minimum_required(VERSION 3.0)
# project(vfuncs)
cmake_minimum_required(VERSION 3.14)
project(vfuncs)

# set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake" ${CMAKE_MODULE_PATH})
# find_package(PythonLibs 2.7 REQUIRED)
# find_package(Numpy REQUIRED)
# find_package(Eigen REQUIRED)
# include(UsefulMacros)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(Python3 COMPONENTS Interpreter Development NumPy)
find_package(Eigen3 REQUIRED)
include(UsefulMacros)

add_library(vfuncs SHARED vfuncs.cpp)
target_link_libraries(vfuncs Eigen3::Eigen Python3::Python Python3::NumPy)
set_target_python_module_name(vfuncs)
if(WIN32)
target_link_libraries(vfuncs ${PYTHON_LIBRARY})
Expand All @@ -21,9 +21,7 @@ elseif(UNIX)
endif()
target_include_directories(vfuncs PRIVATE
../include # for python_util.h
${PYTHON_INCLUDE_DIR}
${Eigen_INCLUDE_DIR}
${Numpy_INCLUDE_DIR})
)
copy_target(vfuncs)
copy_target_dependencies(vfuncs)
copy_file(__init__.py)
Expand Down
2 changes: 1 addition & 1 deletion pptk/vfuncs/vfuncs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Python.h"
#include "arrayobject.h"
#include "numpy/arrayobject.h"
#define EIGEN_NO_DEBUG // comment this for runtime assertions
#include <algorithm>
#include <functional>
Expand Down
21 changes: 11 additions & 10 deletions pptk/viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# # Uncomment the following lines to run as standalone cmake script
# cmake_minimum_required(VERSION 2.8.11)
# project(viewer)
cmake_minimum_required(VERSION 3.14)
project(viewer)

# set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake" ${CMAKE_MODULE_PATH})
# find_package(Eigen REQUIRED)
# find_package(OpenGL REQUIRED)
# find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets Network OpenGL Core)
# include(UsefulMacros)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(Eigen3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets Network OpenGL Core)
include(UsefulMacros)

add_executable(viewer
main.cpp
Expand All @@ -28,8 +28,9 @@ add_executable(viewer
point_attributes.h)

set_target_properties(viewer PROPERTIES AUTOMOC TRUE)
target_link_libraries(viewer Qt5::Widgets Qt5::Network Qt5::OpenGL ${OPENGL_gl_LIBRARY})
target_include_directories(viewer PRIVATE ${Eigen_INCLUDE_DIR} )
target_link_libraries(viewer OpenGL Qt5::Widgets Qt5::Network Qt5::OpenGL
Eigen3::Eigen)
target_include_directories(viewer PRIVATE )
copy_target(viewer)
copy_target_dependencies(viewer)
copy_file(viewer.py)
Expand Down
15 changes: 7 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import shutil
import platform

from pip._internal import wheel
import packaging.tags

wheel_tags = wheel.pep425tags.get_supported()[0]

system_type = platform.system()
sys_tag = packaging.tags.sys_tags().__next__()
system_type = sys_tag.platform

license_text = b''
with open('LICENSE', 'rb') as fd:
Expand All @@ -23,7 +22,7 @@
def make_mod(x):
if system_type == 'Windows':
return x + '.pyd'
elif system_type == 'Linux':
elif "linux" in system_type.lower():
return x + '.so'
elif system_type == 'Darwin':
return x + '.so'
Expand All @@ -34,7 +33,7 @@ def make_mod(x):
def make_lib(x, version_suffix=''):
if system_type == 'Windows':
return x + '.dll'
elif system_type == 'Linux':
elif "linux" in system_type.lower():
return 'lib' + x + '.so' + version_suffix
elif system_type == 'Darwin':
return 'lib' + x + '.dylib'
Expand Down Expand Up @@ -85,5 +84,5 @@ def list_libs():
'pptk.vfuncs': [make_mod('vfuncs')],
'pptk.viewer': [make_exe('viewer'), 'qt.conf']},
options={'bdist_wheel': {
'python_tag': wheel_tags[0],
'plat_name': wheel_tags[2]}})
'python_tag': sys_tag.interpreter,
'plat_name': sys_tag.platform}})

0 comments on commit e08b018

Please sign in to comment.