Skip to content

Commit 3a5279f

Browse files
authored
Merge pull request #9 from jnbrunet/fix_python_rpath_on_macos
[cmake] Add XCode framework to RPath on MacOS
2 parents 17b0887 + aaa8978 commit 3a5279f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CMake/SofaPython3Tools.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ function(SP3_add_python_module)
149149
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_DIRECTORY}"
150150
)
151151

152+
if (APPLE)
153+
set_target_properties(
154+
${PROJECT_NAME}
155+
PROPERTIES
156+
INSTALL_NAME_DIR "@rpath/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}"
157+
)
158+
endif()
159+
152160
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
153161
set_target_properties(
154162
${A_TARGET}

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ message("-- Python user site: ${PYTHON_USER_SITE}")
9898
message("-- pybind11 version: ${pybind11_VERSION}")
9999
message("-- pybind11 config: ${pybind11_CONFIG}")
100100

101+
# When using python3 from XCode on MacOS, the RPath is wrongly set to XCode frameworks directory:
102+
# LC_LOAD_DYLIB @rpath/Python3.framework/Versions/3.7/Python3
103+
# LC_RPATH /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib
104+
# Hence LC_RPATH/LC_LOAD_DYLIB does not exists.
105+
# Until this is fixed (not sure if it comes from pybind11, cmake or XCode), we can add another path to RPATH:
106+
# LC_LOAD_DYLIB @rpath/Python3.framework/Versions/3.7/Python3
107+
# LC_RPATH /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib
108+
# /Applications/Xcode.app/Contents/Developer/Library/Frameworks <----- ADDED
109+
# And now one combination of LC_RPATH/LC_LOAD_DYLIB will be valid.
110+
# This should't change anything for those that use other python libs than XCode (homebrew for example) since the
111+
# LC_LOAD_DYLIB from XCode is quite unique.
112+
if (APPLE)
113+
set(CMAKE_INSTALL_RPATH "/Applications/Xcode.app/Contents/Developer/Library/Frameworks")
114+
set(CMAKE_BUILD_RPATH "/Applications/Xcode.app/Contents/Developer/Library/Frameworks")
115+
endif()
116+
101117
add_subdirectory(Plugin)
102118
add_subdirectory(bindings)
103119
add_subdirectory(examples)

0 commit comments

Comments
 (0)