CMP0113.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. CMP0113
  2. -------
  3. .. versionadded:: 3.19
  4. :ref:`Makefile Generators` do not repeat custom commands from target
  5. dependencies.
  6. Consider a chain of custom commands split across two dependent targets:
  7. .. code-block:: cmake
  8. add_custom_command(OUTPUT output-not-created
  9. COMMAND ... DEPENDS ...)
  10. set_property(SOURCE output-not-created PROPERTY SYMBOLIC 1)
  11. add_custom_command(OUTPUT output-created
  12. COMMAND ... DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/output-not-created)
  13. add_custom_target(first DEPENDS output-not-created)
  14. add_custom_target(second DEPENDS output-created)
  15. add_dependencies(second first)
  16. In CMake 3.18 and lower, the Makefile generators put a copy of both custom
  17. commands in the Makefile for target ``second`` even though its dependency on
  18. target ``first`` ensures that the first custom command runs before the second.
  19. Running ``make second`` would cause the first custom command to run once in
  20. the ``first`` target and then again in the ``second`` target.
  21. CMake 3.19 and above prefer to not duplicate custom commands in a target that
  22. are already generated in other targets on which the target depends (directly or
  23. indirectly). This policy provides compatibility for projects that have not
  24. been updated to expect the new behavior. In particular, projects that relied
  25. on the duplicate execution or that did not properly set the :prop_sf:`SYMBOLIC`
  26. source file property may be affected.
  27. The ``OLD`` behavior for this policy is to duplicate custom commands in
  28. dependent targets. The ``NEW`` behavior of this policy is to not duplicate
  29. custom commands in dependent targets.
  30. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.19
  31. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  32. .. include:: include/STANDARD_ADVICE.rst
  33. .. include:: include/DEPRECATED.rst