h5pp icon indicating copy to clipboard operation
h5pp copied to clipboard

Using H5PP as a subproject

Open ryakoub opened this issue 10 months ago • 2 comments

Hello,

I am able to build H5PP standalone which is able to find and build hdf5 fine. My goal is to include h5pp as a submodule. I created a CMake project that has the following:

cmake_minimum_required(VERSION 3.15)
project(HDFWrapper)

set(CMAKE_MODULE_PATH
    ${CMAKE_MODULE_PATH}
    ${CMAKE_CURRENT_SOURCE_DIR}/deps/h5pp/cmake
    ${CMAKE_CURRENT_SOURCE_DIR}/deps/h5pp/cmake/modules
)

# Set H5PP Options
set(H5PP_ENABLE_EIGEN3 OFF)
set(H5PP_ENABLE_FMT OFF)
set(H5PP_ENABLE_SPDLOG OFF)
set(H5PP_ENABLE_TESTS OFF)
set(H5PP_ENABLE_EXAMPLES OFF)
set(BUILD_SHARED_LIBS OFF)
set(H5PP_IS_SUBPROJECT ON)

# Add the HDF5 submodule
add_subdirectory(deps/h5pp)

# Add your executable or library
add_executable(hdf_rw hdf_rw.cpp)

# Link your project to the HDF5 static library
target_link_libraries(hdf_rw PRIVATE h5pp::h5pp)

But with this it is unable to download and find the hdf5 package. What am I missing? Thank you.

ryakoub avatar Feb 27 '25 21:02 ryakoub

Hi! In plain subdirectory mode, h5pp does not automate the installation of dependencies, it will just call find_package(HDF5 ...) as usual.

To access automated installations, use the dependency provider mechanism, which installs the enabled dependencies upon encountering the first find_package call. h5pp bundles two different dependency providers:

  • cmake/conan_dependency_provider/conan_provider.cmake to let the conan package manager handle the installation, or
  • cmake/cmake_dependency_provider/cmake_provider.cmake which relies exclusively on cmake.

To pick a dependency provider, set the CMake flag CMAKE_PROJECT_TOP_LEVEL_INCLUDES to one of the paths above before the first call to project().

DavidAce avatar Mar 03 '25 10:03 DavidAce

Thank you. This worked. One suggestion though on:

if(TARGET ZLIB::ZLIB)
    target_link_libraries(HDF5::HDF5 INTERFACE ZLIB::ZLIB)
endif()
if(TARGET SZIP::SZIP)
    target_link_libraries(HDF5::HDF5 INTERFACE SZIP::SZIP)
endif()

to change ZLIB::ZLIB to target name as it might be included in a project that already defining zlib differently.

ryakoub avatar Mar 04 '25 00:03 ryakoub