mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-30 02:59:22 -05:00
cmMakefile: set GENERATED property of outputs upfront
Setting the GENERATED property of outputs upfront is a precondition for delayed custom command creation (generator expressions in outputs). Issue: 12877
This commit is contained in:
+20
-28
@@ -860,7 +860,7 @@ void cmMakefile::AddCustomCommandToTarget(
|
|||||||
e << "No TARGET '" << target
|
e << "No TARGET '" << target
|
||||||
<< "' has been created in this directory.";
|
<< "' has been created in this directory.";
|
||||||
}
|
}
|
||||||
IssueMessage(messageType, e.str());
|
this->IssueMessage(messageType, e.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -886,11 +886,7 @@ void cmMakefile::AddCustomCommandToTarget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always create the byproduct sources and mark them generated.
|
// Always create the byproduct sources and mark them generated.
|
||||||
for (std::string const& o : byproducts) {
|
this->CreateGeneratedSources(byproducts);
|
||||||
if (cmSourceFile* out = this->GetOrCreateSource(o, true)) {
|
|
||||||
out->SetProperty("GENERATED", "1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the command to the appropriate build step for the target.
|
// Add the command to the appropriate build step for the target.
|
||||||
std::vector<std::string> no_output;
|
std::vector<std::string> no_output;
|
||||||
@@ -940,6 +936,10 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always create the output sources and mark them generated.
|
||||||
|
this->CreateGeneratedSources(outputs, cmSourceFileLocationKind::Known);
|
||||||
|
this->CreateGeneratedSources(byproducts, cmSourceFileLocationKind::Known);
|
||||||
|
|
||||||
// Choose a source file on which to store the custom command.
|
// Choose a source file on which to store the custom command.
|
||||||
cmSourceFile* file = nullptr;
|
cmSourceFile* file = nullptr;
|
||||||
if (!commandLines.empty() && !main_dependency.empty()) {
|
if (!commandLines.empty() && !main_dependency.empty()) {
|
||||||
@@ -987,20 +987,6 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
|||||||
file->SetProperty("__CMAKE_RULE", "1");
|
file->SetProperty("__CMAKE_RULE", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always create the output sources and mark them generated.
|
|
||||||
for (std::string const& o : outputs) {
|
|
||||||
if (cmSourceFile* out =
|
|
||||||
this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) {
|
|
||||||
out->SetProperty("GENERATED", "1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (std::string const& o : byproducts) {
|
|
||||||
if (cmSourceFile* out =
|
|
||||||
this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) {
|
|
||||||
out->SetProperty("GENERATED", "1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attach the custom command to the file.
|
// Attach the custom command to the file.
|
||||||
if (file) {
|
if (file) {
|
||||||
// Construct a complete list of dependencies.
|
// Construct a complete list of dependencies.
|
||||||
@@ -1180,6 +1166,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
|
|||||||
if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
|
if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
|
||||||
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!comment) {
|
if (!comment) {
|
||||||
// Use an empty comment to avoid generation of default comment.
|
// Use an empty comment to avoid generation of default comment.
|
||||||
comment = "";
|
comment = "";
|
||||||
@@ -1187,6 +1174,9 @@ cmTarget* cmMakefile::AddUtilityCommand(
|
|||||||
|
|
||||||
// Store the custom command in the target.
|
// Store the custom command in the target.
|
||||||
if (!commandLines.empty() || !depends.empty()) {
|
if (!commandLines.empty() || !depends.empty()) {
|
||||||
|
// Always create the byproduct sources and mark them generated.
|
||||||
|
this->CreateGeneratedSources(byproducts, cmSourceFileLocationKind::Known);
|
||||||
|
|
||||||
std::string force =
|
std::string force =
|
||||||
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName);
|
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName);
|
||||||
std::vector<std::string> forced;
|
std::vector<std::string> forced;
|
||||||
@@ -1205,14 +1195,6 @@ cmTarget* cmMakefile::AddUtilityCommand(
|
|||||||
} else {
|
} else {
|
||||||
cmSystemTools::Error("Could not get source file entry for " + force);
|
cmSystemTools::Error("Could not get source file entry for " + force);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always create the byproduct sources and mark them generated.
|
|
||||||
for (std::string const& byproduct : byproducts) {
|
|
||||||
if (cmSourceFile* out = this->GetOrCreateSource(
|
|
||||||
byproduct, true, cmSourceFileLocationKind::Known)) {
|
|
||||||
out->SetProperty("GENERATED", "1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@@ -3325,6 +3307,16 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
|
|||||||
return this->CreateSource(sourceName, generated, kind);
|
return this->CreateSource(sourceName, generated, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmMakefile::CreateGeneratedSources(
|
||||||
|
const std::vector<std::string>& outputs, cmSourceFileLocationKind kind)
|
||||||
|
{
|
||||||
|
for (std::string const& output : outputs) {
|
||||||
|
if (cmSourceFile* out = this->GetOrCreateSource(output, true, kind)) {
|
||||||
|
out->SetProperty("GENERATED", "1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cmMakefile::AddTargetObject(std::string const& tgtName,
|
void cmMakefile::AddTargetObject(std::string const& tgtName,
|
||||||
std::string const& objFile)
|
std::string const& objFile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1030,6 +1030,11 @@ private:
|
|||||||
bool escapeQuotes, bool noEscapes,
|
bool escapeQuotes, bool noEscapes,
|
||||||
bool atOnly, const char* filename,
|
bool atOnly, const char* filename,
|
||||||
long line, bool replaceAt) const;
|
long line, bool replaceAt) const;
|
||||||
|
|
||||||
|
void CreateGeneratedSources(
|
||||||
|
const std::vector<std::string>& outputs,
|
||||||
|
cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old version of GetSourceFileWithOutput(const std::string&) kept for
|
* Old version of GetSourceFileWithOutput(const std::string&) kept for
|
||||||
* backward-compatibility. It implements a linear search and support
|
* backward-compatibility. It implements a linear search and support
|
||||||
|
|||||||
Reference in New Issue
Block a user