Skip to content

Commit

Permalink
Improved MacOS side of build system; now able to automatically find a…
Browse files Browse the repository at this point in the history
…nd create local copies of dependencies required by built targets.
  • Loading branch information
victoriousluser authored and Victor Lu committed Jul 13, 2018
1 parent 0ca8775 commit a398d99
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 23 deletions.
12 changes: 12 additions & 0 deletions CMakeCache.mac.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PYTHON_INCLUDE_DIR:PATH=/Applications/Canopy.app/appdata/canopy-1.4.0.1938.macosx-x86_64/Canopy.app/Contents/include/python2.7
PYTHON_LIBRARY:FILEPATH=/Applications/Canopy.app/appdata/canopy-1.4.0.1938.macosx-x86_64/Canopy.app/Contents/lib/libpython2.7.dylib
Numpy_INCLUDE_DIR:PATH=/Users/victorlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy
Eigen_INCLUDE_DIR:PATH=/Users/victorlu/Sources/eigen-3.2.2
Qt5_DIR:PATH=/Users/victorlu/Qt5.3.0/5.3/clang_64/lib/cmake/Qt5
TBB_INCLUDE_DIR:PATH=/Users/victorlu/Sources/tbb2017_20170226oss/include
TBB_tbb_LIBRARY:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbb.dylib
TBB_tbb_RUNTIME:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbb.dylib
TBB_tbbmalloc_LIBRARY:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbbmalloc.dylib
TBB_tbbmalloc_RUNTIME:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbbmalloc.dylib
CMAKE_CXX_COMPILER:FILEPATH=/Users/victorlu/Sources/install/bin/g++
CMAKE_C_COMPILER:FILEPATH=/Users/victorlu/Sources/install/bin/gcc
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ 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(PYPCL_LIBS_DIR ${PROJECT_BINARY_DIR}/pypcl/libs)

include(UsefulMacros)

# following lines specifies the CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS variable
Expand Down
33 changes: 23 additions & 10 deletions cmake/CopyAppleDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
# usage: cmake -P CopyAppleDependencies.cmake
# <install_name_tool path> <target file path> <copy folder path>
include(GetPrerequisites)
# <target file path> <copy folder path>
# paths assumed to be existing full paths

set(_install_name_tool ${CMAKE_ARGV3})
set(_target ${CMAKE_ARGV4})
set(_copy_folder ${CMAKE_ARGV5})
message(${_install_name_tool})
message(${_target})
message(${_copy_folder})
get_prerequisites(${_target} _prereqs 1 1 "" "")
include(BundleUtilities)

find_program(_install_name_tool "install_name_tool")
set(_target ${CMAKE_ARGV3})
set(_copy_folder ${CMAKE_ARGV4})
set(_paths "/usr/bin")
get_item_rpaths(${_target} _rpaths)
get_prerequisites(${_target} _prereqs 1 1 "" "${_paths}" "${_rpaths}")

# delete existing rpaths in _target and
# add relative path to _copy_folder as new rpath
foreach(p ${_rpaths})
execute_process(COMMAND ${_install_name_tool} -delete_rpath ${p} ${_target})
endforeach()
get_filename_component(_target_folder ${_target} DIRECTORY)
file(RELATIVE_PATH _new_rpath ${_target_folder} ${_copy_folder})
execute_process(COMMAND
${_install_name_tool} -add_rpath "@loader_path/${_new_rpath}" ${_target})

# copy _target's dependencies to _copy_folder
foreach(p ${_prereqs})
get_filename_component(y ${p} NAME)
set(dst ${_copy_folder}/${y})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${p} ${dst})
gp_resolve_item(${_target} ${p} "" "${_paths}" src "${_rpaths}")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst})
execute_process(COMMAND ${_install_name_tool} -id @rpath/${y} ${dst})
if (IS_ABSOLUTE ${p})
execute_process(COMMAND ${_install_name_tool} -change ${p} @rpath/${y} ${_target})
Expand Down
4 changes: 4 additions & 0 deletions cmake/UsefulMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function(copy_file x)
string(REGEX REPLACE "(/|\\\\)" "." temp "${temp}")
string(CONCAT name "${temp}" "." "${name}")
endif()
if (ARGC EQUAL 2)
message("${ARGV0}")
set(${ARGV1} ${name} PARENT_SCOPE)
endif()
if (NOT IS_ABSOLUTE ${x})
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${x})
else()
Expand Down
12 changes: 11 additions & 1 deletion pypcl/kdtree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

