CMP0154.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. CMP0154
  2. -------
  3. .. versionadded:: 3.28
  4. Generated files are private by default in targets using :ref:`file sets`.
  5. CMake 3.27 and below assume that any file generated as an output or byproduct
  6. of :command:`add_custom_command` or :command:`add_custom_target` may be a
  7. public header file meant for inclusion by dependents' source files. This
  8. requires :ref:`Ninja Generators` to add conservative order-only dependencies
  9. that prevent a target's source files from compiling before custom commands
  10. from the target's dependencies are finished, even if those custom commands
  11. only produce sources private to their own target.
  12. :ref:`File Sets`, introduced by CMake 3.23, provide a way to express the
  13. visibility of generated header files. CMake 3.28 and above prefer to
  14. assume that, in targets using file sets, generated files are private to
  15. their own target by default. Generated public headers must be specified
  16. as members of a ``PUBLIC`` (or ``INTERFACE``) ``FILE_SET``, typically of
  17. type ``HEADERS``. With this information, :ref:`Ninja Generators` may omit
  18. the above-mentioned conservative dependencies and produce more efficient
  19. build graphs.
  20. Additionally, if the custom command's output is a member of a file set of type
  21. ``CXX_MODULES``, it will additionally not be required to exist before
  22. compiling other sources in the same target. Since these files should not be
  23. included at compile time directly, they may not be implicitly required to
  24. exist for other compilation rules.
  25. This policy provides compatibility for projects using file sets in targets
  26. with generated header files that have not been updated. Such projects
  27. should be updated to express generated public headers in a file set.
  28. For example:
  29. .. code-block:: cmake
  30. add_custom_command(
  31. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.h
  32. ...
  33. )
  34. target_sources(foo
  35. PUBLIC FILE_SET HEADERS
  36. BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
  37. FILES ${CMAKE_CURRENT_BINARY_DIR}/foo.h
  38. )
  39. The ``OLD`` behavior for this policy is to assume generated files are
  40. public, even in targets using file sets, and for :ref:`Ninja Generators`
  41. to produce conservative build graphs. The ``NEW`` behavior for this
  42. policy is to assume generated files are private in targets using file sets,
  43. and for :ref:`Ninja Generators` to produce more efficient build graphs.
  44. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.28
  45. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  46. .. include:: STANDARD_ADVICE.txt
  47. .. include:: DEPRECATED.txt