Skip to content

Commit

Permalink
Merge branch 'fix-macos-builds' into trunk-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Jan 22, 2024
2 parents 8eaec02 + 0f00a34 commit e29e61c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
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

0 comments on commit e29e61c

Please sign in to comment.