Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CPack / cmCPackBundleGenerator.cxx
blob996393df28d82ad1531e9bebaa465e0183c2dd9e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPackBundleGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-02-19 15:39:08 $
7 Version: $Revision: 1.10 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "cmCPackBundleGenerator.h"
19 #include "cmCPackLog.h"
20 #include "cmSystemTools.h"
22 #include <cmsys/RegularExpression.hxx>
24 //----------------------------------------------------------------------
25 cmCPackBundleGenerator::cmCPackBundleGenerator()
29 //----------------------------------------------------------------------
30 cmCPackBundleGenerator::~cmCPackBundleGenerator()
34 //----------------------------------------------------------------------
35 int cmCPackBundleGenerator::InitializeInternal()
37 const char* name = this->GetOption("CPACK_BUNDLE_NAME");
38 if(0 == name)
40 cmCPackLogger(cmCPackLog::LOG_ERROR,
41 "CPACK_BUNDLE_NAME must be set to use the Bundle generator."
42 << std::endl);
44 return 0;
47 return this->Superclass::InitializeInternal();
50 //----------------------------------------------------------------------
51 const char* cmCPackBundleGenerator::GetPackagingInstallPrefix()
53 this->InstallPrefix = "/";
54 this->InstallPrefix += this->GetOption("CPACK_BUNDLE_NAME");
55 this->InstallPrefix += ".app/Contents/Resources";
57 return this->InstallPrefix.c_str();
60 //----------------------------------------------------------------------
61 int cmCPackBundleGenerator::CompressFiles(const char* outFileName,
62 const char* toplevel, const std::vector<std::string>& files)
64 (void) files;
66 // Get required arguments ...
67 const std::string cpack_bundle_name = this->GetOption("CPACK_BUNDLE_NAME")
68 ? this->GetOption("CPACK_BUNDLE_NAME") : "";
69 if(cpack_bundle_name.empty())
71 cmCPackLogger(cmCPackLog::LOG_ERROR,
72 "CPACK_BUNDLE_NAME must be set."
73 << std::endl);
75 return 0;
78 const std::string cpack_bundle_plist = this->GetOption("CPACK_BUNDLE_PLIST")
79 ? this->GetOption("CPACK_BUNDLE_PLIST") : "";
80 if(cpack_bundle_plist.empty())
82 cmCPackLogger(cmCPackLog::LOG_ERROR,
83 "CPACK_BUNDLE_PLIST must be set."
84 << std::endl);
86 return 0;
89 const std::string cpack_bundle_icon = this->GetOption("CPACK_BUNDLE_ICON")
90 ? this->GetOption("CPACK_BUNDLE_ICON") : "";
91 if(cpack_bundle_icon.empty())
93 cmCPackLogger(cmCPackLog::LOG_ERROR,
94 "CPACK_BUNDLE_ICON must be set."
95 << std::endl);
97 return 0;
100 // Get optional arguments ...
101 const std::string cpack_bundle_startup_command =
102 this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND")
103 ? this->GetOption("CPACK_BUNDLE_STARTUP_COMMAND") : "";
105 // The staging directory contains everything that will end-up inside the
106 // final disk image ...
107 cmOStringStream staging;
108 staging << toplevel;
110 cmOStringStream contents;
111 contents << staging.str() << "/" << cpack_bundle_name
112 << ".app/" << "Contents";
114 cmOStringStream application;
115 application << contents.str() << "/" << "MacOS";
117 cmOStringStream resources;
118 resources << contents.str() << "/" << "Resources";
120 // Install a required, user-provided bundle metadata file ...
121 cmOStringStream plist_source;
122 plist_source << cpack_bundle_plist;
124 cmOStringStream plist_target;
125 plist_target << contents.str() << "/" << "Info.plist";
127 if(!this->CopyFile(plist_source, plist_target))
129 cmCPackLogger(cmCPackLog::LOG_ERROR,
130 "Error copying plist. Check the value of CPACK_BUNDLE_PLIST."
131 << std::endl);
133 return 0;
136 // Install a user-provided bundle icon ...
137 cmOStringStream icon_source;
138 icon_source << cpack_bundle_icon;
140 cmOStringStream icon_target;
141 icon_target << resources.str() << "/" << cpack_bundle_name << ".icns";
143 if(!this->CopyFile(icon_source, icon_target))
145 cmCPackLogger(cmCPackLog::LOG_ERROR,
146 "Error copying bundle icon. Check the value of CPACK_BUNDLE_ICON."
147 << std::endl);
149 return 0;
152 // Optionally a user-provided startup command (could be an
153 // executable or a script) ...
154 if(!cpack_bundle_startup_command.empty())
156 cmOStringStream command_source;
157 command_source << cpack_bundle_startup_command;
159 cmOStringStream command_target;
160 command_target << application.str() << "/" << cpack_bundle_name;
162 if(!this->CopyFile(command_source, command_target))
164 cmCPackLogger(cmCPackLog::LOG_ERROR,
165 "Error copying startup command. "
166 " Check the value of CPACK_BUNDLE_STARTUP_COMMAND."
167 << std::endl);
169 return 0;
172 cmSystemTools::SetPermissions(command_target.str().c_str(), 0777);
175 return this->CreateDMG(toplevel, outFileName);