Skip to content

Commit

Permalink
Check presumptive cmake targets before use
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Jan 22, 2025
1 parent 7584d5a commit 89e5446
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions cmake/HDF5TargetUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,31 @@ function(h5pp_get_modern_hdf5_target_name)
list(APPEND HDF5_TARGET_NAMES hdf5 hdf5_hl hdf5_cpp hdf5_hl_cpp hdf5_cpp_hl hdf5_fortran hdf5_fortran_hl)
foreach(name ${HDF5_TARGET_NAMES})
foreach(tgt ${name} ${name}-static ${name}-shared hdf5::${name} hdf5::${name}-static hdf5::${name}-shared )
if(TARGET ${tgt})
# tgt is not self-contained!
if(name STREQUAL "hdf5")
if(${tgt} MATCHES "static")
list(APPEND HDF5_C_STATIC_TARGET ${tgt})
elseif(${tgt} MATCHES "shared")
list(APPEND HDF5_C_SHARED_TARGET ${tgt})
else()
list(APPEND HDF5_C_UNKNOWN_TARGET ${tgt})
endif()
if(NOT TARGET ${tgt})
continue()
endif()
# tgt is not self-contained!
if(name STREQUAL "hdf5")
if(${tgt} MATCHES "static")
list(APPEND HDF5_C_STATIC_TARGET ${tgt})
elseif(${tgt} MATCHES "shared")
list(APPEND HDF5_C_SHARED_TARGET ${tgt})
else()
if(${tgt} MATCHES "static")
list(APPEND HDF5_X_STATIC_TARGETS ${tgt})
elseif(${tgt} MATCHES "shared")
list(APPEND HDF5_X_SHARED_TARGETS ${tgt})
else()
list(APPEND HDF5_X_UNKNOWN_TARGETS ${tgt})
endif()
list(APPEND HDF5_C_UNKNOWN_TARGET ${tgt})
endif()
else()
if(${tgt} MATCHES "static")
list(APPEND HDF5_X_STATIC_TARGETS ${tgt})
elseif(${tgt} MATCHES "shared")
list(APPEND HDF5_X_SHARED_TARGETS ${tgt})
else()
list(APPEND HDF5_X_UNKNOWN_TARGETS ${tgt})
endif()
endif()
endforeach()
endforeach()

unset(HDF5_C_TARGET)
unset(HDF5_X_TARGETS)
if(BUILD_SHARED_LIBS OR NOT HDF5_USE_STATIC_LIBRARIES)
# Prefer shared
if(HDF5_C_SHARED_TARGET AND HDF5_X_SHARED_TARGETS)
Expand Down Expand Up @@ -211,6 +213,9 @@ function(h5pp_get_modern_hdf5_target_name)

# Check whether zlib or szip are linked to the targets, and make sure we can find them
foreach (tgt ${HDF5_X_TARGETS};${HDF5_C_TARGET})
if(NOT TARGET ${tgt})
continue()
endif ()
get_target_property(HDF5_INTERFACE_LINK_LIBRARIES ${tgt} INTERFACE_LINK_LIBRARIES)
foreach (ltgt ${HDF5_INTERFACE_LINK_LIBRARIES})
if(ltgt MATCHES "ZLIB::ZLIB")
Expand Down

0 comments on commit 89e5446

Please sign in to comment.