Skip to content

Commit

Permalink
Only call find_package once, by default module mode for zlib (#5284)
Browse files Browse the repository at this point in the history
* Update workflow and mark options advanced
  • Loading branch information
byrnHDF authored Jan 31, 2025
1 parent 808395c commit 3d07387
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 17 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/main-cmake-spc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,64 @@ jobs:
run: ctest . --parallel 2 -C Debug -V
working-directory: ${{ runner.workspace }}/build

build_system_zlib:
name: "gcc system zlib"
runs-on: ubuntu-latest
steps:
# SETUP
- name: Install Linux Dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build doxygen graphviz
sudo apt install libssl3 libssl-dev libcurl4 libcurl4-openssl-dev
sudo apt install gcc-12 g++-12 gfortran-12 zlib1g-dev
echo "CC=gcc-12" >> $GITHUB_ENV
echo "CXX=g++-12" >> $GITHUB_ENV
echo "FC=gfortran-12" >> $GITHUB_ENV
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Get Sources
uses: actions/[email protected]

# CMAKE CONFIGURE
- name: CMake Configure
run: |
mkdir "${{ runner.workspace }}/build"
cd "${{ runner.workspace }}/build"
cmake -C $GITHUB_WORKSPACE/config/cmake/cacheinit.cmake \
-G Ninja \
--log-level=VERBOSE \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DHDF5_ENABLE_ALL_WARNINGS:BOOL=ON \
-DHDF5_ENABLE_PARALLEL:BOOL=OFF \
-DHDF5_BUILD_CPP_LIB:BOOL=ON \
-DHDF5_BUILD_FORTRAN:BOOL=ON \
-DHDF5_BUILD_JAVA:BOOL=ON \
-DHDF5_BUILD_DOC:BOOL=OFF \
-DHDF5_ENABLE_MIRROR_VFD:BOOL=ON \
-DHDF5_ENABLE_DIRECT_VFD:BOOL=ON \
-DHDF5_ENABLE_ROS3_VFD:BOOL=ON \
-DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="NO" \
-DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
-DZLIB_USE_LOCALCONTENT:BOOL=OFF \
-DZLIB_USE_EXTERNAL:BOOL=OFF \
-DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF \
-DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF \
-DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \
$GITHUB_WORKSPACE
shell: bash

# BUILD
- name: CMake Build
run: cmake --build . --parallel 3 --config Debug
working-directory: ${{ runner.workspace }}/build

# RUN TESTS
- name: CMake Run Tests
run: ctest . --parallel 2 -C Debug -V
working-directory: ${{ runner.workspace }}/build

build_zlibng:
name: "gcc use zlib-ng filter"
runs-on: ubuntu-latest
Expand Down
46 changes: 29 additions & 17 deletions CMakeFilters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ option (HDF5_USE_ZLIB_NG "Use zlib-ng library as zlib 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)
mark_as_advanced (ZLIB_USE_EXTERNAL)
option (SZIP_USE_EXTERNAL "Use External Library Building for SZIP" OFF)
mark_as_advanced (SZIP_USE_EXTERNAL)
option (ZLIB_USE_LOCALCONTENT "Use local file for ZLIB FetchContent" OFF)
mark_as_advanced (ZLIB_USE_LOCALCONTENT)
option (LIBAEC_USE_LOCALCONTENT "Use local file for LIBAEC FetchContent" OFF)
mark_as_advanced (LIBAEC_USE_LOCALCONTENT)

if (NOT ZLIB_USE_LOCALCONTENT)
if (HDF5_USE_ZLIB_NG)
Expand Down Expand Up @@ -88,26 +92,32 @@ endif ()
if (HDF5_ENABLE_Z_LIB_SUPPORT)
if (NOT H5_ZLIB_HEADER)
if (NOT ZLIB_USE_EXTERNAL)
option (HDF5_MODULE_MODE_ZLIB "Find the default system ZLIB in module mode" ON)
mark_as_advanced (HDF5_MODULE_MODE_ZLIB)
if (HDF5_USE_ZLIB_NG)
set (HDF5_MODULE_MODE_ZLIB OFF CACHE BOOL "" FORCE)
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_MODULE_MODE_ZLIB)
# Expect that the default shared library is expected with FindZLIB.cmake
find_package (ZLIB MODULE)
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})
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 @@ -116,11 +126,13 @@ if (HDF5_ENABLE_Z_LIB_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
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 @@ -880,6 +880,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" ON
HDF5_MODULE_MODE_ZLIB "Find the default system ZLIB in module mode" ON
HDF5_ENABLE_Z_LIB_SUPPORT "Enable Zlib Filters" ON

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 @@ -136,6 +136,13 @@ Bug Fixes since HDF5-1.14.5 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_MODULE_MODE_ZLIB 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

0 comments on commit 3d07387

Please sign in to comment.