Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS builds. #323

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Change Log
and before `gsd_end_frame()` (`#319 <https://github.com/glotzerlab/gsd/pull/319>`__).
* Readthedocs builds with pandas 2.2.0
(`#322 <https://github.com/glotzerlab/gsd/pull/322>`__).
* Import without seg fault when built with CMake on macOS.
(`#323 <https://github.com/glotzerlab/gsd/pull/323>`__).

*Changed:*

Expand Down
20 changes: 0 additions & 20 deletions CMake/PythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} $<TARGET_FILE:${target}>)
endif ()
endmacro()
14 changes: 11 additions & 3 deletions gsd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<$<PLATFORM_ID:Darwin>: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)
Expand Down
Loading