Can't perform find_package(hdf5 REQUIRED) in CMake

Hi,

I’m trying to use HDF5 as an external project while CMake superbuild (inside Slicer 3D application). My test project where you can see the CMake files is located here.
The problem is that after CMake builds HDF5 I cannot perform find_package(hdf5 REQUIRED). This command gives me error:


CMake Warning (dev) at C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:424 (message):
The package name passed to find_package_handle_standard_args (HDF5) does
not match the name of the calling package (hdf5). This can lead to
problems in calling code that expects find_package result variables
_(e.g., FOUND) to follow a certain pattern.
Call Stack (most recent call first):
C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindHDF5.cmake:975 (find_package_handle_standard_args)
C:/S/d/VTK/CMake/FindHDF5.cmake:9 (include)
KKK/CMakeLists.txt:10 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.

– Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version “”)


If I change lower case find_package(hdf5 REQUIRED) to upper case find_package(HDF5 REQUIRED) then I get the following error:


CMake Error at C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
_ Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found_
_ version “”)_


I need help to overcome this problem

Windows 10 x64, MSVC 2019 x64, HDF5 git-tag hdf5-1_12_0 and hdf-1_10_7, CMAKE 3.13.4

I think the main reason is that hdf5-config.cmake stores wrong information about where hdf5 is located.
The command find_package(hdf5 REQUIRED CONFIG) gives me error:
CMake Error at C:/S/extensions/Proba_fixed/Proba-build/hdf5-build/hdf5-config.cmake:25 (message):
File or directory C:/S/extensions/Proba_fixed/bin referenced by variable HDF5_TOOLS_DIR does not exist !

But hdf5 is build in here C:\S\extensions\Proba_fixed\Proba-build and the bin folder lives there: C:\S\extensions\Proba_fixed\Proba-build\bin

Could you try a development build of hdf5, a recent change moved where the hdf5-config files are located on windows. Any of the branches from git should be sufficient for the test.

Allen

Thank you for hint

I’m trying to build dev branch but whenI build it I always get the error:
fatal error C1083: Cannot open include file: ‘H5version.h’: No such file or directory

Can’t understand how to overcome this.

Windows 10 x64, CMake 3.19.0, MSVC 2019 x64 v142

Sorry, I forgot, dev branch requires the HDF5_GENERATE_HEADERS to be ON. release branches do not need this.

Allen

It seems that HDF5_GENERATE_HEADERS were ON by default but I got this error.
I’m gonna turn ON/OFF and will report

You can check the config/cmake/cacheinit.cmake file for the settings we use in our daily tests. Might be some clues.

Allen

thank you

It seems that after I downloaded Perl the HDF5-dev build is fine.
But I still get error when I try to compile HDF5 as an external package:

File or directory C:/S/extensions/bin referenced by variable HDF5_TOOLS_DIR does not exist !

It is strange that it used to be C:/S/extensions/Proba_fixed/bin but now the path is C:/S/extensions/bin

In my ExternalProject_Add(...) I have:
GIT_REPOSITORY "git://github.com/HDFGroup/hdf5.git"
GIT_TAG "develop"
I think that is correct to force CMake to build HDF5-dev branch?

  ExternalProject_Add(${proj}
    ${${proj}_EP_ARGS}
    GIT_REPOSITORY "${${CMAKE_PROJECT_NAME}_${proj}_GIT_REPOSITORY}"
    GIT_TAG "${${CMAKE_PROJECT_NAME}_${proj}_GIT_TAG}"
    SOURCE_DIR ${EP_SOURCE_DIR}
    BINARY_DIR ${EP_BINARY_DIR}
    CMAKE_CACHE_ARGS
      # Compiler settings
      -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
      -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags}
      -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
      -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags}
      -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
      -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED}
      -DCMAKE_CXX_EXTENSIONS:BOOL=${CMAKE_CXX_EXTENSIONS}
      # Output directories
      -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CMAKE_BINARY_DIR}/${Slicer_THIRDPARTY_BIN_DIR}
      -DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CMAKE_BINARY_DIR}/${Slicer_THIRDPARTY_LIB_DIR}
      -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
#      -DCMAKE_PDB_OUTPUT_DIRECTORY:PATH=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
      # Install directories
      -Dhdf5_INSTALL_RUNTIME_DIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR}
      -Dhdf5_INSTALL_LIBRARY_DIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR}
      -DCMAKE_INSTALL_LIBDIR:STRING=${Slicer_INSTALL_THIRDPARTY_LIB_DIR} # Skip default initialization by GNUInstallDirs CMake module
      # Options
      -DBUILD_TESTING:BOOL=OFF
      -DBUILD_SHARED_LIBS:BOOL=ON
      -DBUILD_STATIC_LIBS:BOOL=ON
      -DHDF5_EXTERNALLY_CONFIGURED:BOOL=ON
      -DHDF5_BUILD_TOOLS:BOOL=ON
      -DHDF5_TEST_TOOLS:BOOL=ON
      -DHDF5_GENERATE_HEADERS:BOOL=ON
    INSTALL_COMMAND ""
    DEPENDS
      ${${proj}_DEPENDS}
    )

You should be right. I think the problem is that hdf5-config.cmake is located in wrong directory (it is in C:/.../hdf5-build dir).

I just tried to move this file two folders down (in C:/.../hdf5-build/src/CMakeFiles dir) and the command find_package(hdf5 REQUIRED CONFIG PATHS "C:/S/extensions/Proba_fixed/Proba-build/hdf5-build/src") didn’t give me the mentionned error but I got another one:
CMake Error at C:/S/extensions/Proba_fixed/Proba-build/hdf5-build/src/CMakeFiles/hdf5-config.cmake:144 (include):
include could not find load file:
C:/S/extensions/Proba_fixed/Proba-build/share/cmake/hdf5/hdf5-targets.cmake

while hdf5_FOUND returns TRUE

I think I cannot solve this issue by myself