Skip to content

Commit

Permalink
Switch to a static library build.
Browse files Browse the repository at this point in the history
INSTALL_RPATH is not working on Mac for unknown reasons.
  • Loading branch information
joaander committed Aug 29, 2024
1 parent f4d1753 commit ae4c897
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 49 deletions.
6 changes: 0 additions & 6 deletions CMake/freud-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ endmacro()

# set the rpath for installing python extension modules
function(target_set_install_rpath _target)
if(APPLE)
set_target_properties(${_target} PROPERTIES INSTALL_RPATH "@loader_path")
else()
set_target_properties(${_target} PROPERTIES INSTALL_RPATH "\$ORIGIN")
endif()

if(_using_conda)
set_target_properties(${_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH
True)
Expand Down
42 changes: 9 additions & 33 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()

# Detect when building against a conda environment set the _using_conda variable
# for use both in this file and in the parent
get_filename_component(_python_bin_dir ${PYTHON_EXECUTABLE} DIRECTORY)
get_filename_component(_python_bin_dir ${Python_EXECUTABLE} DIRECTORY)
if(EXISTS "${_python_bin_dir}/../conda-meta")
message("-- Detected conda environment, setting INSTALL_RPATH_USE_LINK_PATH")
set(_using_conda On)
Expand All @@ -22,42 +22,22 @@ else()
PARENT_SCOPE)
endif()

# get the sources/header files for building libfreud.so
include(box/box-files.cmake)
include(locality/locality-files.cmake)
include(parallel/parallel-files.cmake)
include(pmft/pmft-files.cmake)
include(util/util-files.cmake)

# make libfreud.so
add_library(libfreud SHARED ${box_sources} ${locality_sources}
# Use a static library for the main code. A Dynamic library would be more
# disk space efficient, but I was unable to resolve a RPATH issue where
# any use of `INSTALL_RPATH` would result in "terminated by signal SIGKILL"
# the moment Python attempts to load the library.
add_library(freud STATIC ${box_sources} ${locality_sources}
${parallel_sources} ${pmft_sources} ${util_sources})
set_target_properties(freud PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(freud PUBLIC TBB::tbb)

target_link_libraries(libfreud PUBLIC TBB::tbb)

# We treat the extern folder as a SYSTEM library to avoid getting any diagnostic
# information from it. In particular, this avoids clang-tidy throwing errors due
# to any issues in external code.
target_include_directories(libfreud SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/extern/)

# CMake will automatically prepend any library name with "lib" when creating
# shared libraries, so a CMake library named libfreud will result in
# liblibfreud.so object. This rename gives the more expected name of
# libfreud.so. Note that we choose not to name the CMake target "freud" to avoid
# conflicting with the project name.
set_target_properties(libfreud PROPERTIES OUTPUT_NAME freud)

# Copy the C++ library into the built version.
install(TARGETS libfreud DESTINATION freud)

if(CMAKE_EXPORT_COMPILE_COMMANDS)
# Copy the compile commands into the root of the project.
add_custom_command(
TARGET libfreud
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/compile_commands.json
${PROJECT_SOURCE_DIR})
endif()
target_include_directories(freud SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/extern/)

# now build the python extension modules
add_subdirectory(box)
Expand All @@ -70,7 +50,3 @@ add_subdirectory(util)
# add_subdirectory(cluster) add_subdirectory(density)
# add_subdirectory(diffraction) add_subdirectory(environment)
# add_subdirectory(order) add_subdirectory(pmft)

if(${freud_nanobind_linking} STREQUAL "NB_SHARED")
install(TARGETS nanobind DESTINATION freud)
endif()
4 changes: 2 additions & 2 deletions cpp/box/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# create the target and add the needed properties
nanobind_add_module(_box ${freud_nanobind_linking} module-box.cc export_Box.cc)
target_link_libraries(_box PUBLIC libfreud)
nanobind_add_module(_box module-box.cc export_Box.cc)
target_link_libraries(_box PUBLIC TBB::tbb)

target_set_install_rpath(_box)

Expand Down
4 changes: 2 additions & 2 deletions cpp/locality/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set(locality_extension_sources
export_Voronoi.cc)

# create the target and add the needed properties
nanobind_add_module(_locality ${freud_nanobind_linking} module-locality.cc
nanobind_add_module(_locality module-locality.cc
${locality_extension_sources})
target_link_libraries(_locality PUBLIC libfreud)
target_link_libraries(_locality PUBLIC freud TBB::tbb)

target_set_install_rpath(_locality)

Expand Down
4 changes: 2 additions & 2 deletions cpp/parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
nanobind_add_module(_parallel ${freud_nanobind_linking} module-parallel.cc)
target_link_libraries(_parallel PUBLIC libfreud)
nanobind_add_module(_parallel module-parallel.cc)
target_link_libraries(_parallel PUBLIC freud TBB::tbb)

target_set_install_rpath(_parallel)

Expand Down
3 changes: 1 addition & 2 deletions cpp/pmft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
nanobind_add_module(
_pmft
${freud_nanobind_linking}
module-pmft.cc
export-PMFTXY.cc
export-PMFTXYZ.cc
export-PMFTR12.cc
export-PMFTXYT.cc)
target_link_libraries(_pmft PUBLIC libfreud)
target_link_libraries(_pmft PUBLIC freud)

target_set_install_rpath(_pmft)

Expand Down
4 changes: 2 additions & 2 deletions cpp/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(util_extension_headers export_ManagedArray.h export_Vector.h)

nanobind_add_module(_util ${freud_nanobind_linking} module-util.cc
nanobind_add_module(_util module-util.cc
${util_extension_headers})
target_link_libraries(_util PUBLIC libfreud)
target_link_libraries(_util PUBLIC freud)

target_set_install_rpath(_util)

Expand Down

0 comments on commit ae4c897

Please sign in to comment.