# CMP0154

Added in version 3.28.

Generated files are private by default in targets using File Sets.

CMake 3.27 and below assume that any file generated as an output or byproduct of `add_custom_command()` or `add_custom_target()` may be a public header file meant for inclusion by dependents' source files. This requires 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.

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, Ninja Generators may omit the above-mentioned conservative dependencies and produce more efficient build graphs.

Additionally, if the custom command's output is a member of a file set of type `CXX_MODULES`, it will additionally not be required to exist before compiling other sources in the same target. Since these files should not be included at compile time directly, they may not be implicitly required to exist for other compilation rules.

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:

    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 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 Ninja Generators to produce more efficient build graphs.

This policy was introduced in CMake version 3.28. It may be set by `cmake_policy()` or `cmake_minimum_required()`. If it is not set, CMake does not warn, and uses `OLD` behavior.

Note

The `OLD` behavior of a policy is `deprecated by definition` and may be removed in a future version of CMake.