Ninja: Evaluate generator expressions in CODEGEN outputs

Codegen is supported for Ninja Multi-Config, so CODEGEN should support
generator expressions.
This commit is contained in:
Tyler Yankee committed 2026-10-25 19:52:43 -04:00
1 parent 902ec85438
commit f54117c6b1
5 files changed
+39 -1

No files matched your search

+4
View File
@@ -264,6 +264,10 @@ Generating Files
It can only be set on the first call to ``add_custom_command(OUTPUT...)``
for the output files.
.. versionchanged:: 4.5
Arguments to ``OUTPUT`` may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``IMPLICIT_DEPENDS``
Request scanning of implicit dependencies of an input file.
The language given specifies the programming language whose
+3 -1
View File
@@ -23,6 +23,7 @@
#include "cmsys/String.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmCxxModuleMapper.h"
#include "cmDiagnostics.h"
#include "cmDyndepCollation.h"
@@ -1713,7 +1714,8 @@ void cmGlobalNinjaGenerator::AppendCodegenOutputs(
for (cmSourceFile const* sf : customCommandSources) {
cmCustomCommand const* cc = sf->GetCustomCommand();
if (cc->GetCodegen()) {
std::vector<std::string> const& outputs = cc->GetOutputs();
cmCustomCommandGenerator ccg(*cc, config, target->GetLocalGenerator());
std::vector<std::string> const& outputs = ccg.GetOutputs();
std::transform(outputs.begin(), outputs.end(), std::back_inserter(deps),
this->MapToNinjaPath());
}
+10
View File
@@ -28,6 +28,16 @@ run_codegen("add-custom-command-depends")
run_codegen("byproducts")
run_codegen("add-dependencies-not-all")
# Outputs that differ per configuration
block()
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=Debug\\;Release")
else()
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_codegen("per-config")
endblock()
# Error handling
run_cmake("implicit-depends")
run_cmake("implicit-depends-append-codegen")
@@ -0,0 +1,11 @@
set(filename "${RunCMake_TEST_BINARY_DIR}/Debug/generated.h")
if (NOT EXISTS "${filename}")
set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
return()
endif()
set(filename "${RunCMake_TEST_BINARY_DIR}/Release/generated.h")
if (EXISTS "${filename}")
set(RunCMake_TEST_FAILED "unexpected file created:\n ${filename}")
return()
endif()
+11
View File
@@ -0,0 +1,11 @@
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/generated.h
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/generated.h
CODEGEN
)
add_custom_target(h_creator ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/generated.h
)