Issue when building hdf5 as submodule via `add_subdirectory`


#1

I am trying to build HDF5 as part of my project, but using a git submodule (pointing to release 1.10.6) via a CMake add_subdirectory.
In general, this works fine, however when I try to link hdf5-static, I am getting a build error "H5pubconf.h": No such file or directory

The reason for this is, that in scr\CMakeLists.txt you have the follwing code (line 1073 - 1077) (https://github.com/live-clones/hdf5/blob/1.10/master/src/CMakeLists.txt#L1073)

 add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} ${gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS})
 target_include_directories (${HDF5_LIB_TARGET}
     PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>"
     INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
 )

The problem here is, that when using hdf5 as part of the build, H5pubconf.h will be located inside ${HDF5_BINARY_DIR}, but this is added only as a PRIVATE requirement of target_include_directories, it needs to be either public, or both private and interface.
If you change the line starting with INTERFACE to the following code, the project builds fine:

INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>;$<BUILD_INTERFACE:${HDF5_BINARY_DIR}>"

Is this the correct way to create a bugreport? I’d be happy to make a pull request.


#2

Looks reasonable.

Should this be added to all the libraries that create headers?

Allen


#3

Yes, I would think so. If anyone using that library will (implicitly) include the generated headers, then yes, the line will have to be added for that library.