From 168e55be416583fa90b3ccef3bb9326f2eeaade1 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 5 Sep 2025 23:48:37 -0400 Subject: [PATCH] cmObjectLocation: support install-specific object locations This will be used to implement custom install object paths. These can support per-configuration values much more easily as it is generator-agnostic. --- Source/cmGeneratorTarget.cxx | 3 ++- Source/cmObjectLocation.cxx | 19 +++++++++++++++++++ Source/cmObjectLocation.h | 7 +++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 0c89f0e80b..671c278263 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4054,7 +4054,8 @@ void cmGeneratorTarget::GetTargetObjectLocations( // Find the object file name corresponding to this source file. auto map_it = mapping.find(src); auto const& buildLoc = map_it->second.GetLocation(buildUseShortPaths); - auto const& installLoc = map_it->second.GetLocation(installUseShortPaths); + auto const& installLoc = + map_it->second.GetInstallLocation(installUseShortPaths, config); // It must exist because we populated the mapping just above. assert(!buildLoc.GetPath().empty()); assert(!installLoc.GetPath().empty()); diff --git a/Source/cmObjectLocation.cxx b/Source/cmObjectLocation.cxx index bb0c2ee9dd..7b3c382b89 100644 --- a/Source/cmObjectLocation.cxx +++ b/Source/cmObjectLocation.cxx @@ -45,3 +45,22 @@ std::string const& cmObjectLocations::GetPath(UseShortPath use) const { return this->GetLocation(use).GetPath(); } + +cmObjectLocation const& cmObjectLocations::GetInstallLocation( + UseShortPath use, std::string const& config) const +{ + if (use == UseShortPath::Yes && this->ShortLoc) { + return *this->ShortLoc; + } + auto it = this->InstallLongLoc.find(config); + if (it != this->InstallLongLoc.end()) { + return it->second; + } + return this->LongLoc; +} + +std::string const& cmObjectLocations::GetInstallPath( + UseShortPath use, std::string const& config) const +{ + return this->GetInstallLocation(use, config).GetPath(); +} diff --git a/Source/cmObjectLocation.h b/Source/cmObjectLocation.h index 2cf2564635..b2eabf238a 100644 --- a/Source/cmObjectLocation.h +++ b/Source/cmObjectLocation.h @@ -4,6 +4,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include @@ -39,6 +40,7 @@ struct cmObjectLocations cm::optional ShortLoc; cmObjectLocation LongLoc; + std::map InstallLongLoc; enum class UseShortPath { @@ -47,4 +49,9 @@ struct cmObjectLocations }; cmObjectLocation const& GetLocation(UseShortPath use) const; std::string const& GetPath(UseShortPath use) const; + + cmObjectLocation const& GetInstallLocation(UseShortPath use, + std::string const& config) const; + std::string const& GetInstallPath(UseShortPath use, + std::string const& config) const; };