jasonjje223
jasonjje223

Reputation: 21

Modern CMake - C++ version with set_property or target_compile_features

I see two main ways to do this in "modern" cmake:

set_property(TARGET target PROPERTY CXX_STANDARD 17)

or

target_compile_features(target PRIVATE cxx_std_17)

I understand that with target_compile_features, one can also specify a feature of the language version they want, rather than a specific version; it seems that it will also allow any version later than the one specified, so is possibly more flexible.

The former seems more common, however the latter seems to be considered the more modern, ideal way to do this.

Do either have any major advantages, or does it really just not matter?

Upvotes: 2

Views: 1373

Answers (1)

eerorika
eerorika

Reputation: 238361

Besides the advantages that you already mentioned, target_compile_features supports the INTERFACE, PUBLIC and PRIVATE keywords that can be used to control propagation to dependencies.

set_property seemingly can be used to specify different language version for a subset of sources (which is probably a bad idea, but if you have to do it then you have to do it).

Upvotes: 1

Related Questions