mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
Makefiles: pass the target name to cmake -E cmake_depends
When a shortened directory is used, the name of the target is not accessible just by the path. Pass it explicitly.
This commit is contained in:
@@ -290,6 +290,7 @@ public:
|
||||
|
||||
/** Called from command-line hook to update dependencies. */
|
||||
virtual bool UpdateDependencies(std::string const& /* tgtInfo */,
|
||||
std::string const& /* targetName */,
|
||||
bool /*verbose*/, bool /*color*/)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -1376,7 +1376,8 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable(
|
||||
}
|
||||
|
||||
bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
|
||||
std::string const& tgtInfo, bool verbose, bool color)
|
||||
std::string const& tgtInfo, std::string const& targetName, bool verbose,
|
||||
bool color)
|
||||
{
|
||||
// read in the target info file
|
||||
if (!this->Makefile->ReadListFile(tgtInfo) ||
|
||||
@@ -1473,8 +1474,6 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
|
||||
if (needRescanDependInfo || needRescanDirInfo || needRescanDependencies) {
|
||||
// The dependencies must be regenerated.
|
||||
if (verbose) {
|
||||
std::string targetName = cmSystemTools::GetFilenameName(targetDir);
|
||||
targetName = targetName.substr(0, targetName.length() - 4);
|
||||
std::string message =
|
||||
cmStrCat("Scanning dependencies of target ", targetName);
|
||||
echoColor(message);
|
||||
@@ -1508,10 +1507,6 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
|
||||
: std::function<bool(std::string const&)>())) {
|
||||
// regenerate dependencies files
|
||||
if (verbose) {
|
||||
std::string targetName = cmCMakePath(targetDir)
|
||||
.GetFileName()
|
||||
.RemoveExtension()
|
||||
.GenericString();
|
||||
auto message =
|
||||
cmStrCat("Consolidate compiler generated dependencies of target ",
|
||||
targetName);
|
||||
|
||||
@@ -135,7 +135,8 @@ public:
|
||||
|
||||
/** Called from command-line hook to bring dependencies up to date
|
||||
for a target. */
|
||||
bool UpdateDependencies(std::string const& tgtInfo, bool verbose,
|
||||
bool UpdateDependencies(std::string const& tgtInfo,
|
||||
std::string const& targetName, bool verbose,
|
||||
bool color) override;
|
||||
|
||||
/** Called from command-line hook to clear dependencies. */
|
||||
|
||||
@@ -1548,6 +1548,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
||||
// <home-src-dir> <start-src-dir>
|
||||
// <home-out-dir> <start-out-dir>
|
||||
// <dep-info> --color=$(COLOR)
|
||||
// <target-name>
|
||||
//
|
||||
// This gives the dependency scanner enough information to recreate
|
||||
// the state of our local generator sufficiently for its needs.
|
||||
@@ -1574,6 +1575,9 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
||||
if (this->LocalGenerator->GetColorMakefile()) {
|
||||
depCmd << " \"--color=$(COLOR)\"";
|
||||
}
|
||||
depCmd << ' '
|
||||
<< this->LocalGenerator->ConvertToOutputFormat(
|
||||
this->GeneratorTarget->GetName(), cmOutputConverter::SHELL);
|
||||
commands.push_back(depCmd.str());
|
||||
|
||||
// Make sure all custom command outputs in this target are built.
|
||||
|
||||
@@ -1361,6 +1361,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
std::string homeOutDir;
|
||||
std::string startOutDir;
|
||||
std::string depInfo;
|
||||
std::string targetName;
|
||||
bool color = false;
|
||||
if (args.size() >= 8) {
|
||||
// Full signature:
|
||||
@@ -1369,6 +1370,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
// <home-src-dir> <start-src-dir>
|
||||
// <home-out-dir> <start-out-dir>
|
||||
// <dep-info> [--color=$(COLOR)]
|
||||
// <target-name>
|
||||
//
|
||||
// All paths are provided.
|
||||
gen = args[2];
|
||||
@@ -1377,10 +1379,19 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
homeOutDir = args[5];
|
||||
startOutDir = args[6];
|
||||
depInfo = args[7];
|
||||
size_t targetNameIdx = 8;
|
||||
if (args.size() >= 9 && cmHasLiteralPrefix(args[8], "--color=")) {
|
||||
// Enable or disable color based on the switch value.
|
||||
targetNameIdx = 9;
|
||||
color = (args[8].size() == 8 || cmIsOn(args[8].substr(8)));
|
||||
}
|
||||
if (args.size() > targetNameIdx) {
|
||||
targetName = args[targetNameIdx];
|
||||
} else {
|
||||
std::string targetDir = cmSystemTools::GetFilenamePath(depInfo);
|
||||
targetDir = cmSystemTools::GetFilenameName(targetDir);
|
||||
targetName = targetDir.substr(0, targetDir.size() - 4);
|
||||
}
|
||||
} else {
|
||||
// Support older signature for existing makefiles:
|
||||
//
|
||||
@@ -1396,6 +1407,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
homeOutDir = args[3];
|
||||
startOutDir = args[3];
|
||||
depInfo = args[5];
|
||||
// Strip the `.dir` suffix. Old CMake always uses this pattern.
|
||||
std::string targetDir = cmSystemTools::GetFilenamePath(depInfo);
|
||||
targetDir = cmSystemTools::GetFilenameName(targetDir);
|
||||
targetName = targetDir.substr(0, targetDir.size() - 4);
|
||||
}
|
||||
|
||||
// Create a local generator configured for the directory in
|
||||
@@ -1421,7 +1436,9 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
lgd->SetRelativePathTop(homeDir, homeOutDir);
|
||||
|
||||
// Actually scan dependencies.
|
||||
return lgd->UpdateDependencies(depInfo, verbose, color) ? 0 : 2;
|
||||
return lgd->UpdateDependencies(depInfo, targetName, verbose, color)
|
||||
? 0
|
||||
: 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user