CMP0154.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. Dependents to such targets may also prune dependencies to such
  20. targets when using the :prop_tgt:`OPTIMIZE_DEPENDENCIES` target property.
  21. Additionally, if the custom command's output is a member of a file set of type
  22. ``CXX_MODULES``, it will additionally not be required to exist before
  23. compiling other sources in the same target. Since these files should not be
  24. included at compile time directly, they may not be implicitly required to
  25. exist for other compilation rules.
  26. This policy provides compatibility for projects using file sets in targets
  27. with generated header files that have not been updated. Such projects
  28. should be updated to express generated public headers in a file set.
  29. For example:
  30. .. code-block:: cmake
  31. add_custom_command(
  32. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.h
  33. ...
  34. )
  35. target_sources(foo
  36. PUBLIC FILE_SET HEADERS
  37. BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
  38. FILES ${CMAKE_CURRENT_BINARY_DIR}/foo.h
  39. )
  40. The ``OLD`` behavior for this policy is to assume generated files are
  41. public, even in targets using file sets, and for :ref:`Ninja Generators`
  42. to produce conservative build graphs. The ``NEW`` behavior for this
  43. policy is to assume generated files are private in targets using file sets,
  44. and for :ref:`Ninja Generators` to produce more efficient build graphs.
  45. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.28
  46. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  47. .. include:: include/STANDARD_ADVICE.rst
  48. .. include:: include/DEPRECATED.rst