Browse Source

Merge topic 'cpack-custom-templates'

7d6ab5dc5b CPack: Restore support for custom package configuration templates

Acked-by: Kitware Robot <[email protected]>
Acked-by: Kyle Edwards <[email protected]>
Merge-request: !4054
Brad King 6 years ago
parent
commit
0e46dea343

+ 1 - 1
Source/CPack/WiX/cmCPackWIXGenerator.cxx

@@ -610,7 +610,7 @@ std::string cmCPackWIXGenerator::GetRootFolderId() const
 
 bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
 {
-  std::string wixTemplate = FindTemplate("Internal/CPack/WIX.template.in");
+  std::string wixTemplate = FindTemplate("WIX.template.in");
   if (GetOption("CPACK_WIX_TEMPLATE") != 0) {
     wixTemplate = GetOption("CPACK_WIX_TEMPLATE");
   }

+ 11 - 0
Source/CPack/cmCPackGenerator.cxx

@@ -23,6 +23,7 @@
 #include "cmState.h"
 #include "cmStateSnapshot.h"
 #include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
 #include "cmVersion.h"
 #include "cmWorkingDirectory.h"
 #include "cmXMLSafe.h"
@@ -1254,7 +1255,17 @@ std::string cmCPackGenerator::FindTemplate(const char* name)
   cmCPackLogger(cmCPackLog::LOG_DEBUG,
                 "Look for template: " << (name ? name : "(NULL)")
                                       << 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);
+    cmSystemTools::ConvertToUnixSlashes(ffile);
+    if (!cmSystemTools::FileExists(ffile)) {
+      ffile.clear();
+    }
+  }
   cmCPackLogger(cmCPackLog::LOG_DEBUG,
                 "Found template: " << ffile << std::endl);
   return ffile;

+ 2 - 3
Source/CPack/cmCPackNSISGenerator.cxx

@@ -39,8 +39,7 @@ int cmCPackNSISGenerator::PackageFiles()
 {
   // TODO: Fix nsis to force out file name
 
-  std::string nsisInFileName =
-    this->FindTemplate("Internal/CPack/NSIS.template.in");
+  std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
   if (nsisInFileName.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "CPack error: Could not find NSIS installer template file."
@@ -48,7 +47,7 @@ int cmCPackNSISGenerator::PackageFiles()
     return false;
   }
   std::string nsisInInstallOptions =
-    this->FindTemplate("Internal/CPack/NSIS.InstallOptions.ini.in");
+    this->FindTemplate("NSIS.InstallOptions.ini.in");
   if (nsisInInstallOptions.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "CPack error: Could not find NSIS installer options file."

+ 1 - 1
Source/CPack/cmCPackOSXX11Generator.cxx

@@ -240,7 +240,7 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile(
   const std::string& name, const std::string& dir,
   const char* outputFileName /* = 0 */, bool copyOnly /* = false */)
 {
-  std::string inFName = cmStrCat("Internal/CPack/CPack.", name, ".in");
+  std::string inFName = cmStrCat("CPack.", name, ".in");
   std::string inFileName = this->FindTemplate(inFName.c_str());
   if (inFileName.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,

+ 2 - 2
Source/CPack/cmCPackPKGGenerator.cxx

@@ -108,7 +108,7 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile,
                                                 const char* genName)
 {
   std::string distributionTemplate =
-    this->FindTemplate("Internal/CPack/CPack.distribution.dist.in");
+    this->FindTemplate("CPack.distribution.dist.in");
   if (distributionTemplate.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "Cannot find input file: " << distributionTemplate
@@ -364,7 +364,7 @@ bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name,
     outName = name.c_str();
   }
 
-  std::string inFName = cmStrCat("Internal/CPack/CPack.", name, ".in");
+  std::string inFName = cmStrCat("CPack.", name, ".in");
   std::string inFileName = this->FindTemplate(inFName.c_str());
   if (inFileName.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,

+ 1 - 2
Source/CPack/cmCPackSTGZGenerator.cxx

@@ -27,8 +27,7 @@ int cmCPackSTGZGenerator::InitializeInternal()
 {
   this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
 
-  std::string inFile =
-    this->FindTemplate("Internal/CPack/CPack.STGZ_Header.sh.in");
+  std::string inFile = this->FindTemplate("CPack.STGZ_Header.sh.in");
   if (inFile.empty()) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "Cannot find template file: " << inFile << std::endl);