target_precompile_headers.rst 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. target_precompile_headers(<target> REUSE_FROM <other_target>)
  9. Adds header files to :prop_tgt:`PRECOMPILE_HEADERS` or
  10. :prop_tgt:`INTERFACE_PRECOMPILE_HEADERS` target properties.
  11. The second signature will reuse an already precompiled header file artefact
  12. from another target. This is done by setting the
  13. :prop_tgt:`PRECOMPILE_HEADERS_REUSE_FROM` to ``<other_target>`` value.
  14. The ``<other_target>`` will become a dependency of ``<target>``.
  15. .. note::
  16. The second signature will require the same set of compiler options,
  17. compiler flags, compiler definitions for both ``<target>``, and
  18. ``<other_target>``. Compilers (e.g. GCC) will issue a warning if the
  19. precompiled header file cannot be used (``-Winvalid-pch``).
  20. Precompiling header files can speed up compilation by creating a partially
  21. processed version of some header files, and then using that version during
  22. compilations rather than repeatedly parsing the original headers.
  23. The named ``<target>`` must have been created by a command such as
  24. :command:`add_executable` or :command:`add_library` and must not be an
  25. :ref:`ALIAS target <Alias Targets>`.
  26. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  27. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  28. items will populate the :prop_tgt:`PRECOMPILE_HEADERS` property of
  29. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  30. :prop_tgt:`INTERFACE_PRECOMPILE_HEADERS` property of ``<target>``.
  31. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  32. Repeated calls for the same ``<target>`` append items in the order called.
  33. Arguments to ``target_precompile_headers`` may use "generator expressions"
  34. with the syntax ``$<...>``.
  35. See the :manual:`cmake-generator-expressions(7)` manual for available
  36. expressions. See the :manual:`cmake-compile-features(7)` manual for
  37. information on compile features and a list of supported compilers.
  38. .. code-block:: cmake
  39. target_precompile_headers(<target>
  40. PUBLIC
  41. "project_header.h"
  42. PRIVATE
  43. <unordered_map>
  44. )
  45. Header files will be double quoted if they are not specified with double
  46. quotes or angle brackets.
  47. See Also
  48. ^^^^^^^^
  49. For disabling precompile headers for specific targets there is the
  50. property :prop_tgt:`DISABLE_PRECOMPILE_HEADERS`.
  51. For skipping certain source files there is the source file property
  52. :prop_sf:`SKIP_PRECOMPILE_HEADERS`.