hdf5 icon indicating copy to clipboard operation
hdf5 copied to clipboard

The cmake configuration should provide transitive dependencies (like `shlwapi` on MSVC)

Open emmenlau opened this issue 1 year ago • 4 comments

cmake is very good in collecting the list of library dependencies transitively for project trees. This typically works via the list of linker libraries. In order to make use of the automatic dependency tracking feature, dependencies that need to be linked downstream must be listed PUBLIC in the project. Every such PUBLIC dependency will then be linked into the final executable, and in turn, its dependencies are also (transitively) resolved and linked.

Since https://github.com/HDFGroup/hdf5/pull/2407, hdf5 has a dependency on shlwapi on MSVC. However this seems not to be exposed to cmake. At least, when I use the following code in cmake, the build lacks a linker dependency on shlwapi. I could not find out how to instruct cmake with hdf5 to get this dependency resolved. I can resolve it by linking shlwapi myself. But this is not ideal, because I need to maintain the dependency list of hdf5 in my own (user) code. This is unfortunate, because it creates an extra burden on users to keep dependency lists updated, which can be quite tedious for large software projects.

Expected behavior The following used to work until about a year ago. But it is no longer sufficient for me since the current release. This, or something similar, should just work:

  find_package(HDF5 MODULE REQUIRED COMPONENTS C)

  target_include_directories(mylibrary SYSTEM INTERFACE ${HDF5_INCLUDE_DIRS})
  target_link_libraries(mylibrary INTERFACE ${HDF5_LIBRARIES}) 
  target_compile_definitions(mylibrary INTERFACE ${HDF5_DEFINITIONS})

Platform (please complete the following information)

  • HDF5 version: 1.14.2
  • OS and version: Windows 11
  • Compiler and version: Visual Studio 17.7.5 with LLVM clang-cl 16.0.6
  • Build system (e.g. CMake, Autotools) and version: cmake 3.27.7
  • Any configure options you specified:
    "-DBUILD_SHARED_LIBS=OFF"
    "-DBUILD_STATIC_LIBS=ON"
    "-DONLY_SHARED_LIBS=OFF"
  • MPI library and version (parallel HDF5): No MPI

Additional context None.

emmenlau avatar Oct 12 '23 07:10 emmenlau

The dependency for shlwapi is already included in config/cmake/ConfigureChecks.cmake, as of https://github.com/HDFGroup/hdf5/pull/2407, 2023 January.

if (WINDOWS)
  CHECK_INCLUDE_FILE_CONCAT ("shlwapi.h"         ${HDF_PREFIX}_HAVE_SHLWAPI_H)
  # Checking for StrStrIA in the library is not reliable for mingw32 to stdcall
  set (LINK_LIBS ${LINK_LIBS} "shlwapi")
endif ()

That is an interesting comment in the middle, there.

The current problem is not lack of inclusion. It looks like Cmake is already instructed correctly. This is a failure of Cmake's find_package mechanism in certain Windows configurations. I suggest look into that. Perhaps compare the build environments between working and non-working scenarios. Compiler versions, etc.

Dave-Allured avatar Oct 20 '23 16:10 Dave-Allured

We have the same problem after update VCPKG latest.

Functions from szip and shlwapi doesnt visible by linker (static builds).

sergii-rybin-tfs avatar Nov 02 '23 18:11 sergii-rybin-tfs

I can confirm the issue is not fixed at the time being.

duburcqa avatar Dec 07 '23 09:12 duburcqa

I have this same problem. What I'm doing is compiling the hdf5 as a static library, then linking that into a NetCDF library (dll) build on Visual Studio 2022, all using unmodified CMakeLists.txt files from the respective projects. If I open the generated netCDF.sln file and add shlwapi.lib manually to 'Additional Dependencies' in the linker input, it links OK. Without that, it complains about a missing import symbol __imp_StrStrIA from libhdf5.lib (H5system.obj). So it seems that indeed passing on the dependency from hdf5 to the NetCDF build system (which is also CMake based) fails. What's worse is that there doesn't seem to be a way to add libraries to a cmake build from the command line, so as far as I can tell I'm stuck with manually fixing up the generated Visual Studio project files to get things to build. I'm not an expert on CMake but it seems that the config\cmake\ConfigureChecks.cmake mentioned above is only used when hdf5 is used through the CMake package system, but I'm passing the paths to its libraries and header file location manually to my NetCDF builds and I think I'm therefore not using hdf5's ConfigureChecks.cmake ?

roel-v avatar Dec 21 '23 12:12 roel-v

Kindly pinging this issue...

emmenlau avatar Aug 07 '24 16:08 emmenlau