Skip to content

Commit 9818cdb

Browse files
Merge pull request UCL#1668 from KrisThielemans/HDF5_target_workaround
[CMake] depend on both HDF5::HDF5 and hdf5::hdf5_cpp
2 parents 0e667f7 + d2a1816 commit 9818cdb

File tree

7 files changed

+14
-5
lines changed

7 files changed

+14
-5
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ if(NOT DISABLE_HDF5)
157157
if (TARGET HDF5::HDF5)
158158
option(USE_HDF5_TARGET "Use HDF5::HDF5 CMake target for dependencies (recommended)" ON)
159159
mark_as_advanced(USE_HDF5_TARGET)
160+
# Depend on both HDF5::HDF5 (i.e. all libs just found), and hdf5::hdf5_cpp
161+
# (i.e. C++ libs and dependencies). Only the latter should be necessary, but
162+
# we need the former due to https://gitlab.kitware.com/cmake/cmake/-/issues/27379
163+
set(HDF5_TARGET HDF5::HDF5;hdf5::hdf5_cpp)
160164
if (HDF5_FIND_DEBUG) # debugging print (re-use name of FindHDF5 CMake variable)
161165
cmake_print_properties(
162166
TARGETS HDF5::HDF5

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ option(BUILD_EXECUTABLES
2929
option(BUILD_SHARED_LIBS
3030
"Use shared libraries" OFF)
3131

32+
if (BUILD_SHARED_LIBS)
33+
# needed explicitly for the registries
34+
set(CMAKE_POSITION_INDEPENDENT_CODE True)
35+
endif()
36+
3237
### Settings for external libraries
3338

3439
if (LLN_FOUND)

src/IO/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ endif()
104104

105105
if (HAVE_HDF5)
106106
if (USE_HDF5_TARGET)
107-
target_link_libraries(${TARGET} PUBLIC HDF5::HDF5)
107+
target_link_libraries(${TARGET} PUBLIC ${HDF5_TARGET})
108108
else()
109109
target_include_directories(${TARGET} PUBLIC ${HDF5_INCLUDE_DIRS})
110110
target_link_libraries(${TARGET} PUBLIC ${HDF5_CXX_LIBRARIES})

src/buildblock/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ endif()
144144

145145
if (HAVE_HDF5)
146146
if (USE_HDF5_TARGET)
147-
target_link_libraries(${TARGET} PUBLIC HDF5::HDF5)
147+
target_link_libraries(${TARGET} PUBLIC ${HDF5_TARGET})
148148
else()
149149
# for GEHDF5, TODO remove once IO dependency added or GEHDF5Wrapper no longer includes H5Cpp.h
150150
target_include_directories(${TARGET} PRIVATE ${HDF5_INCLUDE_DIRS})

src/data_buildblock/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ set(TARGET ${STIR_BUILDBLOCK_LIB})
3939

4040
if (HAVE_HDF5)
4141
if (USE_HDF5_TARGET)
42-
target_link_libraries(${TARGET} PUBLIC HDF5::HDF5)
42+
target_link_libraries(${TARGET} PUBLIC ${HDF5_TARGET})
4343
else()
4444
# for GEHDF5, TODO remove once IO dependency added or GEHDF5Wrapper no longer includes H5Cpp.h
4545
target_include_directories(${TARGET} PRIVATE ${HDF5_INCLUDE_DIRS})

src/listmode_buildblock/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ set(TARGET ${STIR_BUILDBLOCK_LIB})
6161

6262
if (HAVE_HDF5)
6363
if (USE_HDF5_TARGET)
64-
target_link_libraries(${TARGET} PUBLIC HDF5::HDF5)
64+
target_link_libraries(${TARGET} PUBLIC ${HDF5_TARGET})
6565
else()
6666
# for GEHDF5, TODO remove once IO dependency added or GEHDF5Wrapper no longer includes H5Cpp.h
6767
target_include_directories(${TARGET} PRIVATE ${HDF5_INCLUDE_DIRS})

src/recon_buildblock/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ endif()
175175

176176
if (HAVE_HDF5)
177177
if (USE_HDF5_TARGET)
178-
target_link_libraries(${TARGET} PUBLIC HDF5::HDF5)
178+
target_link_libraries(${TARGET} PUBLIC ${HDF5_TARGET})
179179
else()
180180
# for GEHDF5, TODO remove once IO dependency added or GEHDF5Wrapper no longer includes H5Cpp.h
181181
target_include_directories(${TARGET} PRIVATE ${HDF5_INCLUDE_DIRS})

0 commit comments

Comments
 (0)