I want to create an interface library that contains a bunch of settings in my CMake setup so that all of my libraries (or at least the ones I want, e.g. not tests perhaps) can have uniform settings.
I’m trying to use the warning as error property to automatically turn on the relevant setting for the particular compiler.
My problem: I can’t figure out how to get this to propagate to the “child” or “consuming” library.
# Setting up the interface library
add_library(options_lib INTERFACE)
set_property(TARGET options_lib APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL COMPILE_WARNING_AS_ERROR)
set_target_properties(options_lib PROPERTIES COMPILE_WARNING_AS_ERROR ON)
...
add_library(my_actual_lib PUBLIC src/foo.cpp)
# Note: results seem to be the same even if I do PRIVATE
target_link_library(my_actual_lib PUBLIC options_lib)
get_target_property(result my_actual_lib COMPILE_WARNING_AS_ERROR)
message(STATUS "Result: ${result}")
This produces result-NOTFOUND
as the result.
Is there a better way to propagate this setting? Am I missing something in this setup?