ThePhD / infoware

C++ Library for pulling system and hardware information, without hitting the command line.
Creative Commons Zero v1.0 Universal
410 stars 84 forks source link

Fix CMake export containing reference to missing target #60

Closed merwaaan closed 2 years ago

merwaaan commented 2 years ago

Hi,

CMake causes issues on Windows because the generated export inherits a string from the build script that contains generator expressions that are successfully evaluated at generation time, but they cannot be evaluated at import time (due to the missing target).

The generated code in infowareConfig.cmake looks like this, with the escaped expression from the generation script:

set_target_properties(infoware PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "\$<\$<STREQUAL:\$<TARGET_PROPERTY:infoware,TYPE>,SHARED_LIBRARY>:INFOWARE_DLL=1>"
  ...
)

This commit replaces the generator expression with a plain condition based on BUILD_SHARED_LIBS, which already controls the behavior of add_library used earlier.

This changes the content of the import script with:

set_target_properties(infoware PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "INFOWARE_DLL=1"
  ...
)

(when building a shared library, otherwise INFOWARE_DLL is not defined).

This fixes the import on Windows.

ThePhD commented 2 years ago

I wonder if we can keep the generator expression and simply use string(generate ...) from CMake instead, to just have it evaluate the generator expression directly into a string and then vomit it out into the export...

nabijaczleweli commented 2 years ago

I'm on Windows and it builds for me, but then I'm far from a CMake enjoyer.

Applied as 55f8b9b8b3e4ef665bec4477cb5021e6922960ec with minor editorial, cheers.