If you are interested, attached is some code I started a couple years ago but 
never finished, nor did I do much testing.
Perhaps that'll help, or maybe you'll find a better way.

Clint

----- On Dec 11, 2015, at 9:50 AM, Robert Bielik robert.bie...@dirac.se wrote:

> Dear Attila,
> 
> Ok, been struggling getting an installation package to work with the
> pkgbuild/productbild tools, so I think I got the gist of what needs to
> be done, at least to get something going :)
> 
> Regards
> /R
> 
> Den 2015-12-11 kl. 17:47, skrev Attila Krasznahorkay:
>> Hi Robert,
>>
>> I'm afraid that the sad situation is that nobody has done this yet, or is
>> working on it at the moment.
>>
>> I'm absolutely sure that if you can help with this by any amount, that will 
>> be
>> most welcome by the CMake developers. It will certainly be most welcome by 
>> me,
>> as I've been disappointed by the lack of this support as well. (But
>> unfortunately can't spare the time to help out in writing this CPack
>> generator.)
>>
>> Cheers,
>>               Attila
>>
>>> On 11 Dec 2015, at 17:44, Robert Bielik <robert.bie...@dirac.se> wrote:
>>>
>>> Really ? No one ? :)
>>>
>>> So it's ok to go ahead and start create a new one ? ;)
>>>
>>> Rgds,
>>> /R
>>>
>>> Den 2015-12-09 kl. 16:56, skrev Robert Bielik:
>>>> Mac OSX:
>>>>
>>>> Since PackageMaker has been deprecated by Apple, the new tools to use are
>>>> pkgbuild [1] and productbuild [2].
>>>>
>>>> Simple question: Is there any work being done by the CMake community on a 
>>>> new OS
>>>> X CPack backend to support the above tools ?
>>>>
>>>> Regards
>>>> /Robert
>>>> [1]
>>>> https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pkgbuild.1.html
>>>> [2]
>>>> https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/productbuild.1.html
>>>>
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Kitware offers various services to support the CMake community. For more
>>> information on each offering, please visit:
>>>
>>> CMake Support: http://cmake.org/cmake/help/support.html
>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/cmake
> 
> --
> 
> Powered by www.kitware.com
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
> 
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
commit a49e2b32e9ac1d2d486829c5ee4d8a399530875f
Author: Clinton Stimpson <clin...@elemtech.com>
Date:   Sat Nov 2 10:24:53 2013 -0600

    add product build generator.

diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index a4c982f..79dab75 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -632,6 +632,7 @@ if(APPLE)
     CPack/cmCPackDragNDropGenerator.cxx
     CPack/cmCPackOSXX11Generator.cxx
     CPack/cmCPackPackageMakerGenerator.cxx
+    CPack/cmCPackProductBuildGenerator.cxx
     )
 endif()
 
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
index 94ca536..ed1821f 100644
--- a/Source/CPack/cmCPackGeneratorFactory.cxx
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -28,6 +28,7 @@
 #  include "cmCPackBundleGenerator.h"
 #  include "cmCPackPackageMakerGenerator.h"
 #  include "cmCPackOSXX11Generator.h"
+#  include "cmCPackProductBuildGenerator.h"
 #endif
 
 #ifdef __CYGWIN__
@@ -139,6 +140,11 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
     this->RegisterGenerator("OSXX11", "Mac OSX X11 bundle",
       cmCPackOSXX11Generator::CreateGenerator);
     }
+  if (cmCPackProductBuildGenerator::CanGenerate())
+    {
+    this->RegisterGenerator("ProductBuild", "Mac OSX pkg",
+      cmCPackProductBuildGenerator::CreateGenerator);
+    }
 #endif
 #if !defined(_WIN32) \
   && !defined(__QNXNTO__) && !defined(__BEOS__) && !defined(__HAIKU__)
diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx
new file mode 100644
index 0000000..75c08bb
--- /dev/null
+++ b/Source/CPack/cmCPackProductBuildGenerator.cxx
@@ -0,0 +1,217 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+#include "cmCPackProductBuildGenerator.h"
+
+#include "cmake.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmSystemTools.h"
+#include "cmMakefile.h"
+#include "cmGeneratedFileStream.h"
+#include "cmCPackComponentGroup.h"
+#include "cmCPackLog.h"
+
+#include <cmsys/SystemTools.hxx>
+#include <cmsys/Glob.hxx>
+
+//----------------------------------------------------------------------
+cmCPackProductBuildGenerator::cmCPackProductBuildGenerator()
+{
+  this->componentPackageMethod = ONE_PACKAGE;
+}
+
+//----------------------------------------------------------------------
+cmCPackProductBuildGenerator::~cmCPackProductBuildGenerator()
+{
+}
+
+//----------------------------------------------------------------------
+bool cmCPackProductBuildGenerator::SupportsComponentInstallation() const
+{
+  return true;
+}
+
+//----------------------------------------------------------------------
+int cmCPackProductBuildGenerator::PackageFiles()
+{
+  // TODO: Use toplevel
+  //       It is used! Is this an obsolete comment?
+
+  std::string resDir; // Where this package's resources will go.
+  std::string packageDirFileName
+    = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+  
+  if (!this->Components.empty())
+    {
+    // Create the directory where component packages will be built.
+    std::string basePackageDir = packageDirFileName;
+    basePackageDir += "/Contents/Packages";
+    if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str()))
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+                    "Problem creating component packages directory: "
+                    << basePackageDir.c_str() << std::endl);
+      return 0;
+      }
+
+    std::map<std::string, cmCPackComponent>::iterator compIt;
+    for (compIt = this->Components.begin(); compIt != this->Components.end();
+         ++compIt)
+      {
+      // Build this package within the overall distribution
+      // metapackage.
+      std::string packageFile = basePackageDir;
+
+      packageFile += '/';
+      packageFile += GetPackageName(compIt->second);
+
+      std::string packageDir = toplevel;
+      packageDir += '/';
+      packageDir += compIt->first;
+      if (!this->GenerateComponentPackage(packageFile,
+                                          packageDir,
+                                          &compIt->second))
+        {
+        return 0;
+        }
+      }
+    }
+
+  if (this->Components.empty())
+    {
+    if(!this->GenerateComponentPackage(packageFileNames[0],
+                                       toplevel, NULL))
+      {
+      return 0;
+      }
+    }
+  else
+    {
+    // combine multiple packages into one
+    }
+
+  return 1;
+}
+
+//----------------------------------------------------------------------
+int cmCPackProductBuildGenerator::InitializeInternal()
+{
+  cmCPackLogger(cmCPackLog::LOG_DEBUG,
+    "cmCPackProductBuildGenerator::Initialize()" << std::endl);
+  this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
+
+  // TODO: find pkgbuild and productbuild
+
+  return this->Superclass::InitializeInternal();
+}
+
+
+//----------------------------------------------------------------------
+bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command,
+                                                   const std::string& packageFile)
+{
+  std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+  tmpFile += "/ProductBuildOutput.log";
+
+  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
+  std::string output;
+  int retVal = 1;
+  bool res = cmSystemTools::RunSingleCommand(command.c_str(), &output, &retVal, 0,
+                                             this->GeneratorVerbose, 0);
+  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
+    << std::endl);
+  if ( !res || retVal )
+    {
+    cmGeneratedFileStream ofs(tmpFile.c_str());
+    ofs << "# Run command: " << command << std::endl
+      << "# Output:" << std::endl
+      << output.c_str() << std::endl;
+    cmCPackLogger(cmCPackLog::LOG_ERROR,
+      "Problem running ProductBuild command: " << command
+      << std::endl << "Please check " << tmpFile.c_str() << " for errors"
+      << std::endl);
+    return false;
+    }
+  // sometimes the command finishes but the directory is not yet
+  // created, so try 10 times to see if it shows up
+  int tries = 10;
+  while(tries > 0 &&
+        !cmSystemTools::FileExists(packageFile.c_str()))
+    {
+    cmSystemTools::Delay(500);
+    tries--;
+    }
+  if(!cmSystemTools::FileExists(packageFile.c_str()))
+    {
+    cmCPackLogger(
+      cmCPackLog::LOG_ERROR,
+      "Problem running ProductBuild command: " << command
+      << std::endl << "Package not created: " << packageFile
+      << std::endl);
+    return false;
+    }
+
+  return true;
+}
+
+//----------------------------------------------------------------------
+std::string
+cmCPackProductBuildGenerator::GetPackageName(const cmCPackComponent& component)
+{
+  if (component.ArchiveFile.empty())
+    {
+    std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
+    packagesDir += ".dummy";
+    cmOStringStream out;
+    out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir)
+        << "-" << component.Name << ".pkg";
+    return out.str();
+    }
+  else
+    {
+    return component.ArchiveFile + ".pkg";
+    }
+}
+
+//----------------------------------------------------------------------
+bool
+cmCPackProductBuildGenerator::
+GenerateComponentPackage(const std::string& packageFile,
+                         const std::string& packageDir,
+                         const cmCPackComponent* component)
+{
+  cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+                "-   Building component package: " <<
+                packageFile << std::endl);
+
+  // The command that will be used to run ProductBuild
+  cmOStringStream pkgCmd;
+
+  std::string pkgId = "com.";
+  pkgId += this->GetOption("CPACK_PACKAGE_VENDOR");
+  pkgId += '.';
+  pkgId += this->GetOption("CPACK_PACKAGE_NAME");
+  if(component)
+    {
+    pkgId += '.';
+    pkgId += component->Name;
+    }
+
+  pkgCmd << "pkgbuild"
+         << " --root \"" << packageDir << "\""
+         << " --identifier \"" << pkgId << "\""
+         << " \"" << packageFile << "\"";
+
+  // Run ProductBuild
+  return RunProductBuild(pkgCmd.str(), packageFile);
+}
+
diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h
new file mode 100644
index 0000000..5de5d4c
--- /dev/null
+++ b/Source/CPack/cmCPackProductBuildGenerator.h
@@ -0,0 +1,64 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc.
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef cmCPackProductBuildGenerator_h
+#define cmCPackProductBuildGenerator_h
+
+
+#include "cmCPackGenerator.h"
+
+class cmCPackComponent;
+
+/** \class cmCPackProductBuildGenerator
+ * \brief A generator for ProductBuild files
+ *
+ */
+class cmCPackProductBuildGenerator : public cmCPackGenerator
+{
+public:
+  cmCPackTypeMacro(cmCPackProductBuildGenerator, cmCPackGenerator);
+
+  /**
+   * Construct generator
+   */
+  cmCPackProductBuildGenerator();
+  virtual ~cmCPackProductBuildGenerator();
+
+  virtual bool SupportsComponentInstallation() const;
+
+protected:
+  virtual int InitializeInternal();
+  int PackageFiles();
+  virtual const char* GetOutputExtension() { return ".pkg"; }
+  virtual const char* GetOutputPostfix() { return "darwin"; }
+
+  // Run ProductBuild with the given command line, which will (if
+  // successful) produce the given package file. Returns true if
+  // ProductBuild succeeds, false otherwise.
+  bool RunProductBuild(const std::string& command, const std::string& packageFile);
+
+  // Retrieve the name of package file that will be generated for this
+  // component. The name is just the file name with extension, and
+  // does not include the subdirectory.
+  std::string GetPackageName(const cmCPackComponent& component);
+
+  // Generate a package in the file packageFile for the given
+  // component.  All of the files within this component are stored in
+  // the directory packageDir. Returns true if successful, false
+  // otherwise.
+  bool GenerateComponentPackage(const std::string& packageFile,
+                                const std::string& packageDir,
+                                const cmCPackComponent* component);
+
+};
+
+#endif
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 33c18ce..8124aea 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -933,6 +933,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
     list(APPEND GENLST "ZIP")
     if(APPLE)
       list(APPEND GENLST "DragNDrop")
+      list(APPEND GENLST "ProductBuild")
     endif()
     if (NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
       list(FIND ACTIVE_CPACK_GENERATORS "RPM" RPM_ACTIVE)
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to