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.)
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 namedINTERFACE_
+ the original property name - and there are no properties with prefixINTERFACE_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
orPUBLIC
on these properties, to some extent, by using thetarget_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: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.