target_compile_features.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. .. |command_name| replace:: ``target_compile_features``
  25. .. |more_see_also| replace:: See the :manual:`cmake-compile-features(7)`
  26. manual for information on compile features and a list of supported compilers.
  27. .. include:: GENEX_NOTE.txt
  28. :start-line: 1
  29. See Also
  30. ^^^^^^^^
  31. * :command:`target_compile_definitions`
  32. * :command:`target_compile_options`
  33. * :command:`target_include_directories`
  34. * :command:`target_link_libraries`
  35. * :command:`target_link_directories`
  36. * :command:`target_link_options`
  37. * :command:`target_precompile_headers`
  38. * :command:`target_sources`