target_compile_features.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132
  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>``. Repeated
  17. calls for the same ``<target>`` append items.
  18. The named ``<target>`` must have been created by a command such as
  19. :command:`add_executable` or :command:`add_library` and must not be
  20. an ``IMPORTED`` target.
  21. Arguments to ``target_compile_features`` may use "generator expressions"
  22. with the syntax ``$<...>``.
  23. See the :manual:`cmake-generator-expressions(7)` manual for available
  24. expressions. See the :manual:`cmake-compile-features(7)` manual for
  25. information on compile features and a list of supported compilers.