Skip to content

Commit

Permalink
Merge pull request #1536 from KrisThielemans/lib_deps
Browse files Browse the repository at this point in the history
Improve CMake library dependencies
  • Loading branch information
KrisThielemans authored Nov 14, 2024
2 parents 9d8c508 + dc2640f commit d74fcc1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ endif()
if (CERN_ROOT_FOUND)
target_include_directories(IO PRIVATE ${CERN_ROOT_INCLUDE_DIRS})
if (TARGET ROOT::Tree)
target_link_libraries(IO PUBLIC ROOT::Tree)
target_link_libraries(IO PRIVATE ROOT::Tree)
else()
target_link_libraries(IO PUBLIC ${CERN_ROOT_LIBRARIES})
target_link_libraries(IO PRIVATE ${CERN_ROOT_LIBRARIES})
endif()
endif()

Expand All @@ -94,12 +94,12 @@ if (HAVE_HDF5)
endif()

if (HAVE_ITK)
target_link_libraries(IO PUBLIC ITKCommon ${ITK_LIBRARIES})
target_link_libraries(IO PRIVATE ITKCommon ${ITK_LIBRARIES})
endif()

if (UPENN_FOUND)
target_include_directories(IO PUBLIC ${UPENN_INCLUDE_DIR})
target_link_libraries(IO PUBLIC ${UPENN_libsss_tof} ${UPENN_libfit} ${UPENN_libdist} ${UPENN_libgeom}
target_link_libraries(IO PRIVATE ${UPENN_libsss_tof} ${UPENN_libfit} ${UPENN_libdist} ${UPENN_libgeom}
${UPENN_liblor} ${UPENN_liblist} ${UPENN_libmhdr} ${JANSSON_LIBRARY} ${ZLIB_LIBRARY_RELEASE}
${UPENN_libimagio} ${UPENN_libimagio++})
endif()
Expand Down
10 changes: 9 additions & 1 deletion src/cmake/STIRConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,31 @@ else()
endif()

## find external packages
# Note that we generally need find_package even for those that are only
# PRIVATE dependencies (such as ITK, parallelproj etc). This is because
# otherwise their targets (such as parallelproj::parallelproj_c) don't exist,
# and the user will get CMake errors.
# See https://github.com/UCL/STIR/issues/1535

# we use a trick by Matt McCormick (kitware)
# to set ITK_DIR etc first before calling find_package
# to make sure we pick the same version of the external library

if (STIR_FIND_QUIETLY)
SET(STIR_FIND_TYPE "QUIET")
else()
SET(STIR_FIND_TYPE "REQUIRED")
endif()

find_package(Boost @Boost_VERSION@ REQUIRED)

if (@ITK_FOUND@)
message(STATUS "ITK support in STIR enabled.")
set(ITK_DIR "@ITK_DIR@")
find_package(ITK ${STIR_FIND_TYPE} CONFIG)
if(NOT ITK_FOUND)
SET(STIR_FOUND OFF)
endif()
include(${ITK_USE_FILE})
set(STIR_BUILT_WITH_ITK TRUE)
endif()

Expand Down
16 changes: 8 additions & 8 deletions src/recon_buildblock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ endif()
target_link_libraries(recon_buildblock PUBLIC modelling_buildblock display numerics_buildblock listmode_buildblock data_buildblock buildblock spatial_transformation_buildblock )

if (STIR_WITH_NiftyPET_PROJECTOR)
target_link_libraries(recon_buildblock PUBLIC NiftyPET::petprj)
target_link_libraries(recon_buildblock PUBLIC NiftyPET::mmr_auxe)
target_link_libraries(recon_buildblock PUBLIC NiftyPET::mmr_lmproc)
target_link_libraries(recon_buildblock PUBLIC CUDA::cudart)
target_link_libraries(recon_buildblock PRIVATE NiftyPET::petprj)
target_link_libraries(recon_buildblock PRIVATE NiftyPET::mmr_auxe)
target_link_libraries(recon_buildblock PRIVATE NiftyPET::mmr_lmproc)
target_link_libraries(recon_buildblock PRIVATE CUDA::cudart)
endif()

if (STIR_WITH_Parallelproj_PROJECTOR)
target_link_libraries(recon_buildblock PUBLIC parallelproj::parallelproj_c)
target_link_libraries(recon_buildblock PRIVATE parallelproj::parallelproj_c)
if (parallelproj_built_with_CUDA)
target_link_libraries(recon_buildblock PUBLIC parallelproj::parallelproj_cuda)
target_link_libraries(recon_buildblock PRIVATE parallelproj::parallelproj_cuda)
endif()
endif()

if (STIR_WITH_CUDA)
target_link_libraries(recon_buildblock PUBLIC CUDA::cudart)
endif()
target_link_libraries(recon_buildblock PRIVATE CUDA::cudart)
endif()

0 comments on commit d74fcc1

Please sign in to comment.