FindHDF5: HDF5_USE_STATIC_LIBRARIES does not find static HDF5 libraries
Environment
- CMake: 3.26.0
- OS: macOS Ventura
- HDF5: 1.12.2 (installed by brew: https://formulae.brew.sh/formula/hdf5)
Description
I'm using find_package(HDF5 REQUIRED)
to find HDF5 libraries and I want to prefer static library. According to https://cmake.org/cmake/help/latest/module/FindHDF5.html, I should set HDF5_USE_STATIC_LIBRARIES
to TRUE
. However it still gives me the shared library version. Below is the output after I set HDF5_FIND_DEBUG
to TRUE
:
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5_DIR: HDF5_DIR-NOTFOUND
-- HDF5_DEFINITIONS:
-- HDF5_INCLUDE_DIRS: /usr/local/Cellar/hdf5/1.12.2_2/include;/usr/local/opt/libaec/include
-- HDF5_LIBRARIES: /usr/local/Cellar/hdf5/1.12.2_2/lib/libhdf5.dylib;/usr/local/opt/libaec/lib/libsz.dylib;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libz.tbd;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libdl.tbd;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libm.tbd
-- HDF5_HL_LIBRARIES:
-- HDF5_C_DEFINITIONS:
-- HDF5_C_INCLUDE_DIR:
-- HDF5_C_INCLUDE_DIRS: /usr/local/Cellar/hdf5/1.12.2_2/include;/usr/local/opt/libaec/include
-- HDF5_C_LIBRARY:
-- HDF5_C_LIBRARIES: /usr/local/Cellar/hdf5/1.12.2_2/lib/libhdf5.dylib;/usr/local/opt/libaec/lib/libsz.dylib;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libz.tbd;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libdl.tbd;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libm.tbd
-- HDF5_C_HL_LIBRARY:
-- HDF5_C_HL_LIBRARIES:
-- Defined targets (if any):
-- ... hdf5::hdf5
I doubled checked that in my local, there are static libraries of HDF5:
(venv_tmp) $ ls /usr/local/Cellar/hdf5/1.12.2_2/lib
libhdf5.200.dylib libhdf5_cpp.200.dylib libhdf5_fortran.200.dylib libhdf5_hl.200.dylib libhdf5_hl_cpp.200.dylib libhdf5_hl_fortran.a libhdf5hl_fortran.dylib
libhdf5.a libhdf5_cpp.a libhdf5_fortran.a libhdf5_hl.a libhdf5_hl_cpp.a libhdf5hl_fortran.200.dylib
libhdf5.dylib libhdf5_cpp.dylib libhdf5_fortran.dylib libhdf5_hl.dylib libhdf5_hl_cpp.dylib libhdf5hl_fortran.a
Let me know if you need further info.
Edited by Qingran Zheng