diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 548397ae..1c9f69ff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,8 @@ Change Log and before `gsd_end_frame()` (`#319 `__). * Readthedocs builds with pandas 2.2.0 (`#322 `__). +* Import without seg fault when built with CMake on macOS. + (`#323 `__). *Changed:* diff --git a/CMake/PythonSetup.cmake b/CMake/PythonSetup.cmake index 7ea49986..43b44860 100644 --- a/CMake/PythonSetup.cmake +++ b/CMake/PythonSetup.cmake @@ -83,23 +83,3 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(cython DEFAULT_MSG CYTHON_EXECUTABLE) if (NOT CYTHON_EXECUTABLE) message(ERROR "cython not found") endif() - -############################################################################################# -# Fixup conda linking, if this python appears to be a conda python -if (${CMAKE_MAJOR_VERSION} GREATER 2) -get_filename_component(_python_bin_dir ${PYTHON_EXECUTABLE} DIRECTORY) -if (EXISTS "${_python_bin_dir}/conda") - message("-- Detected conda python, activating workaround") - set(_using_conda On) -else() - set(_using_conda Off) -endif() -endif() - -macro(fix_conda_python target) -if (_using_conda) -get_filename_component(_python_lib_file ${PYTHON_LIBRARY} NAME) -add_custom_command(TARGET ${target} POST_BUILD - COMMAND install_name_tool ARGS -change ${_python_lib_file} ${PYTHON_LIBRARY} $) -endif () -endmacro() diff --git a/gsd/CMakeLists.txt b/gsd/CMakeLists.txt index 5290f268..2dca238c 100644 --- a/gsd/CMakeLists.txt +++ b/gsd/CMakeLists.txt @@ -23,15 +23,23 @@ target_compile_definitions(fl PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) set_target_properties(fl PROPERTIES PREFIX "" OUTPUT_NAME "fl" MACOSX_RPATH "On") if(APPLE) set_target_properties(fl PROPERTIES SUFFIX ".so") - target_link_libraries(fl ${PYTHON_LIBRARY}) - fix_conda_python(fl) endif(APPLE) if (WIN32) - target_link_libraries(fl ${PYTHON_LIBRARY}) set_target_properties(fl PROPERTIES SUFFIX ".pyd") endif() +if(WIN32) + # Link to the Python libraries on windows + target_link_libraries(fl ${PYTHON_LIBRARY}) +else() + # Do not link to the Python libraries on Mac/Linux - symbols are provided by + # the `python` executable. "-undefined dynamic_lookup" is needed on Mac + target_link_options( + fl PRIVATE + "$<$:LINKER:-undefined,dynamic_lookup>") +endif() + ################ Python only modules # copy python modules to the build directory to make it a working python package MACRO(copy_file file)