target_compile_features.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. target_compile_features
  2. -----------------------
  3. .. versionadded:: 3.1
  4. Add expected compiler features to a target.
  5. .. code-block:: cmake
  6. target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> <feature> [...])
  7. Specifies compiler features required when compiling a given target. If the
  8. feature is not listed in the :variable:`CMAKE_C_COMPILE_FEATURES`,
  9. :variable:`CMAKE_CUDA_COMPILE_FEATURES`, or :variable:`CMAKE_CXX_COMPILE_FEATURES`
  10. variables, then an error will be reported by CMake. If the use of the feature requires
  11. an additional compiler flag, such as ``-std=gnu++11``, the flag will be added
  12. automatically.
  13. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  14. specify the scope of the features. ``PRIVATE`` and ``PUBLIC`` items will
  15. populate the :prop_tgt:`COMPILE_FEATURES` property of ``<target>``.
  16. ``PUBLIC`` and ``INTERFACE`` items will populate the
  17. :prop_tgt:`INTERFACE_COMPILE_FEATURES` property of ``<target>``.
  18. Repeated calls for the same ``<target>`` append items.
  19. .. versionadded:: 3.11
  20. Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
  21. The named ``<target>`` must have been created by a command such as
  22. :command:`add_executable` or :command:`add_library` and must not be an
  23. :ref:`ALIAS target <Alias Targets>`.
  24. Arguments to ``target_compile_features`` may use "generator expressions"
  25. with the syntax ``$<...>``.
  26. See the :manual:`cmake-generator-expressions(7)` manual for available
  27. expressions. See the :manual:`cmake-compile-features(7)` manual for
  28. information on compile features and a list of supported compilers.