1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

cmNinjaTargetGenerator: use GetObjectFileDir where possible

Lots of code simplification.
This commit is contained in:
Ben Boeckel
2025-05-21 21:17:03 +02:00
parent 9f97582973
commit aafd771529

View File

@@ -450,18 +450,11 @@ std::string cmNinjaTargetGenerator::GetClangTidyReplacementsFilePath(
std::string const& directory, cmSourceFile const& source, std::string const& directory, cmSourceFile const& source,
std::string const& config) const std::string const& config) const
{ {
auto path = this->LocalGenerator->GetHomeRelativeOutputPath();
if (!path.empty()) {
path += '/';
}
path = cmStrCat(directory, '/', path);
auto const& objectName = this->GeneratorTarget->GetObjectName(&source); auto const& objectName = this->GeneratorTarget->GetObjectName(&source);
path = return cmStrCat(directory, '/',
cmStrCat(std::move(path), this->LocalGenerator->CreateSafeObjectFileName(
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), this->GetObjectFileDir(config)),
this->GetGlobalGenerator()->ConfigDirectory(config), '/', '/', objectName, ".yaml");
objectName, ".yaml");
return path;
} }
std::string cmNinjaTargetGenerator::GetPreprocessedFilePath( std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
@@ -490,38 +483,20 @@ std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
std::string const ppName = std::string const ppName =
cmStrCat(objName.substr(0, objName.size() - objExt.size()), "-pp.", ppExt); cmStrCat(objName.substr(0, objName.size() - objExt.size()), "-pp.", ppExt);
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); return cmStrCat(this->GetObjectFileDir(config), '/', ppName);
if (!path.empty()) {
path += '/';
}
path +=
cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
this->GetGlobalGenerator()->ConfigDirectory(config), '/', ppName);
return path;
} }
std::string cmNinjaTargetGenerator::GetDyndepFilePath( std::string cmNinjaTargetGenerator::GetDyndepFilePath(
std::string const& lang, std::string const& config) const std::string const& lang, std::string const& config) const
{ {
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); return cmStrCat(this->GetObjectFileDir(config), '/', lang, ".dd");
if (!path.empty()) {
path += '/';
}
path += cmStrCat(
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang, ".dd");
return path;
} }
std::string cmNinjaTargetGenerator::GetTargetDependInfoPath( std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
std::string const& lang, std::string const& config) const std::string const& lang, std::string const& config) const
{ {
std::string path = return cmStrCat(this->GetObjectFileDir(config), '/', lang,
cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang,
"DependInfo.json"); "DependInfo.json");
return path;
} }
std::string cmNinjaTargetGenerator::GetTargetOutputDir( std::string cmNinjaTargetGenerator::GetTargetOutputDir(
@@ -1129,9 +1104,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
tgtDir = "."; tgtDir = ".";
} else { } else {
// Any path that always exists will work here. // Any path that always exists will work here.
tgtDir = cmStrCat( tgtDir = this->GetObjectFileDir(config);
this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget));
} }
orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
} }
@@ -1233,10 +1206,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
cmNinjaBuild build(this->LanguageDyndepRule(language, config)); cmNinjaBuild build(this->LanguageDyndepRule(language, config));
build.Outputs.push_back(this->GetDyndepFilePath(language, config)); build.Outputs.push_back(this->GetDyndepFilePath(language, config));
build.ImplicitOuts.emplace_back( build.ImplicitOuts.emplace_back(
cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', cmStrCat(this->GetObjectFileDir(config), '/', language, "Modules.json"));
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
this->GetGlobalGenerator()->ConfigDirectory(config), '/',
language, "Modules.json"));
build.ImplicitDeps.emplace_back( build.ImplicitDeps.emplace_back(
this->GetTargetDependInfoPath(language, config)); this->GetTargetDependInfoPath(language, config));
{ {
@@ -1411,9 +1381,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
{ {
std::string const language = source->GetLanguage(); std::string const language = source->GetLanguage();
std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source); std::string const sourceFilePath = this->GetCompiledSourceNinjaPath(source);
std::string const objectDir = this->ConvertToNinjaPath( std::string const objectDir =
cmStrCat(this->GeneratorTarget->GetSupportDirectory(), this->ConvertToNinjaPath(this->GetObjectFileDir(config));
this->GetGlobalGenerator()->ConfigDirectory(config)));
std::string const objectFileName = std::string const objectFileName =
this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)); this->ConvertToNinjaPath(this->GetObjectFilePath(source, config));
std::string const objectFileDir = std::string const objectFileDir =