Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
emmenlau opened this issue Oct 12, 2023 · 5 comments · Fixed by #4701
Closed
Assignees
Labels
Component - Build CMake, Autotools Priority - 2. Medium ⏹ It would be nice to have this in the next release Type - Bug Please report security issues to help@hdfgroup.org instead of creating an issue on GitHub
Milestone

Comments

@emmenlau
Copy link

emmenlau commented Oct 12, 2023

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 #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.

@mattjala mattjala added Priority - 2. Medium ⏹ It would be nice to have this in the next release Component - Build CMake, Autotools Type - Bug Please report security issues to help@hdfgroup.org instead of creating an issue on GitHub labels Oct 12, 2023
@derobins derobins added this to the 1.14.3 milestone Oct 13, 2023
@Dave-Allured
Copy link
Contributor

The dependency for shlwapi is already included in config/cmake/ConfigureChecks.cmake, as of #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.

@derobins derobins modified the milestones: 1.14.3, 1.14.4 Oct 21, 2023
@sergii-rybin-tfs
Copy link

We have the same problem after update VCPKG latest.

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

@duburcqa
Copy link

duburcqa commented Dec 7, 2023

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

@roel-v
Copy link

roel-v commented Dec 21, 2023

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 ?

@derobins derobins self-assigned this Jan 19, 2024
@derobins derobins modified the milestones: 1.14.4, 1.14.5 Apr 18, 2024
@emmenlau
Copy link
Author

emmenlau commented Aug 7, 2024

Kindly pinging this issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Build CMake, Autotools Priority - 2. Medium ⏹ It would be nice to have this in the next release Type - Bug Please report security issues to help@hdfgroup.org instead of creating an issue on GitHub
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants