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

Use only one find_package call for zlib. #5280

Merged
merged 16 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
42 changes: 23 additions & 19 deletions CMakeFilters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,33 @@ endif ()
if(NOT DEFINED ZLIBNG_PACKAGE_NAME)
set(ZLIBNG_PACKAGE_NAME "zlib-ng")
endif ()
option (HDF5_ENABLE_ZLIB_SUPPORT "Enable Zlib Filters" OFF)
if (HDF5_ENABLE_ZLIB_SUPPORT)
if (NOT H5_ZLIB_HEADER)
if (NOT ZLIB_USE_EXTERNAL)
option (HDF5_DEFAULT_ZLIB_SYSTEM "Use the default system installed ZLIB" ON)
if (HDF5_USE_ZLIB_NG)
set (PACKAGE_NAME ${ZLIBNG_PACKAGE_NAME}${HDF_PACKAGE_EXT})
else ()
set (PACKAGE_NAME ${ZLIB_PACKAGE_NAME}${HDF_PACKAGE_EXT})
endif ()
set(ZLIB_FOUND FALSE)
if (HDF5_USE_ZLIB_STATIC)
set(ZLIB_SEARCH_TYPE static)
message (VERBOSE "Filter HDF5_ZLIB package name:${PACKAGE_NAME}")
if (HDF5_DEFAULT_ZLIB_SYSTEM)
# Expect that the default shared library is expected with FindZLIB.cmake
find_package (ZLIB MODULE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
find_package (ZLIB MODULE)
find_package (ZLIB MODULE REQUIRED)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #5306 created

else ()
set(ZLIB_SEARCH_TYPE shared)
endif ()
# Search pure Config mode first
find_package (ZLIB NAMES ${PACKAGE_NAME} OPTIONAL_COMPONENTS ${ZLIB_SEARCH_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
# Expect that a correctly built library with CMake config files is available
if (HDF5_USE_ZLIB_STATIC)
set(ZLIB_SEARCH_TYPE static)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
set(ZLIB_USE_STATIC_LIBS ${HDF5_USE_ZLIB_STATIC})
endif()
else ()
set(ZLIB_SEARCH_TYPE shared)
endif ()
find_package (ZLIB NAMES ${PACKAGE_NAME} CONFIG OPTIONAL_COMPONENTS ${ZLIB_SEARCH_TYPE})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
find_package (ZLIB NAMES ${PACKAGE_NAME} CONFIG OPTIONAL_COMPONENTS ${ZLIB_SEARCH_TYPE})
find_package (ZLIB NAMES ${PACKAGE_NAME} CONFIG REQUIRED OPTIONAL_COMPONENTS ${ZLIB_SEARCH_TYPE})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #5306 created

endif ()
set(H5_ZLIB_FOUND ${ZLIB_FOUND})
set(H5_ZLIB_FOUND ZLIB_FOUND})
if (H5_ZLIB_FOUND)
if (HDF5_USE_ZLIB_NG)
set (H5_ZLIB_HEADER "zlib-ng.h")
Expand All @@ -117,11 +120,13 @@ if (HDF5_ENABLE_ZLIB_SUPPORT)
endif ()
set (H5_ZLIB_INCLUDE_DIR_GEN ${ZLIB_INCLUDE_DIR})
set (H5_ZLIB_INCLUDE_DIRS ${H5_ZLIB_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
# 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 ${libname})
if (NOT WIN32) #windows has a list of names
# 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 ${libname})
endif ()
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ZLIB::ZLIB)
endif ()
else ()
Expand Down Expand Up @@ -161,7 +166,6 @@ set(H5_SZIP_FOUND FALSE)
if(NOT DEFINED LIBAEC_PACKAGE_NAME)
set(LIBAEC_PACKAGE_NAME "libaec")
endif ()
option (HDF5_ENABLE_SZIP_SUPPORT "Use SZip Filter" OFF)
if (HDF5_ENABLE_SZIP_SUPPORT)
option (HDF5_ENABLE_SZIP_ENCODING "Use SZip Encoding" ON)
if (NOT SZIP_USE_EXTERNAL)
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ if (POLICY CMP0074)
cmake_policy (SET CMP0074 NEW)
endif ()

if (POLICY CMP0144)
# <PACKAGENAME> is the upper-cased package name.
cmake_policy (SET CMP0144 NEW)
endif ()

if (POLICY CMP0083)
# To control generation of Position Independent Executable (PIE) or not,
# some flags are required at link time.
Expand Down
1 change: 1 addition & 0 deletions release_docs/INSTALL_CMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ if (BUILD_TESTING)
HDF5_ALLOW_EXTERNAL_SUPPORT "Allow External Library Building (NO GIT TGZ)" "NO"
HDF5_ENABLE_PLUGIN_SUPPORT "Enable PLUGIN Filters" OFF
HDF5_ENABLE_SZIP_SUPPORT "Use SZip Filter" OFF
HDF5_DEFAULT_ZLIB_SYSTEM "Use the default system installed ZLIB" ON
HDF5_ENABLE_ZLIB_SUPPORT "Enable Zlib Filters" OFF

if (HDF5_USE_ZLIB_NG)
Expand Down
7 changes: 7 additions & 0 deletions release_docs/RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ Bug Fixes since HDF5-2.0.0 release

Configuration
-------------
- When using a system installed zlib library, the shared library is expected to
be found in the system library path.

Setting the HDF5_DEFAULT_ZLIB_SYSTEM option to OFF, the system installed zlib,
or an alternate installed zlib library, is expected to have a correct
zlib-config.cmake file.

- Use pre-installed libaec compression library

The CMake logic for finding the libaec compression library has been
Expand Down
Loading