Skip to content

Commit a398d99

Browse files
victoriousluserVictor Lu
authored andcommitted
Improved MacOS side of build system; now able to automatically find and create local copies of dependencies required by built targets.
1 parent 0ca8775 commit a398d99

File tree

13 files changed

+107
-23
lines changed

13 files changed

+107
-23
lines changed

CMakeCache.mac.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PYTHON_INCLUDE_DIR:PATH=/Applications/Canopy.app/appdata/canopy-1.4.0.1938.macosx-x86_64/Canopy.app/Contents/include/python2.7
2+
PYTHON_LIBRARY:FILEPATH=/Applications/Canopy.app/appdata/canopy-1.4.0.1938.macosx-x86_64/Canopy.app/Contents/lib/libpython2.7.dylib
3+
Numpy_INCLUDE_DIR:PATH=/Users/victorlu/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/include/numpy
4+
Eigen_INCLUDE_DIR:PATH=/Users/victorlu/Sources/eigen-3.2.2
5+
Qt5_DIR:PATH=/Users/victorlu/Qt5.3.0/5.3/clang_64/lib/cmake/Qt5
6+
TBB_INCLUDE_DIR:PATH=/Users/victorlu/Sources/tbb2017_20170226oss/include
7+
TBB_tbb_LIBRARY:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbb.dylib
8+
TBB_tbb_RUNTIME:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbb.dylib
9+
TBB_tbbmalloc_LIBRARY:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbbmalloc.dylib
10+
TBB_tbbmalloc_RUNTIME:FILEPATH=/Users/victorlu/Sources/tbb2017_20170226oss/lib/libtbbmalloc.dylib
11+
CMAKE_CXX_COMPILER:FILEPATH=/Users/victorlu/Sources/install/bin/g++
12+
CMAKE_C_COMPILER:FILEPATH=/Users/victorlu/Sources/install/bin/gcc

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ find_package(Eigen REQUIRED)
1111
find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets Network OpenGL Core)
1212
find_package(OpenMP)
1313

14+
# get root Qt5 folder (i.e. contains bin, lib, plugins, etc.)
15+
get_target_property(Qt5_DIR Qt5::qmake LOCATION)
16+
get_filename_component(Qt5_DIR ${Qt5_DIR} DIRECTORY)
17+
get_filename_component(Qt5_DIR ${Qt5_DIR} DIRECTORY)
18+
19+
set(PYPCL_LIBS_DIR ${PROJECT_BINARY_DIR}/pypcl/libs)
20+
1421
include(UsefulMacros)
1522

1623
# following lines specifies the CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS variable

cmake/CopyAppleDependencies.cmake

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
# usage: cmake -P CopyAppleDependencies.cmake
2-
# <install_name_tool path> <target file path> <copy folder path>
3-
include(GetPrerequisites)
2+
# <target file path> <copy folder path>
3+
# paths assumed to be existing full paths
44

5-
set(_install_name_tool ${CMAKE_ARGV3})
6-
set(_target ${CMAKE_ARGV4})
7-
set(_copy_folder ${CMAKE_ARGV5})
8-
message(${_install_name_tool})
9-
message(${_target})
10-
message(${_copy_folder})
11-
get_prerequisites(${_target} _prereqs 1 1 "" "")
5+
include(BundleUtilities)
126

7+
find_program(_install_name_tool "install_name_tool")
8+
set(_target ${CMAKE_ARGV3})
9+
set(_copy_folder ${CMAKE_ARGV4})
10+
set(_paths "/usr/bin")
11+
get_item_rpaths(${_target} _rpaths)
12+
get_prerequisites(${_target} _prereqs 1 1 "" "${_paths}" "${_rpaths}")
13+
14+
# delete existing rpaths in _target and
15+
# add relative path to _copy_folder as new rpath
16+
foreach(p ${_rpaths})
17+
execute_process(COMMAND ${_install_name_tool} -delete_rpath ${p} ${_target})
18+
endforeach()
19+
get_filename_component(_target_folder ${_target} DIRECTORY)
20+
file(RELATIVE_PATH _new_rpath ${_target_folder} ${_copy_folder})
21+
execute_process(COMMAND
22+
${_install_name_tool} -add_rpath "@loader_path/${_new_rpath}" ${_target})
23+
24+
# copy _target's dependencies to _copy_folder
1325
foreach(p ${_prereqs})
1426
get_filename_component(y ${p} NAME)
1527
set(dst ${_copy_folder}/${y})
16-
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${p} ${dst})
28+
gp_resolve_item(${_target} ${p} "" "${_paths}" src "${_rpaths}")
29+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst})
1730
execute_process(COMMAND ${_install_name_tool} -id @rpath/${y} ${dst})
1831
if (IS_ABSOLUTE ${p})
1932
execute_process(COMMAND ${_install_name_tool} -change ${p} @rpath/${y} ${_target})

