Shaobo Zi
Shaobo Zi

Reputation: 729

How to get GCC version supports specific feature?

There are cases that I want to know since which version of gcc a specific compiler flag or c++ language feature is supported so that I can write compile control preprocessors in source files or in CMakeLists.txt. For example, the compiler flag -wno-missing-field-initializers is not supported in gcc 3.4.3(an ancient version I have to use), but I want to know exactly since which version does gcc support that flag. Where can I find such instructions?

Upvotes: 1

Views: 426

Answers (1)

Mikhail
Mikhail

Reputation: 8028

You can check specific flags using CheckCXXCompilerFlag

For example,

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-Wno-missing-field-initializers RESULT_OF_TEST)

Although a more portable option, across compilers, is to use CMAKE_CXX_KNOWN_FEATURES

See https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html

Upvotes: 1

Related Questions