From b31c318d84e3099fb7ce0b57a04fcfd1fd490700 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sun, 13 Oct 2024 15:28:33 -0400 Subject: [PATCH] Fix CMake build detection of `libaec` Partial revert of https://github.com/HDFGroup/hdf5/pull/4567 as libaec is the correct name of the package and should be searched first. Also fixes pkg-config generation handling. This does mean the output CMake configuration files need to `find_package(libaec)` prior to `hdf5-static`, but it also avoids using absolute path to shared library so that users can do `set(libaec_USE_STATIC_LIBS ON)`. --- CMakeFilters.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeFilters.cmake b/CMakeFilters.cmake index 3eca6e743c8..255b72be122 100644 --- a/CMakeFilters.cmake +++ b/CMakeFilters.cmake @@ -160,15 +160,27 @@ if (HDF5_ENABLE_SZIP_SUPPORT) endif () set(libaec_USE_STATIC_LIBS ${HDF5_USE_LIBAEC_STATIC}) set(SZIP_FOUND FALSE) - find_package (SZIP NAMES ${LIBAEC_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS ${LIBAEC_SEACH_TYPE}) + find_package (libaec CONFIG) if (NOT SZIP_FOUND) - find_package (SZIP) # Legacy find + find_package (SZIP NAMES ${LIBAEC_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS ${LIBAEC_SEACH_TYPE}) # Legacy find + if (NOT SZIP_FOUND) + find_package (SZIP) # Legacy find + endif () endif () set(H5_SZIP_FOUND ${SZIP_FOUND}) if (H5_SZIP_FOUND) set (H5_SZIP_INCLUDE_DIR_GEN ${SZIP_INCLUDE_DIR}) set (H5_SZIP_INCLUDE_DIRS ${H5_SZIP_INCLUDE_DIRS} ${SZIP_INCLUDE_DIR}) - set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_LIBRARIES}) + if (TARGET libaec::sz) + # The libaec-config.cmake does not set an OUTPUT_NAME + # on the target. The target returned is: libaec::sz + get_filename_component (libname ${SZIP_LIBRARIES} NAME_WLE) + string (REGEX REPLACE "^lib" "" libname ${libname}) + set_target_properties (libaec::sz PROPERTIES OUTPUT_NAME ${libname}) + set (LINK_COMP_LIBS ${LINK_COMP_LIBS} libaec::sz) + else () + set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_LIBRARIES}) + endif () endif () else () if (HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "TGZ")