diff options
author | Brad King <brad.king@kitware.com> | 2024-12-10 15:09:14 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-12-10 16:46:31 (GMT) |
commit | 5ce1ca607f8c99a81b7155940ff3ce7afa13140b (patch) | |
tree | 3c22e8893544f0866978bc21defce951708e11ca | |
parent | 5d0f2aba7e231efefa28f54f9c1a5e36b4f374ea (diff) | |
download | CMake-5ce1ca607f8c99a81b7155940ff3ce7afa13140b.zip CMake-5ce1ca607f8c99a81b7155940ff3ce7afa13140b.tar.gz CMake-5ce1ca607f8c99a81b7155940ff3ce7afa13140b.tar.bz2 |
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
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 7 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/RunCMakeTest.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDir-build-check.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDir-common.cmake | 15 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDir.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDir/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDirExcludeFromAll-build-check.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/Codegen/SubDirExcludeFromAll.cmake | 2 |
8 files changed, 63 insertions, 0 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 04c8c02..2933a4f 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -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) diff --git a/Tests/RunCMake/Codegen/RunCMakeTest.cmake b/Tests/RunCMake/Codegen/RunCMakeTest.cmake index bbd70b0..7b072ba 100644 --- a/Tests/RunCMake/Codegen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Codegen/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/Codegen/SubDir-build-check.cmake b/Tests/RunCMake/Codegen/SubDir-build-check.cmake new file mode 100644 index 0000000..d81aa40 --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDir-build-check.cmake @@ -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() diff --git a/Tests/RunCMake/Codegen/SubDir-common.cmake b/Tests/RunCMake/Codegen/SubDir-common.cmake new file mode 100644 index 0000000..b4013d9 --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDir-common.cmake @@ -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 +) diff --git a/Tests/RunCMake/Codegen/SubDir.cmake b/Tests/RunCMake/Codegen/SubDir.cmake new file mode 100644 index 0000000..5e5ff7b --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDir.cmake @@ -0,0 +1,2 @@ +add_subdirectory(SubDir) +include(SubDir-common.cmake) diff --git a/Tests/RunCMake/Codegen/SubDir/CMakeLists.txt b/Tests/RunCMake/Codegen/SubDir/CMakeLists.txt new file mode 100644 index 0000000..58f2f6e --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDir/CMakeLists.txt @@ -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 +) diff --git a/Tests/RunCMake/Codegen/SubDirExcludeFromAll-build-check.cmake b/Tests/RunCMake/Codegen/SubDirExcludeFromAll-build-check.cmake new file mode 100644 index 0000000..9357747 --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDirExcludeFromAll-build-check.cmake @@ -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() diff --git a/Tests/RunCMake/Codegen/SubDirExcludeFromAll.cmake b/Tests/RunCMake/Codegen/SubDirExcludeFromAll.cmake new file mode 100644 index 0000000..707da29 --- /dev/null +++ b/Tests/RunCMake/Codegen/SubDirExcludeFromAll.cmake @@ -0,0 +1,2 @@ +add_subdirectory(SubDir EXCLUDE_FROM_ALL) +include(SubDir-common.cmake) |