From e08b0184f2e5c5e288f1ff030cf09d11c8864ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20A=C3=9Ffalg?= Date: Thu, 17 Sep 2020 15:15:26 +0200 Subject: [PATCH] Changes necessary to compile on arch linux (py38) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .gitignore | 2 ++ CMakeLists.txt | 27 ++--------------- cmake/FindEigen.cmake | 5 ---- cmake/FindNumpy.cmake | 5 ---- cmake/FindTBB.cmake | 16 ---------- cmake/UsefulMacros.cmake | 22 ++++++++------ pptk/include/python_util.h | 2 +- pptk/kdtree/CMakeLists.txt | 23 ++++++-------- pptk/libs/CMakeLists.txt | 21 ++++++------- pptk/libs/qt_plugins/platforms/CMakeLists.txt | 4 ++- .../xcbglintegrations/CMakeLists.txt | 9 +++--- .../estimate_normals/CMakeLists.txt | 30 ++++++++----------- .../estimate_normals/estimate_normals.cpp | 2 +- pptk/vfuncs/CMakeLists.txt | 20 ++++++------- pptk/vfuncs/vfuncs.cpp | 2 +- pptk/viewer/CMakeLists.txt | 21 ++++++------- setup.py | 15 +++++----- 17 files changed, 88 insertions(+), 138 deletions(-) create mode 100644 .gitignore delete mode 100644 cmake/FindEigen.cmake delete mode 100644 cmake/FindNumpy.cmake delete mode 100644 cmake/FindTBB.cmake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d43339 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +__pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a41ccd..9ffb9a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/FindEigen.cmake b/cmake/FindEigen.cmake deleted file mode 100644 index a8a1388..0000000 --- a/cmake/FindEigen.cmake +++ /dev/null @@ -1,5 +0,0 @@ -include(FindPackageHandleStandardArgs) - -set(Eigen_INCLUDE_DIR "Eigen_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path containing Eigen folder") - -find_package_handle_standard_args(Eigen REQUIRED_VARS Eigen_INCLUDE_DIR) diff --git a/cmake/FindNumpy.cmake b/cmake/FindNumpy.cmake deleted file mode 100644 index 8dd8df4..0000000 --- a/cmake/FindNumpy.cmake +++ /dev/null @@ -1,5 +0,0 @@ -include(FindPackageHandleStandardArgs) - -set(Numpy_INCLUDE_DIR "Numpy_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path of folder containing arrayobject.h") - -find_package_handle_standard_args(Numpy REQUIRED_VARS Numpy_INCLUDE_DIR) diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake deleted file mode 100644 index c87118f..0000000 --- a/cmake/FindTBB.cmake +++ /dev/null @@ -1,16 +0,0 @@ -include(FindPackageHandleStandardArgs) - -set(TBB_INCLUDE_DIR "TBB_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path to directory containing TBB header files") -set(TBB_tbb_LIBRARY "TBB_tbb_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to tbb link library (i.e. tbb.lib)") -set(TBB_tbbmalloc_LIBRARY "TBB_tbbmalloc_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to tbbmalloc link library (i.e. tbbmalloc.lib)") -set(TBB_tbb_RUNTIME "TBB_tbb_RUNTIME-NOTFOUND" CACHE FILEPATH "Path to tbb runtime library (i.e. tbb.dll)") -set(TBB_tbbmalloc_RUNTIME "TBB_tbbmalloc_RUNTIME-NOTFOUND" CACHE FILEPATH "Path to tbbmalloc runtime library (i.e. tbbmalloc.dll)") - -find_package_handle_standard_args(TBB - REQUIRED_VARS - TBB_INCLUDE_DIR - TBB_tbb_LIBRARY - TBB_tbbmalloc_LIBRARY - TBB_tbb_RUNTIME - TBB_tbbmalloc_RUNTIME -) diff --git a/cmake/UsefulMacros.cmake b/cmake/UsefulMacros.cmake index 9eab9b5..ebb11dc 100644 --- a/cmake/UsefulMacros.cmake +++ b/cmake/UsefulMacros.cmake @@ -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() @@ -65,14 +67,16 @@ 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}) @@ -80,7 +84,7 @@ function(copy_file x) 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() diff --git a/pptk/include/python_util.h b/pptk/include/python_util.h index 5b16c3b..b7ce238 100644 --- a/pptk/include/python_util.h +++ b/pptk/include/python_util.h @@ -4,7 +4,7 @@ #include #include #include "Python.h" -#include "arrayobject.h" +#include "numpy/arrayobject.h" struct Array2D { const unsigned char* data; diff --git a/pptk/kdtree/CMakeLists.txt b/pptk/kdtree/CMakeLists.txt index 5dc0569..475014f 100644 --- a/pptk/kdtree/CMakeLists.txt +++ b/pptk/kdtree/CMakeLists.txt @@ -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) @@ -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) diff --git a/pptk/libs/CMakeLists.txt b/pptk/libs/CMakeLists.txt index a0c691d..4e490d0 100644 --- a/pptk/libs/CMakeLists.txt +++ b/pptk/libs/CMakeLists.txt @@ -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) @@ -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) diff --git a/pptk/libs/qt_plugins/platforms/CMakeLists.txt b/pptk/libs/qt_plugins/platforms/CMakeLists.txt index 5492601..2b4d2b7 100644 --- a/pptk/libs/qt_plugins/platforms/CMakeLists.txt +++ b/pptk/libs/qt_plugins/platforms/CMakeLists.txt @@ -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() diff --git a/pptk/libs/qt_plugins/xcbglintegrations/CMakeLists.txt b/pptk/libs/qt_plugins/xcbglintegrations/CMakeLists.txt index 497999d..6efd9b7 100644 --- a/pptk/libs/qt_plugins/xcbglintegrations/CMakeLists.txt +++ b/pptk/libs/qt_plugins/xcbglintegrations/CMakeLists.txt @@ -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() diff --git a/pptk/processing/estimate_normals/CMakeLists.txt b/pptk/processing/estimate_normals/CMakeLists.txt index 00f5284..8d74a75 100644 --- a/pptk/processing/estimate_normals/CMakeLists.txt +++ b/pptk/processing/estimate_normals/CMakeLists.txt @@ -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}) @@ -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) diff --git a/pptk/processing/estimate_normals/estimate_normals.cpp b/pptk/processing/estimate_normals/estimate_normals.cpp index a172399..b5e2d3a 100644 --- a/pptk/processing/estimate_normals/estimate_normals.cpp +++ b/pptk/processing/estimate_normals/estimate_normals.cpp @@ -5,7 +5,7 @@ #include #include #include "Python.h" -#include "arrayobject.h" +#include "numpy/arrayobject.h" #include "kdtree.h" #include "progress_bar.h" #include "python_util.h" diff --git a/pptk/vfuncs/CMakeLists.txt b/pptk/vfuncs/CMakeLists.txt index 395db0c..baef6e1 100644 --- a/pptk/vfuncs/CMakeLists.txt +++ b/pptk/vfuncs/CMakeLists.txt @@ -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}) @@ -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) diff --git a/pptk/vfuncs/vfuncs.cpp b/pptk/vfuncs/vfuncs.cpp index 6a379a4..67d8460 100644 --- a/pptk/vfuncs/vfuncs.cpp +++ b/pptk/vfuncs/vfuncs.cpp @@ -1,5 +1,5 @@ #include "Python.h" -#include "arrayobject.h" +#include "numpy/arrayobject.h" #define EIGEN_NO_DEBUG // comment this for runtime assertions #include #include diff --git a/pptk/viewer/CMakeLists.txt b/pptk/viewer/CMakeLists.txt index aa03e7b..c215749 100644 --- a/pptk/viewer/CMakeLists.txt +++ b/pptk/viewer/CMakeLists.txt @@ -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 @@ -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) diff --git a/setup.py b/setup.py index 52da4f4..4bc9c62 100644 --- a/setup.py +++ b/setup.py @@ -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: @@ -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' @@ -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' @@ -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}})