Using static library Windows
yaml-cpp 0.7.0 broke one of my projects (which was using 0.6.3) at least on Windows as it seems that the installed cmake config (at least with cmake v3.23.1) doesn't set "YAML_CPP_STATIC_DEFINE" by default ... even though the default build/install is a static library.
The result is that when I build my project I see a message "Defining YAML_CPP_API for DLL import" then an ensuing barrage of linker errors (as well as CN4251 warnings).
Is this expected behaviour? Is it up to projects which import the yaml-cpp (target) to explicitly specify that the static library defines should be used via the macro?
Related: #1078
My hunch was that we could propagate the macro to the yaml-cpp target (interface) ... i.e. update line 125 of CMakeLists.txt to something like:
target_compile_definitions(yaml-cpp
INTERFACE
$<$<NOT:$<BOOL:${YAML_BUILD_SHARED_LIBS}>>:YAML_CPP_STATIC_DEFINE>
PRIVATE
$<${build-windows-dll}:${PROJECT_NAME}_DLL>
$<$<NOT:$<BOOL:${YAML_CPP_BUILD_CONTRIB}>>:YAML_CPP_NO_CONTRIB>)
and then remove add_definitions() (line 49).
This could cause issues if both shared and static libraries are installed side by side (not sure if this is common?). For example, after installation with YAML_BUILD_SHARED_LIBS=OFF the config file share/cmake/yaml-cpp/yaml-cpp-targets.cmake contains
set_target_properties(yaml-cpp PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "\$<\$<NOT:\$<BOOL:OFF>>:YAML_CPP_STATIC_DEFINE>"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)
Obviously, if you build+install shared libs then the second line will be over-written with:
INTERFACE_COMPILE_DEFINITIONS "\$<\$<NOT:\$<BOOL:ON>>:YAML_CPP_STATIC_DEFINE>"
and so the YAML_CPP_STATIC_DEFINE is once again suppressed.