summaryrefslogtreecommitdiffstats
path: root/Help/policy/CMP0154.rst
blob: cb93d4167418462b24a5da0df3004d5dc4592022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
CMP0154
-------

.. versionadded:: 3.28

Generated files are private by default in targets using :ref:`file sets`.

CMake 3.27 and below assume that any file generated as an output or byproduct
of :command:`add_custom_command` or :command:`add_custom_target` may be a
public header file meant for inclusion by dependents' source files.  This
requires :ref:`Ninja Generators` to add conservative order-only dependencies
that prevent a target's source files from compiling before custom commands
from the target's dependencies are finished, even if those custom commands
only produce sources private to their own target.

:ref:`File Sets`, introduced by CMake 3.23, provide a way to express the
visibility of generated header files.  CMake 3.28 and above prefer to
assume that, in targets using file sets, generated files are private to
their own target by default.  Generated public headers must be specified
as members of a ``PUBLIC`` (or ``INTERFACE``) ``FILE_SET``, typically of
type ``HEADERS``.  With this information, :ref:`Ninja Generators` may omit
the above-mentioned conservative dependencies and produce more efficient
build graphs.

This policy provides compatibility for projects using file sets in targets
with generated header files that have not been updated.  Such projects
should be updated to express generated public headers in a file set.
For example:

.. code-block:: cmake

  add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.h
    ...
  )
  target_sources(foo
    PUBLIC FILE_SET HEADERS
      BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
      FILES     ${CMAKE_CURRENT_BINARY_DIR}/foo.h
  )

The ``OLD`` behavior for this policy is to assume generated files are
public, even in targets using file sets, and for :ref:`Ninja Generators`
to produce conservative build graphs.  The ``NEW`` behavior for this
policy is to assume generated files are private in targets using file sets,
and for :ref:`Ninja Generators` to produce more efficient build graphs.

This policy was introduced in CMake version 3.28.  Use the
:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
Unlike many policies, CMake version |release| does *not* warn
when this policy is not set and simply uses ``OLD`` behavior.

.. include:: DEPRECATED.txt