Browse Source

cmCPackGenerator: Add option to FindTemplate to use alternate builtin path

Brad King 1 year ago
parent
commit
438809d3ba
2 changed files with 11 additions and 5 deletions
  1. 6 4
      Source/CPack/cmCPackGenerator.cxx
  2. 5 1
      Source/CPack/cmCPackGenerator.h

+ 6 - 4
Source/CPack/cmCPackGenerator.cxx

@@ -7,6 +7,8 @@
 #include <memory>
 #include <utility>
 
+#include <cmext/string_view>
+
 #include "cmsys/FStream.hxx"
 #include "cmsys/Glob.hxx"
 #include "cmsys/RegularExpression.hxx"
@@ -1315,17 +1317,17 @@ const char* cmCPackGenerator::GetPackagingInstallPrefix()
   return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX")->c_str();
 }
 
-std::string cmCPackGenerator::FindTemplate(const char* name)
+std::string cmCPackGenerator::FindTemplate(cm::string_view name,
+                                           cm::optional<cm::string_view> alt)
 {
   cmCPackLogger(cmCPackLog::LOG_DEBUG,
-                "Look for template: " << (name ? name : "(NULL)")
-                                      << std::endl);
+                "Look for template: " << name << std::endl);
   // Search CMAKE_MODULE_PATH for a custom template.
   std::string ffile = this->MakefileMap->GetModulesFile(name);
   if (ffile.empty()) {
     // Fall back to our internal builtin default.
     ffile = cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/Internal/CPack/",
-                     name);
+                     alt ? *alt : ""_s, name);
     cmSystemTools::ConvertToUnixSlashes(ffile);
     if (!cmSystemTools::FileExists(ffile)) {
       ffile.clear();

+ 5 - 1
Source/CPack/cmCPackGenerator.h

@@ -9,6 +9,9 @@
 #include <string>
 #include <vector>
 
+#include <cm/optional>
+#include <cm/string_view>
+
 #include "cm_sys_stat.h"
 
 #include "cmCPackComponentGroup.h"
@@ -179,7 +182,8 @@ protected:
   virtual const char* GetInstallPath();
   virtual const char* GetPackagingInstallPrefix();
 
-  virtual std::string FindTemplate(const char* name);
+  std::string FindTemplate(cm::string_view name,
+                           cm::optional<cm::string_view> alt = cm::nullopt);
   virtual bool ConfigureFile(const std::string& inName,
                              const std::string& outName,
                              bool copyOnly = false);