cmCPackIFWInstaller.cxx 10 KB

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