target_compile_features.rst 1.5 KB

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