Skip to content

Commit ce157bc

Browse files
committed
[cmake] Do not link libpython under OSX but resolve symbols using '-undefined dynamic_lookup'
-Adjust python_and_numpy target accordingly -Adjust add_cpp2py_module accordingly
1 parent 9c7456d commit ce157bc

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

cmake/Cpp2PyConfig.cmake.in

-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ macro(add_cpp2py_module)
9393
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
9494
)
9595

96-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
97-
target_link_libraries(${module_name} "-undefined dynamic_lookup")
98-
endif()
99-
10096
# Keep a list of every module target.
10197
# Usage : e.g. Documentation top target depends on them being built first
10298
set_property(GLOBAL APPEND PROPERTY CPP2PY_MODULES_LIST ${module_name})

cmake/FindPython.cmake

+7-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ ENDFUNCTION(EXEC_PYTHON_SCRIPT)
134134

135135
# Define python_and_numpy interface target
136136
add_library(python_and_numpy INTERFACE)
137-
target_link_libraries(python_and_numpy INTERFACE ${PYTHON_LIBRARY} "${PYTHON_EXTRA_LIBS}")
137+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
138+
# On OSX missing python symbols should be resolved at runtime through '-undefined dynamic_lookup'
139+
# as the interperter shipped with e.g. anaconda provides all relevant symbols statically
140+
target_link_libraries(python_and_numpy INTERFACE "-undefined dynamic_lookup" "${PYTHON_EXTRA_LIBS}")
141+
else()
142+
target_link_libraries(python_and_numpy INTERFACE ${PYTHON_LIBRARY} "${PYTHON_EXTRA_LIBS}")
143+
endif()
138144
target_include_directories(python_and_numpy SYSTEM INTERFACE ${PYTHON_INCLUDE_DIRS} ${PYTHON_NUMPY_INCLUDE_DIR})
139145
target_compile_options(python_and_numpy INTERFACE -Wno-register) # Some version of Python.h still use register
140146

cpp2py/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ macro(add_cpp2py_module)
5656
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
5757
)
5858

59-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
60-
target_link_libraries(${module_name} "-undefined dynamic_lookup")
61-
endif()
62-
6359
# Keep a list of every module target.
6460
# Usage : e.g. Documentation top target depends on them being built first
6561
set_property(GLOBAL APPEND PROPERTY CPP2PY_MODULES_LIST ${module_name})

0 commit comments

Comments
 (0)