target_precompile_headers.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. target_precompile_headers
  2. -------------------------
  3. Add a list of header files to precompile.
  4. .. code-block:: cmake
  5. target_precompile_headers(<target>
  6. <INTERFACE|PUBLIC|PRIVATE> [header1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [header2...] ...])
  8. Adds header files to :prop_tgt:`PRECOMPILE_HEADERS` or
  9. :prop_tgt:`INTERFACE_PRECOMPILE_HEADERS` target properties.
  10. Precompiling header files can speed up compilation by creating a partially
  11. processed version of some header files, and then using that version during
  12. compilations rather than repeatedly parsing the original headers.
  13. The named ``<target>`` must have been created by a command such as
  14. :command:`add_executable` or :command:`add_library` and must not be an
  15. :ref:`ALIAS target <Alias Targets>`.
  16. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  17. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  18. items will populate the :prop_tgt:`PRECOMPILE_HEADERS` property of
  19. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  20. :prop_tgt:`INTERFACE_PRECOMPILE_HEADERS` property of ``<target>``.
  21. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  22. Repeated calls for the same ``<target>`` append items in the order called.
  23. Arguments to ``target_precompile_headers`` may use "generator expressions"
  24. with the syntax ``$<...>``.
  25. See the :manual:`cmake-generator-expressions(7)` manual for available
  26. expressions. See the :manual:`cmake-compile-features(7)` manual for
  27. information on compile features and a list of supported compilers.
  28. .. code-block:: cmake
  29. target_precompile_headers(<target>
  30. PUBLIC
  31. "project_header.h"
  32. PRIVATE
  33. <unordered_map>
  34. )
  35. Header files will be double quoted if they are not specified with double
  36. quotes or angle brackets.
  37. See Also
  38. ^^^^^^^^
  39. For disabling precompile headers for specific targets there is the
  40. property :prop_tgt:`DISABLE_PRECOMPILE_HEADERS`.
  41. For skipping certain source files there is the source file property
  42. :prop_sf:`SKIP_PRECOMPILE_HEADERS`.