Browse Source

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.
Ben Boeckel 3 months ago
parent
commit
168e55be41
3 changed files with 28 additions and 1 deletions
  1. 2 1
      Source/cmGeneratorTarget.cxx
  2. 19 0
      Source/cmObjectLocation.cxx
  3. 7 0
      Source/cmObjectLocation.h

+ 2 - 1
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());

+ 19 - 0
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();
+}

+ 7 - 0
Source/cmObjectLocation.h

@@ -4,6 +4,7 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
+#include <map>
 #include <string>
 #include <utility>
 
@@ -39,6 +40,7 @@ struct cmObjectLocations
 
   cm::optional<cmObjectLocation> ShortLoc;
   cmObjectLocation LongLoc;
+  std::map<std::string, cmObjectLocation> 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;
 };