C_STANDARD.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. C_STANDARD
  2. ----------
  3. .. versionadded:: 3.1
  4. The C standard whose features are requested to build this target.
  5. This property specifies the C standard whose features are requested
  6. to build this target. For some compilers, this results in adding a
  7. flag such as ``-std=gnu11`` to the compile line. For compilers that
  8. have no notion of a C standard level, such as Microsoft Visual C++ before
  9. VS 16.7, this property has no effect.
  10. Supported values are ``90``, ``99`` and ``11``.
  11. If the value requested does not result in a compile flag being added for
  12. the compiler in use, a previous standard flag will be added instead. This
  13. means that using:
  14. .. code-block:: cmake
  15. set_property(TARGET tgt PROPERTY C_STANDARD 11)
  16. with a compiler which does not support ``-std=gnu11`` or an equivalent
  17. flag will not result in an error or warning, but will instead add the
  18. ``-std=gnu99`` or ``-std=gnu90`` flag if supported. This "decay" behavior may
  19. be controlled with the :prop_tgt:`C_STANDARD_REQUIRED` target property.
  20. Additionally, the :prop_tgt:`C_EXTENSIONS` target property may be used to
  21. control whether compiler-specific extensions are enabled on a per-target basis.
  22. See the :manual:`cmake-compile-features(7)` manual for information on
  23. compile features and a list of supported compilers.
  24. This property is initialized by the value of
  25. the :variable:`CMAKE_C_STANDARD` variable if it is set when a target
  26. is created.