Files
cmake/Tests/RunCMake/Codegen/add-dependencies.cmake
Tyler Yankee 2d85779126 Ninja: Account for explicit target dependencies via CODEGEN
When a "normal" target (e.g., an executable) depends on a custom target
that is not part of `all`, and that custom target owns the output of a
custom command marked `CODEGEN`, an explicit `add_dependencies` from
the normal to custom target must be incorporated in `codegen`.

Amends commit 197cb419d1 (add_custom_command: Add CODEGEN support,
2024-05-27, v3.31.0-rc1~394^2), which already incorporated such logic
in the Unix Makefile generator, but was not tested nor implemented for
Ninja.

Fixes: #28092
2026-09-15 10:34:09 -04:00

19 lines
576 B
CMake

add_custom_target(foobar
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated.h
)
add_custom_command(
OUTPUT generated.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/generated.h
${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
CODEGEN
)
add_custom_target(hpp_creator ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp)
# This test will fail if add_dependencies isn't accounted for in the
# codegen build graph
add_dependencies(hpp_creator foobar)