cmCPackIFWInstaller.cxx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCPackIFWInstaller.h"
  11. #include "cmCPackIFWGenerator.h"
  12. #include <CPack/cmCPackLog.h>
  13. #include <cmGeneratedFileStream.h>
  14. #include <cmXMLWriter.h>
  15. #ifdef cmCPackLogger
  16. #undef cmCPackLogger
  17. #endif
  18. #define cmCPackLogger(logType, msg) \
  19. do { \
  20. std::ostringstream cmCPackLog_msg; \
  21. cmCPackLog_msg << msg; \
  22. if (Generator) { \
  23. Generator->Logger->Log(logType, __FILE__, __LINE__, \
  24. cmCPackLog_msg.str().c_str()); \
  25. } \
  26. } while (0)
  27. cmCPackIFWInstaller::cmCPackIFWInstaller()
  28. : Generator(0)
  29. {
  30. }
  31. const char* cmCPackIFWInstaller::GetOption(const std::string& op) const
  32. {
  33. return Generator ? Generator->GetOption(op) : 0;
  34. }
  35. bool cmCPackIFWInstaller::IsOn(const std::string& op) const
  36. {
  37. return Generator ? Generator->IsOn(op) : false;
  38. }
  39. bool cmCPackIFWInstaller::IsVersionLess(const char* version)
  40. {
  41. return Generator ? Generator->IsVersionLess(version) : false;
  42. }
  43. bool cmCPackIFWInstaller::IsVersionGreater(const char* version)
  44. {
  45. return Generator ? Generator->IsVersionGreater(version) : false;
  46. }
  47. bool cmCPackIFWInstaller::IsVersionEqual(const char* version)
  48. {
  49. return Generator ? Generator->IsVersionEqual(version) : false;
  50. }
  51. void cmCPackIFWInstaller::ConfigureFromOptions()
  52. {
  53. // Name;
  54. if (const char* optIFW_PACKAGE_NAME =
  55. this->GetOption("CPACK_IFW_PACKAGE_NAME")) {
  56. Name = optIFW_PACKAGE_NAME;
  57. } else if (const char* optPACKAGE_NAME =
  58. this->GetOption("CPACK_PACKAGE_NAME")) {
  59. Name = optPACKAGE_NAME;
  60. } else {
  61. Name = "Your package";
  62. }
  63. // Title;
  64. if (const char* optIFW_PACKAGE_TITLE =
  65. GetOption("CPACK_IFW_PACKAGE_TITLE")) {
  66. Title = optIFW_PACKAGE_TITLE;
  67. } else if (const char* optPACKAGE_DESCRIPTION_SUMMARY =
  68. GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY")) {
  69. Title = optPACKAGE_DESCRIPTION_SUMMARY;
  70. } else {
  71. Title = "Your package description";
  72. }
  73. // Version;
  74. if (const char* option = GetOption("CPACK_PACKAGE_VERSION")) {
  75. Version = option;
  76. } else {
  77. Version = "1.0.0";
  78. }
  79. // Publisher
  80. if (const char* optIFW_PACKAGE_PUBLISHER =
  81. GetOption("CPACK_IFW_PACKAGE_PUBLISHER")) {
  82. Publisher = optIFW_PACKAGE_PUBLISHER;
  83. } else if (const char* optPACKAGE_VENDOR =
  84. GetOption("CPACK_PACKAGE_VENDOR")) {
  85. Publisher = optPACKAGE_VENDOR;
  86. }
  87. // ProductUrl
  88. if (const char* option = GetOption("CPACK_IFW_PRODUCT_URL")) {
  89. ProductUrl = option;
  90. }
  91. // ApplicationIcon
  92. if (const char* option = GetOption("CPACK_IFW_PACKAGE_ICON")) {
  93. if (cmSystemTools::FileExists(option)) {
  94. InstallerApplicationIcon = option;
  95. } else {
  96. // TODO: implement warning
  97. }
  98. }
  99. // WindowIcon
  100. if (const char* option = GetOption("CPACK_IFW_PACKAGE_WINDOW_ICON")) {
  101. if (cmSystemTools::FileExists(option)) {
  102. InstallerWindowIcon = option;
  103. } else {
  104. // TODO: implement warning
  105. }
  106. }
  107. // Logo
  108. if (const char* option = GetOption("CPACK_IFW_PACKAGE_LOGO")) {
  109. if (cmSystemTools::FileExists(option)) {
  110. Logo = option;
  111. } else {
  112. // TODO: implement warning
  113. }
  114. }
  115. // Start menu
  116. if (const char* optIFW_START_MENU_DIR =
  117. this->GetOption("CPACK_IFW_PACKAGE_START_MENU_DIRECTORY")) {
  118. StartMenuDir = optIFW_START_MENU_DIR;
  119. } else {
  120. StartMenuDir = Name;
  121. }
  122. // Default target directory for installation
  123. if (const char* optIFW_TARGET_DIRECTORY =
  124. GetOption("CPACK_IFW_TARGET_DIRECTORY")) {
  125. TargetDir = optIFW_TARGET_DIRECTORY;
  126. } else if (const char* optPACKAGE_INSTALL_DIRECTORY =
  127. GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) {
  128. TargetDir = "@ApplicationsDir@/";
  129. TargetDir += optPACKAGE_INSTALL_DIRECTORY;
  130. } else {
  131. TargetDir = "@RootDir@/usr/local";
  132. }
  133. // Default target directory for installation with administrator rights
  134. if (const char* option = GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY")) {
  135. AdminTargetDir = option;
  136. }
  137. // Maintenance tool
  138. if (const char* optIFW_MAINTENANCE_TOOL =
  139. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME")) {
  140. MaintenanceToolName = optIFW_MAINTENANCE_TOOL;
  141. }
  142. // Maintenance tool ini file
  143. if (const char* optIFW_MAINTENANCE_TOOL_INI =
  144. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE")) {
  145. MaintenanceToolIniFile = optIFW_MAINTENANCE_TOOL_INI;
  146. }
  147. // Allow non-ASCII characters
  148. if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) {
  149. if (IsOn("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) {
  150. AllowNonAsciiCharacters = "true";
  151. } else {
  152. AllowNonAsciiCharacters = "false";
  153. }
  154. }
  155. // Space in path
  156. if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) {
  157. if (IsOn("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) {
  158. AllowSpaceInPath = "true";
  159. } else {
  160. AllowSpaceInPath = "false";
  161. }
  162. }
  163. // Control script
  164. if (const char* optIFW_CONTROL_SCRIPT =
  165. this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT")) {
  166. ControlScript = optIFW_CONTROL_SCRIPT;
  167. }
  168. }
  169. void cmCPackIFWInstaller::GenerateInstallerFile()
  170. {
  171. // Lazy directory initialization
  172. if (Directory.empty() && Generator) {
  173. Directory = Generator->toplevel;
  174. }
  175. // Output stream
  176. cmGeneratedFileStream fout((Directory + "/config/config.xml").data());
  177. cmXMLWriter xout(fout);
  178. xout.StartDocument();
  179. WriteGeneratedByToStrim(xout);
  180. xout.StartElement("Installer");
  181. xout.Element("Name", Name);
  182. xout.Element("Version", Version);
  183. xout.Element("Title", Title);
  184. if (!Publisher.empty()) {
  185. xout.Element("Publisher", Publisher);
  186. }
  187. if (!ProductUrl.empty()) {
  188. xout.Element("ProductUrl", ProductUrl);
  189. }
  190. // ApplicationIcon
  191. if (!InstallerApplicationIcon.empty()) {
  192. std::string name =
  193. cmSystemTools::GetFilenameName(InstallerApplicationIcon);
  194. std::string path = Directory + "/config/" + name;
  195. name = cmSystemTools::GetFilenameWithoutExtension(name);
  196. cmsys::SystemTools::CopyFileIfDifferent(InstallerApplicationIcon.data(),
  197. path.data());
  198. xout.Element("InstallerApplicationIcon", name);
  199. }
  200. // WindowIcon
  201. if (!InstallerWindowIcon.empty()) {
  202. std::string name = cmSystemTools::GetFilenameName(InstallerWindowIcon);
  203. std::string path = Directory + "/config/" + name;
  204. cmsys::SystemTools::CopyFileIfDifferent(InstallerWindowIcon.data(),
  205. path.data());
  206. xout.Element("InstallerWindowIcon", name);
  207. }
  208. // Logo
  209. if (!Logo.empty()) {
  210. std::string name = cmSystemTools::GetFilenameName(Logo);
  211. std::string path = Directory + "/config/" + name;
  212. cmsys::SystemTools::CopyFileIfDifferent(Logo.data(), path.data());
  213. xout.Element("Logo", name);
  214. }
  215. // Start menu
  216. if (!IsVersionLess("2.0")) {
  217. xout.Element("StartMenuDir", StartMenuDir);
  218. }
  219. // Target dir
  220. if (!TargetDir.empty()) {
  221. xout.Element("TargetDir", TargetDir);
  222. }
  223. // Admin target dir
  224. if (!AdminTargetDir.empty()) {
  225. xout.Element("AdminTargetDir", AdminTargetDir);
  226. }
  227. // Remote repositories
  228. if (!RemoteRepositories.empty()) {
  229. xout.StartElement("RemoteRepositories");
  230. for (RepositoriesVector::iterator rit = RemoteRepositories.begin();
  231. rit != RemoteRepositories.end(); ++rit) {
  232. (*rit)->WriteRepositoryConfig(xout);
  233. }
  234. xout.EndElement();
  235. }
  236. // Maintenance tool
  237. if (!IsVersionLess("2.0") && !MaintenanceToolName.empty()) {
  238. xout.Element("MaintenanceToolName", MaintenanceToolName);
  239. }
  240. // Maintenance tool ini file
  241. if (!IsVersionLess("2.0") && !MaintenanceToolIniFile.empty()) {
  242. xout.Element("MaintenanceToolIniFile", MaintenanceToolIniFile);
  243. }
  244. // Different allows
  245. if (IsVersionLess("2.0")) {
  246. // CPack IFW default policy
  247. xout.Comment("CPack IFW default policy for QtIFW less 2.0");
  248. xout.Element("AllowNonAsciiCharacters", "true");
  249. xout.Element("AllowSpaceInPath", "true");
  250. } else {
  251. if (!AllowNonAsciiCharacters.empty()) {
  252. xout.Element("AllowNonAsciiCharacters", AllowNonAsciiCharacters);
  253. }
  254. if (!AllowSpaceInPath.empty()) {
  255. xout.Element("AllowSpaceInPath", AllowSpaceInPath);
  256. }
  257. }
  258. // Control script (copy to config dir)
  259. if (!IsVersionLess("2.0") && !ControlScript.empty()) {
  260. std::string name = cmSystemTools::GetFilenameName(ControlScript);
  261. std::string path = Directory + "/config/" + name;
  262. cmsys::SystemTools::CopyFileIfDifferent(ControlScript.data(), path.data());
  263. xout.Element("ControlScript", name);
  264. }
  265. xout.EndElement();
  266. xout.EndDocument();
  267. }
  268. void cmCPackIFWInstaller::GeneratePackageFiles()
  269. {
  270. if (Packages.empty() || Generator->IsOnePackage()) {
  271. // Generate default package
  272. cmCPackIFWPackage package;
  273. package.Generator = Generator;
  274. package.Installer = this;
  275. // Check package group
  276. if (const char* option = GetOption("CPACK_IFW_PACKAGE_GROUP")) {
  277. package.ConfigureFromGroup(option);
  278. package.ForcedInstallation = "true";
  279. } else {
  280. package.ConfigureFromOptions();
  281. }
  282. package.GeneratePackageFile();
  283. return;
  284. }
  285. // Generate packages meta information
  286. for (PackagesMap::iterator pit = Packages.begin(); pit != Packages.end();
  287. ++pit) {
  288. cmCPackIFWPackage* package = pit->second;
  289. package->GeneratePackageFile();
  290. }
  291. }
  292. void cmCPackIFWInstaller::WriteGeneratedByToStrim(cmXMLWriter& xout)
  293. {
  294. if (Generator) {
  295. Generator->WriteGeneratedByToStrim(xout);
  296. }
  297. }