`export(EXPORT)` does not work for windows?

I am using the build directory’s ...Config.cmake file to test that the project works well with find_package. However, on windows this approach does not seem to work, giving me DLL_IMPORT errors. I am not sure what to make of this. Looking at the generated file it looks like:

add_library(Spglib::symspg SHARED IMPORTED)

set_target_properties(Spglib::symspg PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "D:/a/spglib/spglib/cmake-build-ci-windows/src"
)

# Import target "Spglib::symspg" for configuration "RelWithDebInfo"
set_property(TARGET Spglib::symspg APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(Spglib::symspg PROPERTIES
  IMPORTED_IMPLIB_RELWITHDEBINFO "D:/a/spglib/spglib/cmake-build-ci-windows/lib/symspg.lib"
  IMPORTED_LOCATION_RELWITHDEBINFO "D:/a/spglib/spglib/cmake-build-ci-windows/bin/symspg.dll"
  )

Not sure how the install one is supposed to look like and what is responsible for populating Path in order for a test executable to be runable from there.

Whatever you want to do with this cmake snipped, is seems completly wrong to me!

Have a look at ClausKlein/ModernCppStarter: :rocket: Kick-start your C++! A template for modern C++ projects using CMake, CI, code coverage, clang-format, reproducible dependency management and much more. (github.com)

or Professional CMake: A Practical Guide (crascit.com)

The snippet is the the snippet from the generated Targets.cmake file. The using snippet is the general use:

find_package(Spglib REQUIRED)

add_executable(main_c src/main.c)
target_link_libraries(main_c PRIVATE Spglib::symspg)

I am looking into this approach to more generally add the dll to targets.

This is not quite easy!
see CppCon 2019: Deep CMake For Library Authors - Crascit

Not sure what you mean by that link:

  • I have opened a discussion about the design of GenerateExportHeader
  • Most of the contents I am already implementing. Currently working on this if more context is helpful
  • The issue here is more along the line of how export(EXPORT) creates the targets for build so that an executable can be run. Alex’s SO approach with TARGET_RUNTIME_DLL_DIRS is indeed very, although it is cumbersome to implement

YES, it is!

If have implemented it to today: Use GenerateExportHeader by ClausKlein · Pull Request #1 · ClausKlein/spglib (github.com)

I think these issues are along the lines of what you’re looking for:

Thanks Ben, indeed I have converged to a similar approach. It would be nice if export(EXPORT) were able to take care of that similar to RPATH, like populating ENVIRONMENT_MODIFICATIONS , but there is no mechanism for propagating properties like INTERFACE, so indeed I can’t see a way around it.