add_library(kdtree SHARED kdtree_wrapper.cpp)
set_target_python_module_name(kdtree)
set_target_rpath(kdtree ../libs)
target_include_directories(kdtree PRIVATE
../include # for python_util.h
src # for k-d tree source code
Expand All @@ -23,3 +22,14 @@ target_link_libraries(kdtree
${PYTHON_LIBRARY} )
copy_target(kdtree)
copy_file(__init__.py)

if (WIN32)
# TODO
elseif (APPLE)
add_custom_command(TARGET kdtree POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:vfuncs> ${PYPCL_LIBS_DIR})
elseif (UNIX)
# TODO
endif()
10 changes: 3 additions & 7 deletions pypcl/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ if (WIN32)
copy_file(${f})
endforeach()
elseif (APPLE)
# assumes system libraries found in ../lib w.r.t g++
get_filename_component(temp ${CMAKE_CXX_COMPILER} DIRECTORY)
copy_file("${temp}/../lib/libgomp.1.dylib")
copy_file("${temp}/../lib/libstdc++.6.dylib")
copy_file("${temp}/../lib/libgcc_s.1.dylib")
unset(temp)
elseif (UNIX)
# assume Linux system already has libstdc++.so.6 and libgcc_s.so.1
copy_file(/usr/lib64/libgomp.so.1)
Expand All @@ -26,10 +20,12 @@ macro(copy_import_target x)
copy_file(${temp})
unset(temp)
endmacro()
if (NOT DEFINED WIN32)
if (UNIX AND NOT APPLE)
copy_import_target(Qt5::Network)
copy_import_target(Qt5::Core)
copy_import_target(Qt5::Gui)
copy_import_target(Qt5::OpenGL)
copy_import_target(Qt5::Widgets)
endif()

add_subdirectory(qt_plugins)
1 change: 1 addition & 0 deletions pypcl/libs/qt_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(platforms)
8 changes: 8 additions & 0 deletions pypcl/libs/qt_plugins/platforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if (WIN32)
copy_file(${Qt5_DIR}/plugins/platforms/qwindows.dll)
elseif (APPLE)
include(${CMAKE_CURRENT_SOURCE_DIR}/mac.cmake)
elseif (UNIX)
copy_file(${Qt5_DIR}/plugins/platforms/libqxcb.so)
endif()

7 changes: 7 additions & 0 deletions pypcl/libs/qt_plugins/platforms/mac.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
copy_file(${Qt5_DIR}/plugins/platforms/libqcocoa.dylib _target_name)
set(_target_file ${CMAKE_CURRENT_BINARY_DIR}/libqcocoa.dylib)
add_custom_command(TARGET ${_target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${_target_file} ${PYPCL_LIBS_DIR})

13 changes: 12 additions & 1 deletion pypcl/processing/estimate_normals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set_target_properties(estimate_normals PROPERTIES
COMPILE_FLAGS ${OpenMP_CXX_FLAGS}
LINK_FLAGS ${OpenMP_CXX_FLAGS})
set_target_python_module_name(estimate_normals)
set_target_rpath(estimate_normals ../../libs)
target_link_libraries(estimate_normals
${PYTHON_LIBRARY}
${TBB_tbb_LIBRARY}
Expand All @@ -29,3 +28,15 @@ target_include_directories(estimate_normals PRIVATE
${Numpy_INCLUDE_DIR})
copy_target(estimate_normals)
copy_file(__init__.py)

if (WIN32)
# TODO
elseif (APPLE)
add_custom_command(TARGET estimate_normals POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:estimate_normals>
${PYPCL_LIBS_DIR})
elseif (UNIX)
# TODO
endif()
14 changes: 12 additions & 2 deletions pypcl/vfuncs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@

add_library(vfuncs SHARED vfuncs.cpp)
set_target_python_module_name(vfuncs)
set_target_rpath(vfuncs ../libs)
target_link_libraries(vfuncs ${PYTHON_LIBRARY})
target_include_directories(vfuncs PRIVATE
../include # for python_util.h
${PYTHON_INCLUDE_DIR}
${Eigen_INCLUDE_DIR}
${Numpy_INCLUDE_DIR})
copy_target(vfuncs)
copy_file(__init__.py)
copy_file(__init__.py)

if (WIN32)
# TODO
elseif (APPLE)
add_custom_command(TARGET vfuncs POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:vfuncs> ${PYPCL_LIBS_DIR})
elseif (UNIX)
# TODO
endif()
7 changes: 5 additions & 2 deletions pypcl/viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ add_executable(viewer
PointAttributes.h)

set_target_properties(viewer PROPERTIES AUTOMOC TRUE)
set_target_rpath(viewer ../libs)
target_link_libraries(viewer Qt5::Widgets Qt5::Network Qt5::OpenGL ${OPENGL_gl_LIBRARY})
target_include_directories(viewer PRIVATE ${Eigen_INCLUDE_DIR} )
copy_target(viewer)
copy_file(viewer.py)
copy_file(__init__.py)
copy_file(qt.conf)

# deploy runtime dll's to libs folder
get_target_property(_qmake_exe Qt5::qmake IMPORTED_LOCATION)
Expand All @@ -49,7 +49,10 @@ if (WIN32)
--no-angle
--no-system-d3d-compiler)
elseif (APPLE)
# TODO
add_custom_command(TARGET viewer POST_BUILD
COMMAND ${CMAKE_COMMAND} -P
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:viewer> ${PYPCL_LIBS_DIR})
elseif (UNIX)
# TODO
endif()
Expand Down
2 changes: 2 additions & 0 deletions pypcl/viewer/qt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Paths]
Plugins=../libs/qt_plugins

0 comments on commit a398d99

Please sign in to comment.