Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed usage issue with FindZLIB.cmake module #4655

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions CMakeFilters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# [email protected].
#
option (HDF5_USE_ZLIB_NG "Use zlib-ng library as zlib library" OFF)
option (HDF5_USE_LIBAEC_STATIC "Use static AEC library" OFF)
option (HDF5_USE_ZLIB_STATIC "Find static zlib library" OFF)
option (HDF5_USE_LIBAEC_STATIC "Find static AEC library" OFF)
option (ZLIB_USE_EXTERNAL "Use External Library Building for ZLIB" OFF)
option (SZIP_USE_EXTERNAL "Use External Library Building for SZIP" OFF)

Expand Down Expand Up @@ -86,16 +87,29 @@ if (HDF5_ENABLE_Z_LIB_SUPPORT)
set (PACKAGE_NAME ${ZLIB_PACKAGE_NAME}${HDF_PACKAGE_EXT})
endif ()
set(ZLIB_FOUND FALSE)
find_package (ZLIB NAMES ${PACKAGE_NAME} COMPONENTS static shared)
if (HDF5_USE_ZLIB_STATIC)
set(ZLIB_SEACH_TYPE static)
else ()
set(ZLIB_SEACH_TYPE shared)
endif ()
find_package (ZLIB NAMES ${PACKAGE_NAME} COMPONENTS ${ZLIB_SEACH_TYPE})
if (NOT ZLIB_FOUND)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
set(ZLIB_USE_STATIC_LIBS ${HDF5_USE_ZLIB_STATIC})
endif()
find_package (ZLIB) # Legacy find
endif ()
set(H5_ZLIB_FOUND ${ZLIB_FOUND})
if (H5_ZLIB_FOUND)
set (H5_ZLIB_HEADER "zlib.h")
set (H5_ZLIB_INCLUDE_DIR_GEN ${ZLIB_INCLUDE_DIR})
set (H5_ZLIB_INCLUDE_DIRS ${H5_ZLIB_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${ZLIB_LIBRARIES})
# The FindZLIB.cmake module does not set an OUTPUT_NAME
# on the target. The target returned is: ZLIB::ZLIB
get_filename_component (libname ${ZLIB_LIBRARIES} NAME_WLE)
string (REGEX REPLACE "^lib" "" libname ${libname})
set_target_properties (ZLIB::ZLIB PROPERTIES OUTPUT_NAME zlib-static)
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ZLIB::ZLIB)
endif ()
else ()
if (HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "TGZ")
Expand Down Expand Up @@ -131,9 +145,14 @@ option (HDF5_ENABLE_SZIP_SUPPORT "Use SZip Filter" ON)
if (HDF5_ENABLE_SZIP_SUPPORT)
option (HDF5_ENABLE_SZIP_ENCODING "Use SZip Encoding" ON)
if (NOT SZIP_USE_EXTERNAL)
if (HDF5_USE_LIBAEC_STATIC)
set(LIBAEC_SEACH_TYPE static)
else ()
set(LIBAEC_SEACH_TYPE shared)
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 static shared)
find_package (SZIP NAMES ${LIBAEC_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS ${LIBAEC_SEACH_TYPE})
if (NOT SZIP_FOUND)
find_package (SZIP) # Legacy find
endif ()
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
)
endif ()

