I need to replace the /std:c++14
flag of an INTERFACE
target (header-only library) with /std:c++17
. CMake doesn't support setting C++17 flags in VS directly yet (see How to enable /std:c++17 in VS2017 with CMake) so I need to manually replace it.
However get_target_property(my_compile_flags mylib COMPILE_OPTIONS)
to retrieve the list of currently set flags to then subsequently replace /std:c++14 with /std:c++17 doesn't work:
INTERFACE_LIBRARY targets may only have whitelisted properties. The property "COMPILE_OPTIONS" is not allowed.
You can set them however via target_compile_features(...)
and manually via e.g. target_compile_options(mylib INTERFACE /std:c++17)
. But the latter command adds the flag, without removing /std:c++14
.
How to go about that?
For an interface library you need to change
INTERFACE_COMPILE_DEFINITIONS
instead ofCOMPILE_DEFINITIONS
(seeadd_library(INTERFACE)
).Here is a full example I've tested with VS2017 (using
/std:c++latest
since not yet supported/std:c++17
may be ignored/removed by CMake):