From 7929094e6c4034060b8a8a3cbb33f3068cac43e9 Mon Sep 17 00:00:00 2001
From: Calin Cascaval <cascaval@acm.org>
Date: Fri, 26 Dec 2014 09:48:53 -0800
Subject: [PATCH] PackageMaker: fixes version format

---
 Source/CPack/cmCPackPackageMakerGenerator.cxx | 32 +++++++++++++++++++--------
 Source/CPack/cmCPackPackageMakerGenerator.h   |  2 +-
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
index e799d06..aa6fdd5 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.cxx
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -9,6 +9,7 @@
   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the License for more information.
 ============================================================================*/
+#include <cassert>
 #include "cmCPackPackageMakerGenerator.h"

 #include "cmake.h"
@@ -24,11 +25,18 @@
 #include <cmsys/Glob.hxx>
 #include <cmsys/FStream.hxx>

+static inline
+unsigned int getVersion(unsigned int major, unsigned int minor)
+{
+  assert(major < 256 && minor < 256);
+  return ((major & 0xFF) << 16 | minor);
+}
+
 //----------------------------------------------------------------------
 cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
 {
   this->PackageMakerVersion = 0.0;
-  this->PackageCompatibilityVersion = 10.4;
+  this->PackageCompatibilityVersion = getVersion(10, 4);
 }

 //----------------------------------------------------------------------
@@ -39,7 +47,7 @@ cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
 //----------------------------------------------------------------------
 bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
 {
-  return this->PackageCompatibilityVersion >= 10.4;
+  return this->PackageCompatibilityVersion >= getVersion(10, 4);
 }

 //----------------------------------------------------------------------
@@ -241,7 +249,7 @@ int cmCPackPackageMakerGenerator::PackageFiles()
       std::string packageFile;
       if (compIt->second.IsDownloaded)
         {
-        if (this->PackageCompatibilityVersion >= 10.5 &&
+        if (this->PackageCompatibilityVersion >= getVersion(10, 5) &&
             this->PackageMakerVersion >= 3.0)
           {
           // Build this package within the upload directory.
@@ -260,7 +268,7 @@ int cmCPackPackageMakerGenerator::PackageFiles()
           }
         else if (!warnedAboutDownloadCompatibility)
           {
-          if (this->PackageCompatibilityVersion < 10.5)
+            if (this->PackageCompatibilityVersion < getVersion(10, 5))
             {
             cmCPackLogger(
               cmCPackLog::LOG_WARNING,
@@ -520,22 +528,28 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
   const char *packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
   if (packageCompat && *packageCompat)
     {
-    this->PackageCompatibilityVersion = atof(packageCompat);
+    unsigned int majorVersion = 10;
+    unsigned int minorVersion = 5;
+    int res = sscanf(packageCompat, "%u.%u", &majorVersion, &minorVersion);
+    if (res == 2)
+      {
+      this->PackageCompatibilityVersion = getVersion(majorVersion, minorVersion);
+      }
     }
   else if (this->GetOption("CPACK_DOWNLOAD_SITE"))
     {
     this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
-    this->PackageCompatibilityVersion = 10.5;
+    this->PackageCompatibilityVersion = getVersion(10, 5);
     }
   else if (this->GetOption("CPACK_COMPONENTS_ALL"))
     {
     this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
-    this->PackageCompatibilityVersion = 10.4;
+    this->PackageCompatibilityVersion = getVersion(10, 4);
     }
   else
     {
     this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
-    this->PackageCompatibilityVersion = 10.3;
+    this->PackageCompatibilityVersion = getVersion(10, 3);
     }

   std::vector<std::string> no_paths;
@@ -712,7 +726,7 @@ GenerateComponentPackage(const char *packageFile,
   // The command that will be used to run PackageMaker
   cmOStringStream pkgCmd;

-  if (this->PackageCompatibilityVersion < 10.5 ||
+  if (this->PackageCompatibilityVersion < getVersion(10, 5) ||
       this->PackageMakerVersion < 3.0)
     {
     // Create Description.plist and Info.plist files for normal Mac OS
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h
index e350a60..4f9e2a8 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.h
+++ b/Source/CPack/cmCPackPackageMakerGenerator.h
@@ -117,7 +117,7 @@ protected:
   cmCPackComponent PostFlightComponent;

   double PackageMakerVersion;
-  double PackageCompatibilityVersion;
+  unsigned int PackageCompatibilityVersion;
 };

 #endif
--
2.2.1

