Testing if a compiler feature has been required on a target

If I require a compiler feature like the example in the documentation

target_compile_features(mylib PUBLIC cxx_constexpr)

How do I then test that the target has had that feature required So I want some code that does
if target mylib requires cxx_constexpr

My use case is that in a function I want to check if the target passed in has required C++ cxx_std_20

Note I tired the target propertis CXX_STANDARD and CXX_STANDARD_REQUIRED but they don’t seem to be set

It looks like you need to get_target_property for COMPILE_FEATURES

https://cmake.org/cmake/help/latest/command/target_compile_features.html

PRIVATE and PUBLIC items will populate the COMPILE_FEATURES property of <target> . PUBLIC and INTERFACE items will populate the INTERFACE_COMPILE_FEATURES property of <target> .

I had seen that and tried it and thought it didn’t work. My problem is that it doesn’t seem to work transitively. If I have a target foo and do

target_compile_features(foo PUBLIC cxx_std_23)

then the COMPILE_FEATURES contains cxx_std_23 as expected.
However if I then have a target bar with the following

target_link_libraries(bar PUBLIC foo)

Then for bar COMPILE_FEATURES come back as not found. The generated project does seem to set the language version of bar to C++23. So this seems to be working as intended. So how can I find out the full set of COMPILE_FEATURES both direct and indirect, do I have to walk the dependency tree myself?

Ah, I didn’t know you were trying to read the properties on a dependent target.

You could also try setting CXX_STANDARD directly.
My project uses settings like this for example:

set_property(TARGET foo PROPERTY CXX_STANDARD 17)
set_property(TARGET foo PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED ON)

As I understand it, properties like that won’t be inherited by dependent targets…
But I think that INTERFACE libraries exist to address that issue.
I haven’t really done much configuring libraries in cmake though (mostly just building executables), so I could be wrong.