cmake/UsefulMacros.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ function(copy_file x)
4242
string(REGEX REPLACE "(/|\\\\)" "." temp "${temp}")
4343
string(CONCAT name "${temp}" "." "${name}")
4444
endif()
45+
if (ARGC EQUAL 2)
46+
message("${ARGV0}")
47+
set(${ARGV1} ${name} PARENT_SCOPE)
48+
endif()
4549
if (NOT IS_ABSOLUTE ${x})
4650
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${x})
4751
else()

pypcl/kdtree/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
add_library(kdtree SHARED kdtree_wrapper.cpp)
1212
set_target_python_module_name(kdtree)
13-
set_target_rpath(kdtree ../libs)
1413
target_include_directories(kdtree PRIVATE
1514
../include # for python_util.h
1615
src # for k-d tree source code
@@ -23,3 +22,14 @@ target_link_libraries(kdtree
2322
${PYTHON_LIBRARY} )
2423
copy_target(kdtree)
2524
copy_file(__init__.py)
25+
26+
if (WIN32)
27+
# TODO
28+
elseif (APPLE)
29+
add_custom_command(TARGET kdtree POST_BUILD
30+
COMMAND ${CMAKE_COMMAND} -P
31+
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
32+
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:vfuncs> ${PYPCL_LIBS_DIR})
33+
elseif (UNIX)
34+
# TODO
35+
endif()

pypcl/libs/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ if (WIN32)
55
copy_file(${f})
66
endforeach()
77
elseif (APPLE)
8-
# assumes system libraries found in ../lib w.r.t g++
9-
get_filename_component(temp ${CMAKE_CXX_COMPILER} DIRECTORY)
10-
copy_file("${temp}/../lib/libgomp.1.dylib")
11-
copy_file("${temp}/../lib/libstdc++.6.dylib")
12-
copy_file("${temp}/../lib/libgcc_s.1.dylib")
13-
unset(temp)
148
elseif (UNIX)
159
# assume Linux system already has libstdc++.so.6 and libgcc_s.so.1
1610
copy_file(/usr/lib64/libgomp.so.1)
@@ -26,10 +20,12 @@ macro(copy_import_target x)
2620
copy_file(${temp})
2721
unset(temp)
2822
endmacro()
29-
if (NOT DEFINED WIN32)
23+
if (UNIX AND NOT APPLE)
3024
copy_import_target(Qt5::Network)
3125
copy_import_target(Qt5::Core)
3226
copy_import_target(Qt5::Gui)
3327
copy_import_target(Qt5::OpenGL)
3428
copy_import_target(Qt5::Widgets)
3529
endif()
30+
31+
add_subdirectory(qt_plugins)

pypcl/libs/qt_plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(platforms)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if (WIN32)
2+
copy_file(${Qt5_DIR}/plugins/platforms/qwindows.dll)
3+
elseif (APPLE)
4+
include(${CMAKE_CURRENT_SOURCE_DIR}/mac.cmake)
5+
elseif (UNIX)
6+
copy_file(${Qt5_DIR}/plugins/platforms/libqxcb.so)
7+
endif()
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
copy_file(${Qt5_DIR}/plugins/platforms/libqcocoa.dylib _target_name)
2+
set(_target_file ${CMAKE_CURRENT_BINARY_DIR}/libqcocoa.dylib)
3+
add_custom_command(TARGET ${_target_name} POST_BUILD
4+
COMMAND ${CMAKE_COMMAND} -P
5+
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
6+
${_target_file} ${PYPCL_LIBS_DIR})
7+

pypcl/processing/estimate_normals/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ set_target_properties(estimate_normals PROPERTIES
1515
COMPILE_FLAGS ${OpenMP_CXX_FLAGS}
1616
LINK_FLAGS ${OpenMP_CXX_FLAGS})
1717
set_target_python_module_name(estimate_normals)
18-
set_target_rpath(estimate_normals ../../libs)
1918
target_link_libraries(estimate_normals
2019
${PYTHON_LIBRARY}
2120
${TBB_tbb_LIBRARY}
@@ -29,3 +28,15 @@ target_include_directories(estimate_normals PRIVATE
2928
${Numpy_INCLUDE_DIR})
3029
copy_target(estimate_normals)
3130
copy_file(__init__.py)
31+
32+
if (WIN32)
33+
# TODO
34+
elseif (APPLE)
35+
add_custom_command(TARGET estimate_normals POST_BUILD
36+
COMMAND ${CMAKE_COMMAND} -P
37+
${PROJECT_SOURCE_DIR}/cmake/CopyAppleDependencies.cmake
38+
${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:estimate_normals>
39+
${PYPCL_LIBS_DIR})
40+
elseif (UNIX)
41+
# TODO
42+
endif()

0 commit comments

Comments
 (0)