From edd2712a34f6f8ec95a037c06ddae9d4aeed2d8f Mon Sep 17 00:00:00 2001 From: Naropanth Srikar Rao Date: Tue, 27 Oct 2026 00:47:39 -0500 Subject: [PATCH] cmGeneratorTarget: Replace GetFullPath realname parameter with an enum This makes call sites more readable. --- Source/cmComputeLinkInformation.cxx | 11 +++++++---- Source/cmExportBuildFileGenerator.cxx | 8 +++++--- Source/cmFastbuildNormalTargetGenerator.cxx | 11 ++++++----- Source/cmFileAPICodemodel.cxx | 3 ++- Source/cmGeneratorExpressionNode.cxx | 6 ++++-- Source/cmGeneratorTarget.cxx | 10 +++++----- Source/cmGeneratorTarget.h | 11 +++++++++-- Source/cmGlobalGenerator.cxx | 10 ++++++---- Source/cmGlobalNinjaGenerator.cxx | 8 +++++--- Source/cmLocalGenerator.cxx | 2 +- Source/cmMakefileTargetGenerator.cxx | 3 ++- Source/cmNinjaNormalTargetGenerator.cxx | 6 +++--- 12 files changed, 55 insertions(+), 34 deletions(-) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index c2528a65c9..4f9fcebcd8 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1151,7 +1151,8 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry) cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config) ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; - std::string exe = tgt->GetFullPath(config, artifact, true); + std::string exe = + tgt->GetFullPath(config, artifact, cmGeneratorTarget::NameType::Real); this->Items.emplace_back( BT(exe, item.Backtrace), ItemIsPath::Yes, tgt, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT @@ -1186,7 +1187,8 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry) // Pass the full path to the target file. BT lib = BT( - tgt->GetFullPath(config, artifact, true), item.Backtrace); + tgt->GetFullPath(config, artifact, cmGeneratorTarget::NameType::Real), + item.Backtrace); if (tgt->IsAIX() && cmHasLiteralSuffix(lib.Value, "-NOTFOUND") && artifact == cmStateEnums::ImportLibraryArtifact) { // This is an imported executable on AIX that has ENABLE_EXPORTS @@ -1207,7 +1209,8 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry) if (tgt->IsApple() && tgt->HasImportLibrary(config)) { // Use the library rather than the tbd file for runpath computation this->AddLibraryRuntimeInfo( - tgt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, true), + tgt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Real), tgt); } else { this->AddLibraryRuntimeInfo(lib.Value, tgt); @@ -1336,7 +1339,7 @@ void cmComputeLinkInformation::AddSharedDepItem(LinkEntry const& entry) // Use the library rather than the tbd file for runpath computation this->AddLibraryRuntimeInfo( tgt->GetFullPath(this->Config, cmStateEnums::RuntimeBinaryArtifact, - true), + cmGeneratorTarget::NameType::Real), tgt); } else { this->AddLibraryRuntimeInfo(lib, tgt); diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index dcf7a3a92c..71ab4928a5 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -101,8 +101,9 @@ void cmExportBuildFileGenerator::SetImportLocationProperty( value = target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact); } else { - value = target->GetFullPath(config, - cmStateEnums::RuntimeBinaryArtifact, true); + value = + target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Real); } properties[prop] = value; } @@ -111,7 +112,8 @@ void cmExportBuildFileGenerator::SetImportLocationProperty( if (target->HasImportLibrary(config)) { std::string prop = cmStrCat("IMPORTED_IMPLIB", suffix); std::string value = - target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact, true); + target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact, + cmGeneratorTarget::NameType::Real); if (mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) { target->GetImplibGNUtoMS(config, value, value, "${CMAKE_IMPORT_LIBRARY_SUFFIX}"); diff --git a/Source/cmFastbuildNormalTargetGenerator.cxx b/Source/cmFastbuildNormalTargetGenerator.cxx index 54f3ed33b0..d81302d93c 100644 --- a/Source/cmFastbuildNormalTargetGenerator.cxx +++ b/Source/cmFastbuildNormalTargetGenerator.cxx @@ -443,7 +443,7 @@ void cmFastbuildNormalTargetGenerator::ApplyLWYUToLinkerCommand( std::move(args), " --source=", this->ConvertToFastbuildPath(this->GetGeneratorTarget()->GetFullPath( Config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true))); + cmGeneratorTarget::NameType::Real))); LogMessage("LWUY args: " + args); linkerNode.LinkerStampExe = cmSystemTools::GetCMakeCommand(); @@ -1880,8 +1880,9 @@ std::string cmFastbuildNormalTargetGenerator::GetImportedLoc( ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; - std::string importedLoc = this->ConvertToFastbuildPath( - item.Target->GetFullPath(Config, artifact, true)); + std::string importedLoc = + this->ConvertToFastbuildPath(item.Target->GetFullPath( + Config, artifact, cmGeneratorTarget::NameType::Real)); LogMessage("ImportedGetLocation: " + importedLoc); return importedLoc; } @@ -2359,7 +2360,7 @@ void cmFastbuildNormalTargetGenerator::GenerateLink( ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config)); std::string targetOutputReal = ConvertToFastbuildPath( GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true)); + cmGeneratorTarget::NameType::Real)); LogMessage("targetOutput: " + targetOutput); LogMessage("targetOutputReal: " + targetOutputReal); @@ -2464,7 +2465,7 @@ cmFastbuildNormalTargetGenerator::GetSymlinkExecs() const ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config)); std::string const targetOutputReal = ConvertToFastbuildPath( GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true)); + cmGeneratorTarget::NameType::Real)); LogMessage("targetOutput: " + targetOutput); LogMessage("targetOutputReal: " + targetOutputReal); diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 425250d962..4b0bfe3df0 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -2362,7 +2362,8 @@ Json::Value Target::DumpArtifacts() } } else { fullPath = this->GT->NormalGetFullPath( - this->Config, cmStateEnums::ImportLibraryArtifact, false); + this->Config, cmStateEnums::ImportLibraryArtifact, + cmGeneratorTarget::NameType::Output); } if (!fullPath.empty()) { Json::Value artifact = Json::objectValue; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 0cd13bc803..a450edb03d 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -5827,7 +5827,8 @@ struct TargetFilesystemArtifactResultCreator GeneratorExpressionContent const* /*unused*/) { return target->GetFullPath(eval->Context.Config, - cmStateEnums::RuntimeBinaryArtifact, true); + cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Real); } }; @@ -5840,7 +5841,8 @@ struct TargetFilesystemArtifactResultCreator { if (target->HasImportLibrary(eval->Context.Config)) { return target->GetFullPath(eval->Context.Config, - cmStateEnums::ImportLibraryArtifact, true); + cmStateEnums::ImportLibraryArtifact, + cmGeneratorTarget::NameType::Real); } return std::string{}; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 7497954618..50cb551637 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3915,17 +3915,17 @@ std::string cmGeneratorTarget::GetImportedLibName( std::string cmGeneratorTarget::GetFullPath(std::string const& config, cmStateEnums::ArtifactType artifact, - bool realname) const + NameType nameType) const { if (this->IsImported()) { return this->Target->ImportedGetFullPath(config, artifact); } - return this->NormalGetFullPath(config, artifact, realname); + return this->NormalGetFullPath(config, artifact, nameType); } std::string cmGeneratorTarget::NormalGetFullPath( std::string const& config, cmStateEnums::ArtifactType artifact, - bool realname) const + NameType nameType) const { std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/'); if (this->IsAppBundleOnApple()) { @@ -3936,7 +3936,7 @@ std::string cmGeneratorTarget::NormalGetFullPath( // Add the full name of the target. switch (artifact) { case cmStateEnums::RuntimeBinaryArtifact: - if (realname) { + if (nameType == NameType::Real) { fpath += this->NormalGetRealName(config); } else { fpath += @@ -3944,7 +3944,7 @@ std::string cmGeneratorTarget::NormalGetFullPath( } break; case cmStateEnums::ImportLibraryArtifact: - if (realname) { + if (nameType == NameType::Real) { fpath += this->NormalGetRealName(config, cmStateEnums::ImportLibraryArtifact); } else { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index b275632b35..f67d6b2e5b 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -313,15 +313,22 @@ public: /** Get the library name for an imported interface library. */ std::string GetImportedLibName(std::string const& config) const; + /** Which file name to use for the last component of a target's path. */ + enum class NameType + { + Output, // The name that other build rules refer to, e.g. libfoo.so. + Real, // The name of the real file, e.g. libfoo.so.1.2.3. + }; + /** Get the full path to the target according to the settings in its makefile and the configuration type. */ std::string GetFullPath( std::string const& config, cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact, - bool realname = false) const; + NameType nameType = NameType::Output) const; std::string NormalGetFullPath(std::string const& config, cmStateEnums::ArtifactType artifact, - bool realname) const; + NameType nameType) const; std::string NormalGetRealName(std::string const& config, cmStateEnums::ArtifactType artifact = cmStateEnums::RuntimeBinaryArtifact) const; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1d2c196f96..6f6bf89b44 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2498,10 +2498,12 @@ cmGeneratorTarget* cmGlobalGenerator::FindArtifactOwningTarget( continue; } std::set artifacts; - artifacts.insert(cmSystemTools::CollapseFullPath(gt->GetFullPath( - config, cmStateEnums::RuntimeBinaryArtifact, /*realname=*/false))); - artifacts.insert(cmSystemTools::CollapseFullPath(gt->GetFullPath( - config, cmStateEnums::RuntimeBinaryArtifact, /*realname=*/true))); + artifacts.insert(cmSystemTools::CollapseFullPath( + gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Output))); + artifacts.insert(cmSystemTools::CollapseFullPath( + gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Real))); if (gt->HasImportLibrary(config)) { artifacts.insert(cmSystemTools::CollapseFullPath( gt->GetFullPath(config, cmStateEnums::ImportLibraryArtifact))); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 4420d486fc..fa44e408a2 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1542,7 +1542,9 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs( // frameworks always appear versioned, and the build.ninja // will always attempt to manage symbolic links instead // of letting cmOSXBundleGenerator do it. - bool realname = target->IsFrameworkOnApple(); + cmGeneratorTarget::NameType nameType = target->IsFrameworkOnApple() + ? cmGeneratorTarget::NameType::Real + : cmGeneratorTarget::NameType::Output; switch (target->GetType()) { case cm::TargetType::SHARED_LIBRARY: @@ -1557,10 +1559,10 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs( case cm::TargetType::EXECUTABLE: { if (target->IsApple() && target->HasImportLibrary(config)) { outputs.push_back(this->ConvertToNinjaPath(target->GetFullPath( - config, cmStateEnums::ImportLibraryArtifact, realname))); + config, cmStateEnums::ImportLibraryArtifact, nameType))); } outputs.push_back(this->ConvertToNinjaPath(target->GetFullPath( - config, cmStateEnums::RuntimeBinaryArtifact, realname))); + config, cmStateEnums::RuntimeBinaryArtifact, nameType))); break; } case cm::TargetType::OBJECT_LIBRARY: { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index e0b8518d6b..ba8ef1ea43 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2589,7 +2589,7 @@ bool cmLocalGenerator::GetRealDependency(std::string const& inName, case cm::TargetType::MODULE_LIBRARY: case cm::TargetType::UNKNOWN_LIBRARY: dep = target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true); + cmGeneratorTarget::NameType::Real); return true; case cm::TargetType::OBJECT_LIBRARY: // An object library has no single file on which to depend. diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 2f793589da..c050535157 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -923,7 +923,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( this->GeneratorTarget->GetType() == cm::TargetType::SHARED_LIBRARY || this->GeneratorTarget->GetType() == cm::TargetType::MODULE_LIBRARY) { targetFullPathReal = this->GeneratorTarget->GetFullPath( - this->GetConfigName(), cmStateEnums::RuntimeBinaryArtifact, true); + this->GetConfigName(), cmStateEnums::RuntimeBinaryArtifact, + cmGeneratorTarget::NameType::Real); targetFullPathPDB = cmStrCat( this->GeneratorTarget->GetPDBDirectory(this->GetConfigName()), '/', this->GeneratorTarget->GetPDBName(this->GetConfigName())); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 178cbed07a..fefcf4cf43 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -781,7 +781,7 @@ std::vector cmNinjaNormalTargetGenerator::ComputeLinkCmd( std::string targetOutputReal = this->ConvertToNinjaPath(this->GetGeneratorTarget()->GetFullPath( config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true)); + cmGeneratorTarget::NameType::Real)); cmakeCommand = cmStrCat(std::move(cmakeCommand), " --source=", targetOutputReal); linkCmds.push_back(std::move(cmakeCommand)); @@ -1173,7 +1173,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( std::string targetOutput = this->ConvertToNinjaPath(gt->GetFullPath(config)); std::string targetOutputReal = this->ConvertToNinjaPath( gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true)); + cmGeneratorTarget::NameType::Real)); std::string targetOutputImplib = this->ConvertToNinjaPath( gt->GetFullPath(config, cmStateEnums::ImportLibraryArtifact)); @@ -1185,7 +1185,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( if (targetOutputReal == this->ConvertToNinjaPath( gt->GetFullPath(fileConfig, cmStateEnums::RuntimeBinaryArtifact, - /*realname=*/true))) { + cmGeneratorTarget::NameType::Real))) { return; } if (!gt->GetFullName(config, cmStateEnums::ImportLibraryArtifact)