- CMake Cookbook
- Radovan Bast Roberto Di Remigio
- 173字
- 2025-04-04 16:17:17
How it works
In steps 4 and 5, we set a number of properties for the animals and animal-farm targets:
- CXX_STANDARD mandates the standard that we would like to have.
- CXX_EXTENSIONS tells CMake to only use compiler flags that will enable the ISO C++ standard, without compiler-specific extensions.
- CXX_STANDARD_REQUIRED specifies that the version of the standard chosen is required. If this version is not available, CMake will stop configuration with an error. When this property is set to OFF, CMake will look for next latest version of the standard, until a proper flag has been set. This means to first look for C++14, then C++11, then C++98.
At the time of writing, there is no Fortran_STANDARD property available yet, but the standard can be set using target_compile_options; see https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-01/recipe-09.
If the language standard is a global property shared by all targets, you can set the CMAKE_<LANG>_STANDARD, CMAKE_<LANG>_EXTENSIONS, and CMAKE_<LANG>_STANDARD_REQUIRED variables to their desired values. The corresponding properties on all targets will be set with these values.