From 0826c20128fad20aafac2006ac0371e381e3cf60 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Apr 2018 10:53:15 -0400 Subject: Ninja: Do not add empty custom command for file(GENERATE) outputs Internally we mark `file(GENERATE)` outputs as `GENERATED` in order to tell custom command dependency tracing logic not to expect the files to exist on disk yet. This is because we do not generate the files until after that tracing is done. The Ninja generator also interprets the `GENERATED` property to mean that it is expected that some build rule will generate the file if another build rule depends on it. If the generator does not know of a custom command that generates the file then it adds an empty one so that the `ninja` build tool does not complain about a dependency on a file that does not exist and has no rule to generate it. However, this step is not necessary for `file(GENERATE)` outputs because there is no build rule to generate them and they will exist before `ninja` runs. Add an additional `__CMAKE_GENERATED_BY_CMAKE` property internally to tell the Ninja generator that a `GENERATED` file will exist before the build starts and is not expected to have a build rule producing it. Fixes: #17942 --- Source/cmGeneratorExpressionEvaluationFile.cxx | 6 ++++++ Source/cmNinjaTargetGenerator.cxx | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index c544141..99b9261 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -105,8 +105,14 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile( lg, config, false, nullptr, nullptr, nullptr, le); cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource( name, false, cmSourceFileLocationKind::Known); + // Tell TraceDependencies that the file is not expected to exist + // on disk yet. We generate it after that runs. sf->SetProperty("GENERATED", "1"); + // Tell the build system generators that there is no build rule + // to generate the file. + sf->SetProperty("__CMAKE_GENERATED_BY_CMAKE", "1"); + gg->SetFilenameTargetDepends( sf, this->OutputFileExpr->GetSourceSensitiveTargets()); } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index f4faf47..a6a3efb 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -896,7 +896,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // (either attached to this source file or another one), assume that one of // the target dependencies, OBJECT_DEPENDS or header file custom commands // will rebuild the file. - if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() && + if (source->GetPropertyAsBool("GENERATED") && + !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") && + !source->GetCustomCommand() && !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) { this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName, orderOnlyDeps); -- cgit v0.12