Files
CMake/Tests/RunCMake/Make/CMP0113-Common.cmake
Brad King 45fedf0e17 Makefile: Add policy CMP0113 to avoid duplication of custom commands
Do not attach a custom command to a target if it is already attached to one of
the target's dependencies.  The command's output will be available by the time
the target needs it because the dependency containing the command will have
already been built.

This may break existing projects that do not properly mark non-created
outputs with the `SYMBOLIC` property.  Previously a chain of two custom
commands whose intermediate dependency is not created would put both
commands in a dependent project's Makefile even if the first command is
also in its dependency's Makefile.  The first command would run twice
but the build would work.  Now the second command needs an explicit
`SYMBOLIC` mark on its input to tell CMake that it is not expected to
exist.  To maintain compatibility with projects that left out the mark,
add a policy activating the behavior.
2020-09-08 15:38:40 -04:00

18 lines
491 B
CMake

add_custom_command(
OUTPUT output-not-created
COMMAND ${CMAKE_COMMAND} -E echo output-not-created
DEPENDS ${CMAKE_CURRENT_LIST_FILE}
VERBATIM
)
add_custom_command(
OUTPUT output-created
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_FILE} output-created
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/output-not-created
VERBATIM
)
add_custom_target(drive1 ALL DEPENDS output-not-created)
add_custom_target(drive2 ALL DEPENDS output-created)
add_dependencies(drive2 drive1)