Ninja: Add missing top-level codegen dependencies on per-directory codegen

In commit 197cb419d1 (add_custom_command: Add CODEGEN support,
2024-05-27, v3.31.0-rc1~394^2) we accidentally left out the global
`codegen` target's dependencies on the per-directory `codegen` targets.
Add them for parity with the `all` target.

Fixes: #26517
This commit is contained in:
Brad King 2024-12-10 10:09:14 -05:00
parent 5d0f2aba7e
commit 5ce1ca607f
8 changed files with 63 additions and 0 deletions

View File

@ -1661,6 +1661,13 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
}
}
for (DirectoryTarget::Dir const& d : dt.Children) {
if (!d.ExcludeFromAll) {
build.ExplicitDeps.emplace_back(this->BuildAlias(
this->ConvertToNinjaPath(cmStrCat(d.Path, "/codegen")), config));
}
}
// Write target
this->WriteBuild(this->EnableCrossConfigBuild() &&
this->CrossConfigs.count(config)

View File

@ -31,3 +31,7 @@ run_cmake("implicit-depends")
run_cmake("implicit-depends-append-codegen")
run_cmake("append-implicit-depends")
run_cmake("no-output")
# Top-level codegen depends on that of subdirectories.
run_codegen(SubDir)
run_codegen(SubDirExcludeFromAll)

View File

@ -0,0 +1,9 @@
set(filename "${RunCMake_TEST_BINARY_DIR}/generated.h")
if(NOT EXISTS "${filename}")
string(APPEND RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}\n")
endif()
set(filename "${RunCMake_TEST_BINARY_DIR}/SubDir/generated.h")
if(NOT EXISTS "${filename}")
string(APPEND RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}\n")
endif()

View File

@ -0,0 +1,15 @@
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/generated.h
COMMAND
${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated.h
CODEGEN
)
add_library(errorlib_top
# If this library is built error.c will cause the build to fail
error.c
${CMAKE_CURRENT_BINARY_DIR}/generated.h
)

View File

@ -0,0 +1,2 @@
add_subdirectory(SubDir)
include(SubDir-common.cmake)

View File

@ -0,0 +1,15 @@
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/generated.h
COMMAND
${CMAKE_COMMAND} -E
copy ${CMAKE_CURRENT_SOURCE_DIR}/../generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/generated.h
CODEGEN
)
add_library(errorlib_subdir
# If this library is built error.c will cause the build to fail
../error.c
${CMAKE_CURRENT_BINARY_DIR}/generated.h
)

View File

@ -0,0 +1,9 @@
set(filename "${RunCMake_TEST_BINARY_DIR}/generated.h")
if(NOT EXISTS "${filename}")
string(APPEND RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}\n")
endif()
set(filename "${RunCMake_TEST_BINARY_DIR}/SubDir/generated.h")
if(EXISTS "${filename}")
string(APPEND RunCMake_TEST_FAILED "unexpected file created:\n ${filename}\n")
endif()

View File

@ -0,0 +1,2 @@
add_subdirectory(SubDir EXCLUDE_FROM_ALL)
include(SubDir-common.cmake)