find_package(HDF5 COMPONENTS ...) cannot be called twice with different components
The following fails on multiple systems, including Ubuntu 18.04 with standard hdf5 installed
cmake_minimum_required(VERSION 3.17)
PROJECT(TEST)
find_package(HDF5 COMPONENTS C)
message(STATUS "Now looking for CXX")
find_package(HDF5 COMPONENTS CXX REQUIRED)
The second find_package
fails (see below for diagnostic output). Looking twice for C
or CXX
works fine. Somewhat unexpectedly (for me), you can first search only for C
, then modify the CMakeLists.txt
to only look for CXX
(libraries will be set correctly).
We noticed this problem when doing find_package
for 2 dependencies (ISMRRMD and STIR whose config files search for HDF5 (C
and CXX
respectively).
Output of cmake .. -DHDF5_FIND_DEBUG=ON
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.0.1") found components: C
-- HDF5_DIR: HDF5_DIR-NOTFOUND
-- HDF5_DEFINITIONS: -D_FORTIFY_SOURCE=2
-- HDF5_INCLUDE_DIRS: /usr/include/hdf5/serial
-- HDF5_LIBRARIES: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so
-- HDF5_HL_LIBRARIES:
-- HDF5_C_DEFINITIONS: -D_FORTIFY_SOURCE=2
-- HDF5_C_INCLUDE_DIR:
-- HDF5_C_INCLUDE_DIRS: /usr/include/hdf5/serial
-- HDF5_C_LIBRARY:
-- HDF5_C_LIBRARIES: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so
-- HDF5_C_HL_LIBRARY:
-- HDF5_C_HL_LIBRARIES:
-- Now looking for CXX
CMake Error at /usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
Could NOT find HDF5 (missing: CXX) (found version "1.10.0.1")
Call Stack (most recent call first):
/usr/local/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.17/Modules/FindHDF5.cmake:929 (find_package_handle_standard_args)
CMakeLists.txt:7 (find_package)