1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 20:46:37 +08:00

cmLocalGenerator: Adopt custom target 'force' output name generation

This commit is contained in:
Brad King
2020-10-30 11:48:43 -04:00
parent 7b64b0cd5a
commit 15467f12f7
4 changed files with 27 additions and 32 deletions

View File

@@ -1129,9 +1129,8 @@ cmTarget* cmLocalGenerator::AddUtilityCommand(
detail::AddUtilityCommand( detail::AddUtilityCommand(
*this, this->DirectoryBacktrace, cmCommandOrigin::Generator, target, *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, target,
this->Makefile->GetUtilityOutput(target), workingDir, byproducts, depends, workingDir, byproducts, depends, commandLines, escapeOldStyle, comment,
commandLines, escapeOldStyle, comment, uses_terminal, command_expand_lists, uses_terminal, command_expand_lists, job_pool, stdPipesUTF8);
job_pool, stdPipesUTF8);
return target; return target;
} }
@@ -4115,7 +4114,7 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg,
void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
cmCommandOrigin origin, cmTarget* target, cmCommandOrigin origin, cmTarget* target,
std::string const& force, const char* workingDir, const char* workingDir,
const std::vector<std::string>& byproducts, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, const cmCustomCommandLines& commandLines,
@@ -4128,10 +4127,13 @@ void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
comment = ""; comment = "";
} }
// Create the generated symbolic output name of the utility target.
std::string output = lg.CreateUtilityOutput(target->GetName());
std::string no_main_dependency; std::string no_main_dependency;
cmImplicitDependsList no_implicit_depends; cmImplicitDependsList no_implicit_depends;
cmSourceFile* rule = AddCustomCommand( cmSourceFile* rule = AddCustomCommand(
lg, lfbt, origin, { force }, byproducts, depends, no_main_dependency, lg, lfbt, origin, { output }, byproducts, depends, no_main_dependency,
no_implicit_depends, commandLines, comment, workingDir, no_implicit_depends, commandLines, comment, workingDir,
/*replace=*/false, escapeOldStyle, uses_terminal, command_expand_lists, /*replace=*/false, escapeOldStyle, uses_terminal, command_expand_lists,
/*depfile=*/"", job_pool, stdPipesUTF8); /*depfile=*/"", job_pool, stdPipesUTF8);
@@ -4139,7 +4141,7 @@ void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
lg.AddTargetByproducts(target, byproducts, lfbt, origin); lg.AddTargetByproducts(target, byproducts, lfbt, origin);
} }
target->AddSource(force); target->AddSource(output);
} }
std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target) std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target)
@@ -4232,6 +4234,20 @@ cmSourceFile* cmLocalGenerator::GetSourceFileWithOutput(
return nullptr; return nullptr;
} }
std::string cmLocalGenerator::CreateUtilityOutput(
std::string const& targetName)
{
std::string force =
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", targetName);
// The output is not actually created so mark it symbolic.
if (cmSourceFile* sf = this->Makefile->GetOrCreateGeneratedSource(force)) {
sf->SetProperty("SYMBOLIC", "1");
} else {
cmSystemTools::Error("Could not get source file entry for " + force);
}
return force;
}
std::vector<cmCustomCommandGenerator> std::vector<cmCustomCommandGenerator>
cmLocalGenerator::MakeCustomCommandGenerators(cmCustomCommand const& cc, cmLocalGenerator::MakeCustomCommandGenerators(cmCustomCommand const& cc,
std::string const& config) std::string const& config)

View File

@@ -364,6 +364,8 @@ public:
bool command_expand_lists = false, const std::string& job_pool = "", bool command_expand_lists = false, const std::string& job_pool = "",
bool stdPipesUTF8 = false); bool stdPipesUTF8 = false);
std::string CreateUtilityOutput(std::string const& targetName);
virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators( virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
cmCustomCommand const& cc, std::string const& config); cmCustomCommand const& cc, std::string const& config);
@@ -688,7 +690,7 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg,
void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
cmCommandOrigin origin, cmTarget* target, cmCommandOrigin origin, cmTarget* target,
std::string const& force, const char* workingDir, const char* workingDir,
const std::vector<std::string>& byproducts, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, const cmCustomCommandLines& commandLines,

View File

@@ -1257,20 +1257,6 @@ void cmMakefile::AppendCustomCommandToOutput(
} }
} }
std::string cmMakefile::GetUtilityOutput(cmTarget* target)
{
std::string force = cmStrCat(this->GetCurrentBinaryDirectory(),
"/CMakeFiles/", target->GetName());
// The output is not actually created so mark it symbolic.
if (cmSourceFile* sf = this->GetOrCreateSource(
force, false, cmSourceFileLocationKind::Known)) {
sf->SetProperty("SYMBOLIC", "1");
} else {
cmSystemTools::Error("Could not get source file entry for " + force);
}
return force;
}
cmTarget* cmMakefile::AddUtilityCommand( cmTarget* cmMakefile::AddUtilityCommand(
const std::string& utilityName, bool excludeFromAll, const char* workingDir, const std::string& utilityName, bool excludeFromAll, const char* workingDir,
const std::vector<std::string>& byproducts, const std::vector<std::string>& byproducts,
@@ -1287,10 +1273,6 @@ cmTarget* cmMakefile::AddUtilityCommand(
return target; return target;
} }
// Get the output name of the utility target and mark it generated.
std::string force = this->GetUtilityOutput(target);
this->GetOrCreateGeneratedSource(force);
// Always create the byproduct sources and mark them generated. // Always create the byproduct sources and mark them generated.
this->CreateGeneratedOutputs(byproducts); this->CreateGeneratedOutputs(byproducts);
@@ -1303,8 +1285,8 @@ cmTarget* cmMakefile::AddUtilityCommand(
[=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) {
BacktraceGuard guard(this->Backtrace, lfbt); BacktraceGuard guard(this->Backtrace, lfbt);
detail::AddUtilityCommand(lg, lfbt, cmCommandOrigin::Project, target, detail::AddUtilityCommand(lg, lfbt, cmCommandOrigin::Project, target,
force, GetCStrOrNull(workingStr), byproducts, GetCStrOrNull(workingStr), byproducts, depends,
depends, commandLines, escapeOldStyle, commandLines, escapeOldStyle,
GetCStrOrNull(commentStr), uses_terminal, GetCStrOrNull(commentStr), uses_terminal,
command_expand_lists, job_pool, stdPipesUTF8); command_expand_lists, job_pool, stdPipesUTF8);
}); });

View File

@@ -242,11 +242,6 @@ public:
const std::vector<std::string>& srcs, const std::vector<std::string>& srcs,
bool excludeFromAll = false); bool excludeFromAll = false);
/**
* Return the utility target output source file name.
*/
std::string GetUtilityOutput(cmTarget* target);
/** /**
* Dispatch adding a utility to the build. A utility target is a command * Dispatch adding a utility to the build. A utility target is a command
* that is run every time the target is built. * that is run every time the target is built.