Browse Source

CPack: Enable Inno Setup generator on non-Windows hosts

Innosetup tools can be run on Linux using Wine, thus there is no reason
to block this in CMake.
Andreas Oetken 1 year ago
parent
commit
d4a46314ac

+ 5 - 1
Help/cpack_gen/innosetup.rst

@@ -12,7 +12,11 @@ The generator provides a lot of options like components. Unfortunately, not
 all features (e.g. component dependencies) are currently supported by
 Inno Setup and they're ignored by the generator for now.
 
-CPack requires Inno Setup 6 or greater and only works on Windows.
+CPack requires Inno Setup 6 or greater.
+
+.. versionadded:: 3.30
+  The generator is now available on non-Windows hosts,
+  but requires Wine to run the Inno Setup tools.
 
 Variables specific to CPack Inno Setup generator
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

+ 5 - 0
Help/release/dev/cpack-innosetup-linux.rst

@@ -0,0 +1,5 @@
+cpack-innosetup-linux
+---------------------
+
+* The :cpack_gen:`CPack Inno Setup Generator` is now available
+  on non-Windows hosts.

+ 13 - 9
Source/CPack/cmCPackInnoSetupGenerator.cxx

@@ -24,12 +24,7 @@ cmCPackInnoSetupGenerator::~cmCPackInnoSetupGenerator() = default;
 
 bool cmCPackInnoSetupGenerator::CanGenerate()
 {
-  // Inno Setup is only available for Windows
-#ifdef _WIN32
   return true;
-#else
-  return false;
-#endif
 }
 
 int cmCPackInnoSetupGenerator::InitializeInternal()
@@ -63,7 +58,8 @@ int cmCPackInnoSetupGenerator::InitializeInternal()
     return 0;
   }
 
-  const std::string isccCmd = cmStrCat(QuotePath(isccPath), "/?");
+  const std::string isccCmd =
+    cmStrCat(QuotePath(isccPath, PathType::Native), "/?");
   cmCPackLogger(cmCPackLog::LOG_VERBOSE,
                 "Test Inno Setup version: " << isccCmd << std::endl);
   std::string output;
@@ -869,8 +865,8 @@ bool cmCPackInnoSetupGenerator::Compile()
   }
 
   const std::string& isccCmd =
-    cmStrCat(QuotePath(GetOption("CPACK_INSTALLER_PROGRAM")), ' ',
-             cmJoin(isccArgs, " "), ' ', QuotePath(isScriptFile));
+    cmStrCat(QuotePath(GetOption("CPACK_INSTALLER_PROGRAM"), PathType::Native),
+             ' ', cmJoin(isccArgs, " "), ' ', QuotePath(isScriptFile));
 
   cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << isccCmd << std::endl);
 
@@ -1136,8 +1132,16 @@ std::string cmCPackInnoSetupGenerator::Quote(const std::string& string)
   return cmStrCat('"', nString, '"');
 }
 
-std::string cmCPackInnoSetupGenerator::QuotePath(const std::string& path)
+std::string cmCPackInnoSetupGenerator::QuotePath(const std::string& path,
+                                                 PathType type)
 {
+#ifdef _WIN32
+  static_cast<void>(type);
+#else
+  if (type == PathType::Native) {
+    return Quote(cmSystemTools::ConvertToUnixOutputPath(path));
+  }
+#endif
   return Quote(cmSystemTools::ConvertToWindowsOutputPath(path));
 }
 

+ 8 - 1
Source/CPack/cmCPackInnoSetupGenerator.h

@@ -49,6 +49,12 @@ protected:
   inline bool SupportsComponentInstallation() const override { return true; }
 
 private:
+  enum class PathType
+  {
+    Windows,
+    Native,
+  };
+
   bool ProcessSetupSection();
   bool ProcessFiles();
   bool ProcessComponents();
@@ -92,7 +98,8 @@ private:
    * Paths are converted into the format used by Windows before.
    */
   std::string Quote(const std::string& string);
-  std::string QuotePath(const std::string& path);
+  std::string QuotePath(const std::string& path,
+                        PathType type = PathType::Windows);
 
   /**
    * This function replaces the following 5 characters with their %-encoding: