target_compile_features.rst 1.2 KB

123456789101112131415161718192021222324252627282930
  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_CXX_COMPILE_FEATURES` variable,
  8. then an error will be reported by CMake. If the use of the feature requires
  9. an additional compiler flag, such as ``-std=c++11``, the flag will be added
  10. automatically.
  11. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  12. specify the scope of the features. ``PRIVATE`` and ``PUBLIC`` items will
  13. populate the :prop_tgt:`COMPILE_FEATURES` property of ``<target>``.
  14. ``PUBLIC`` and ``INTERFACE`` items will populate the
  15. :prop_tgt:`INTERFACE_COMPILE_FEATURES` property of ``<target>``. Repeated
  16. calls for the same ``<target>`` append items.
  17. The named ``<target>`` must have been created by a command such as
  18. :command:`add_executable` or :command:`add_library` and must not be
  19. an ``IMPORTED`` target.
  20. Arguments to ``target_compile_features`` may use "generator expressions"
  21. with the syntax ``$<...>``.
  22. See the :manual:`cmake-generator-expressions(7)` manual for available
  23. expressions.