Skip to content

Commit

Permalink
Merge pull request #950 from glotzerlab/cmake-updates
Browse files Browse the repository at this point in the history
Fixes to CMake scripts
  • Loading branch information
tommy-waltmann authored May 9, 2022
2 parents e4cafba + cf363b8 commit 76c4eb9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
14 changes: 1 addition & 13 deletions CMake/FindTBB.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
find_path(TBB_INCLUDE_DIR tbb/tbb.h HINTS $ENV{TBBROOT}/include
$ENV{TBB_INCLUDE_DIR})

# Check OS-specific env variables for libraries.
if(DEFINED ENV{LD_LIBRARY_PATH})
# For Linux.
string(REPLACE ":" ";" LD_LIBRARY_DIR_LIST $ENV{LD_LIBRARY_PATH})
elseif(DEFINED ENV{DYLD_LIBRARY_PATH})
# For Mac.
string(REPLACE ":" ";" LD_LIBRARY_DIR_LIST $ENV{DYLD_LIBRARY_PATH})
else()
set(LD_LIBRARY_DIR_LIST "")
endif()

find_library(TBB_LIBRARY tbb HINTS $ENV{TBBROOT}/lib ${LD_LIBRARY_DIR_LIST}
${TBB_INCLUDE_DIR}/../lib)
find_library(TBB_LIBRARY tbb HINTS $ENV{TBBROOT}/lib ${TBB_INCLUDE_DIR}/../lib)

if(TBB_INCLUDE_DIR AND EXISTS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h")
file(STRINGS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h" TBB_H
Expand Down
19 changes: 19 additions & 0 deletions CMake/freud-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ macro(find_package_config_first package)
endif()
endif()
endmacro()

# Convert shared libraries to python extensions
function(make_python_extension_module _target)
set_target_properties(${_target} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
set_target_properties(${_target}
PROPERTIES SUFFIX "${PYTHON_EXTENSION_MODULE_SUFFIX}")

target_include_directories(${_target} PRIVATE "${PYTHON_INCLUDE_DIRS}")
if(WIN32)
# Link to the Python libraries on windows
target_link_libraries(${_target} ${PYTHON_LIBRARIES})
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(
${_target} PRIVATE
"$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
endif()
endfunction()
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(CMake)
find_package_config_first(TBB)

if(TBB_FOUND)
include(FindPackageMessage)
find_package_message(
tbb "Found TBB: ${TBB_DIR} ${TBB_LIBRARY} ${TBB_INCLUDE_DIR}"
"[${TBB_LIBRARY}][${TBB_INCLUDE_DIR}]")
endif()

# Fail fast if users have not cloned submodules.
if(NOT WIN32)
string(ASCII 27 Esc)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/gettingstarted/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ In addition to standard CMake flags, the following CMake options are available f
Build the Cython files with coverage support to check unit test coverage.


The **freud** CMake configuration also respects the following environment variables (in addition to standards like ``LD_LIBRARY_PATH``).
The **freud** CMake configuration also respects the following environment variables (in addition to standards like ``CMAKE_PREFIX_PATH``).

.. glossary::

Expand Down
6 changes: 2 additions & 4 deletions freud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ set(cython_modules_without_cpp interface msd util)

foreach(cython_module ${cython_modules_with_cpp} ${cython_modules_without_cpp})
add_cython_target(${cython_module} PY3 CXX)
add_library(${cython_module} MODULE ${${cython_module}})
# For some reason this command prints the name of the resulting module. Would
# be good to suppress if possible.
python_extension_module(${cython_module})
add_library(${cython_module} SHARED ${${cython_module}})
make_python_extension_module(${cython_module})

target_compile_definitions(
${cython_module}
Expand Down

0 comments on commit 76c4eb9

Please sign in to comment.