1

When you set a CMake target's property, you can make it PUBLIC, INTERFACE or PUBLIC. Yet - the CMake manual page on the CXX_STANDARD property does not indicate the ability to specify one of these. Specifically, suppose I have:

set_target_properties(mylib PROPERTIES 
        CXX_STANDARD 11
        CXX_STANDARD_REQUIRED YES
        CXX_EXTENSIONS NO
)

Is it really unavailable? And if so, why?

(Note: This question applies just the same to C or any language which CMake supports this way.)

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 1
    if you look at target properties list, there is no `INTERFACE_CXX_XXXX` ref: https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#target-properties – Mizux Oct 15 '20 at 07:06

1 Answers1

2

As @Mizux points out in a comment, it seems you can't - at the moment - make these CXX_-prefixed options propagate to dependent targets: Propagating properties are named INTERFACE_ + the original property name - and there are no properties with prefix INTERFACE_CXX_ in the master list of target properties as of October 2020.

I don't know why this is the case.

However - one can obtain the effect of INTERFACE or PUBLIC on these properties, to some extent, by using the target_compile_features() command (or is it a macro? I always get those mixed up), with one of the features: cxx_std_98, cxx_std_11 etc. Thus, for example:

target_compile_features(mylib PUBLIC cxx_std_11)

but that's still not the exact PUBLIC equivalent of OP's command in the question: This doesn't prevent the availability of GNU extensions. So, it's a half-solution - and I don't like it anyway because the syntax in the question is nicer.

einpoklum
  • 118,144
  • 57
  • 340
  • 684