# Whether the most recently called project() command, in the current scope or above,
# was in the top level CMakeLists.txt file.
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.21.0")
if(NOT PROJECT_IS_TOP_LEVEL)
set (HDF5_EXTERNALLY_CONFIGURED 1)
endif()
else()
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set (HDF5_EXTERNALLY_CONFIGURED 1)
endif()
endif()
#-----------------------------------------------------------------------------
# Instructions for use : Sub-Project Build
#
Expand Down
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"HDF5_PACKAGE_EXTLIBS": "ON",
"HDF5_USE_ZLIB_NG": "OFF",
"ZLIB_USE_LOCALCONTENT": "OFF",
"LIBAEC_USE_LOCALCONTENT": "OFF"
"LIBAEC_USE_LOCALCONTENT": "OFF",
"HDF5_USE_ZLIB_STATIC": "ON",
"HDF5_USE_LIBAEC_STATIC": "ON"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions config/cmake/cacheinit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set (ZLIB_TGZ_ORIGPATH "https://github.com/madler/zlib/releases/download/v1.3" C
set (ZLIB_USE_LOCALCONTENT ON CACHE BOOL "Use local file for ZLIB FetchContent" FORCE)
set (ZLIB_GIT_URL "https://github.com/madler/zlib.git" CACHE STRING "Use ZLIB from GitHub repository" FORCE)
set (ZLIB_GIT_BRANCH "develop" CACHE STRING "" FORCE)
set (HDF5_USE_ZLIB_STATIC ON CACHE BOOL "Use static zlib library" FORCE)

set (ZLIBNG_PACKAGE_NAME "zlib-ng" CACHE STRING "Name of ZLIBNG package" FORCE)
set (ZLIBNG_TGZ_NAME "2.1.6.tar.gz" CACHE STRING "Use HDF5_ZLib from compressed file" FORCE)
Expand All @@ -65,6 +66,7 @@ set (LIBAEC_TGZ_ORIGPATH "https://github.com/MathisRosenhauer/libaec/releases/do
set (LIBAEC_USE_LOCALCONTENT ON CACHE BOOL "Use local file for LIBAEC FetchContent" FORCE)
set (LIBAEC_GIT_URL "https://github.com/MathisRosenhauer/libaec.git" CACHE STRING "Use LIBAEC from GitHub repository" FORCE)
set (LIBAEC_GIT_BRANCH "v1.1.3" CACHE STRING "" FORCE)
set (HDF5_USE_LIBAEC_STATIC ON CACHE BOOL "Use static AEC library" FORCE)

########################
# API test options
Expand Down
2 changes: 2 additions & 0 deletions release_docs/INSTALL_CMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,15 @@ else
ZLIB_TGZ_ORIGPATH "Use ZLIB from original location" "https://github.com/madler/zlib/releases/download/v1.2.13"
ZLIB_TGZ_NAME "Use ZLIB from original compressed file" "zlib-1.2.13.tar.gz"
ZLIB_USE_LOCALCONTENT "Use local file for ZLIB FetchContent" ON
HDF5_USE_ZLIB_STATIC "Find static zlib library" OFF

SZIP_USE_EXTERNAL "Use External Library Building for SZIP else search" OFF
if (HDF5_ENABLE_SZIP_SUPPORT)
HDF5_ENABLE_SZIP_ENCODING "Use SZip Encoding" ON
LIBAEC_TGZ_ORIGPATH "Use LIBAEC from original location" "https://github.com/MathisRosenhauer/libaec/releases/download/v1.1.3"
LIBAEC_TGZ_NAME "Use LIBAEC from original compressed file" "libaec-1.1.3.tar.gz"
LIBAEC_USE_LOCALCONTENT "Use local file for LIBAEC FetchContent" ON
HDF5_USE_LIBAEC_STATIC "Find static AEC library" OFF

PLUGIN_USE_EXTERNAL "Use External Library Building for PLUGINS else search" OFF
if (WINDOWS)
Expand Down
13 changes: 13 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,19 @@ Bug Fixes since HDF5-1.14.0 release

Configuration
-------------
- Fixed usage issue with FindZLIB.cmake module

When building HDF5 with CMake and relying on the FindZLIB.cmake module,
the Find module would correctly find the ZLIB library but not set an OUTPUT_NAME
on the target. Also, the target returned, ZLIB::ZLIB, was not in the ZLIB_LIBRARIES
variable. This caused issues when requesting the OUTPUT_NAME of the target in
the pkg-config settings.

Similar to HDF5_USE_LIBAEC_STATIC, "Find static AEC library", option, we added
a new option, HDF5_USE_ZLIB_STATIC, "Find static zlib library". These options
allow a user to specify whether to use a static or shared version of the compression
library in a find_package call.

- Corrected usage of FetchContent in the HDFLibMacros.cmake file.

CMake version 3.30 changed the behavior of the FetchContent module to deprecate
Expand Down
Loading