1
0

cmCPackExtGenerator.cxx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCPackExtGenerator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmCPackComponentGroup.h"
  6. #include "cmCPackLog.h"
  7. #include "cmSystemTools.h"
  8. #include "cm_jsoncpp_value.h"
  9. #include "cm_jsoncpp_writer.h"
  10. #include "cmsys/FStream.hxx"
  11. #include <utility>
  12. #include <vector>
  13. int cmCPackExtGenerator::InitializeInternal()
  14. {
  15. this->SetOption("CPACK_EXT_KNOWN_VERSIONS", "1.0");
  16. if (!this->ReadListFile("Internal/CPack/CPackExt.cmake")) {
  17. cmCPackLogger(cmCPackLog::LOG_ERROR,
  18. "Error while executing CPackExt.cmake" << std::endl);
  19. return 0;
  20. }
  21. std::string major = this->GetOption("CPACK_EXT_SELECTED_MAJOR");
  22. if (major == "1") {
  23. this->Generator = cm::make_unique<cmCPackExtVersion1Generator>(this);
  24. }
  25. return this->Superclass::InitializeInternal();
  26. }
  27. int cmCPackExtGenerator::PackageFiles()
  28. {
  29. Json::StreamWriterBuilder builder;
  30. builder["indentation"] = " ";
  31. std::string filename = "package.json";
  32. if (!this->packageFileNames.empty()) {
  33. filename = this->packageFileNames[0];
  34. }
  35. cmsys::ofstream fout(filename.c_str());
  36. std::unique_ptr<Json::StreamWriter> jout(builder.newStreamWriter());
  37. Json::Value root(Json::objectValue);
  38. if (!this->Generator->WriteToJSON(root)) {
  39. return 0;
  40. }
  41. if (jout->write(root, &fout)) {
  42. return 0;
  43. }
  44. return 1;
  45. }
  46. bool cmCPackExtGenerator::SupportsComponentInstallation() const
  47. {
  48. return true;
  49. }
  50. int cmCPackExtGenerator::InstallProjectViaInstallCommands(
  51. bool setDestDir, const std::string& tempInstallDirectory)
  52. {
  53. (void)setDestDir;
  54. (void)tempInstallDirectory;
  55. return 1;
  56. }
  57. int cmCPackExtGenerator::InstallProjectViaInstallScript(
  58. bool setDestDir, const std::string& tempInstallDirectory)
  59. {
  60. (void)setDestDir;
  61. (void)tempInstallDirectory;
  62. return 1;
  63. }
  64. int cmCPackExtGenerator::InstallProjectViaInstalledDirectories(
  65. bool setDestDir, const std::string& tempInstallDirectory,
  66. const mode_t* default_dir_mode)
  67. {
  68. (void)setDestDir;
  69. (void)tempInstallDirectory;
  70. (void)default_dir_mode;
  71. return 1;
  72. }
  73. int cmCPackExtGenerator::RunPreinstallTarget(
  74. const std::string& installProjectName, const std::string& installDirectory,
  75. cmGlobalGenerator* globalGenerator, const std::string& buildConfig)
  76. {
  77. (void)installProjectName;
  78. (void)installDirectory;
  79. (void)globalGenerator;
  80. (void)buildConfig;
  81. return 1;
  82. }
  83. int cmCPackExtGenerator::InstallCMakeProject(
  84. bool setDestDir, const std::string& installDirectory,
  85. const std::string& baseTempInstallDirectory, const mode_t* default_dir_mode,
  86. const std::string& component, bool componentInstall,
  87. const std::string& installSubDirectory, const std::string& buildConfig,
  88. std::string& absoluteDestFiles)
  89. {
  90. (void)setDestDir;
  91. (void)installDirectory;
  92. (void)baseTempInstallDirectory;
  93. (void)default_dir_mode;
  94. (void)component;
  95. (void)componentInstall;
  96. (void)installSubDirectory;
  97. (void)buildConfig;
  98. (void)absoluteDestFiles;
  99. return 1;
  100. }
  101. cmCPackExtGenerator::cmCPackExtVersionGenerator::cmCPackExtVersionGenerator(
  102. cmCPackExtGenerator* parent)
  103. : Parent(parent)
  104. {
  105. }
  106. int cmCPackExtGenerator::cmCPackExtVersionGenerator::WriteVersion(
  107. Json::Value& root)
  108. {
  109. root["formatVersionMajor"] = this->GetVersionMajor();
  110. root["formatVersionMinor"] = this->GetVersionMinor();
  111. return 1;
  112. }
  113. int cmCPackExtGenerator::cmCPackExtVersionGenerator::WriteToJSON(
  114. Json::Value& root)
  115. {
  116. if (!this->WriteVersion(root)) {
  117. return 0;
  118. }
  119. const char* packageName = this->Parent->GetOption("CPACK_PACKAGE_NAME");
  120. if (packageName) {
  121. root["packageName"] = packageName;
  122. }
  123. const char* packageVersion =
  124. this->Parent->GetOption("CPACK_PACKAGE_VERSION");
  125. if (packageVersion) {
  126. root["packageVersion"] = packageVersion;
  127. }
  128. const char* packageDescriptionFile =
  129. this->Parent->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  130. if (packageDescriptionFile) {
  131. root["packageDescriptionFile"] = packageDescriptionFile;
  132. }
  133. const char* packageDescriptionSummary =
  134. this->Parent->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY");
  135. if (packageDescriptionSummary) {
  136. root["packageDescriptionSummary"] = packageDescriptionSummary;
  137. }
  138. const char* buildConfigCstr = this->Parent->GetOption("CPACK_BUILD_CONFIG");
  139. if (buildConfigCstr) {
  140. root["buildConfig"] = buildConfigCstr;
  141. }
  142. const char* defaultDirectoryPermissions =
  143. this->Parent->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
  144. if (defaultDirectoryPermissions && *defaultDirectoryPermissions) {
  145. root["defaultDirectoryPermissions"] = defaultDirectoryPermissions;
  146. }
  147. if (cmSystemTools::IsInternallyOn(
  148. this->Parent->GetOption("CPACK_SET_DESTDIR"))) {
  149. root["setDestdir"] = true;
  150. root["packagingInstallPrefix"] =
  151. this->Parent->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  152. } else {
  153. root["setDestdir"] = false;
  154. }
  155. root["stripFiles"] =
  156. !cmSystemTools::IsOff(this->Parent->GetOption("CPACK_STRIP_FILES"));
  157. root["warnOnAbsoluteInstallDestination"] =
  158. this->Parent->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION");
  159. root["errorOnAbsoluteInstallDestination"] =
  160. this->Parent->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION");
  161. Json::Value& projects = root["projects"] = Json::Value(Json::arrayValue);
  162. for (auto& project : this->Parent->CMakeProjects) {
  163. Json::Value jsonProject(Json::objectValue);
  164. jsonProject["projectName"] = project.ProjectName;
  165. jsonProject["component"] = project.Component;
  166. jsonProject["directory"] = project.Directory;
  167. jsonProject["subDirectory"] = project.SubDirectory;
  168. Json::Value& installationTypes = jsonProject["installationTypes"] =
  169. Json::Value(Json::arrayValue);
  170. for (auto& installationType : project.InstallationTypes) {
  171. installationTypes.append(installationType->Name);
  172. }
  173. Json::Value& components = jsonProject["components"] =
  174. Json::Value(Json::arrayValue);
  175. for (auto& component : project.Components) {
  176. components.append(component->Name);
  177. }
  178. projects.append(jsonProject);
  179. }
  180. Json::Value& installationTypes = root["installationTypes"] =
  181. Json::Value(Json::objectValue);
  182. for (auto& installationType : this->Parent->InstallationTypes) {
  183. Json::Value& jsonInstallationType =
  184. installationTypes[installationType.first] =
  185. Json::Value(Json::objectValue);
  186. jsonInstallationType["name"] = installationType.second.Name;
  187. jsonInstallationType["displayName"] = installationType.second.DisplayName;
  188. jsonInstallationType["index"] = installationType.second.Index;
  189. }
  190. Json::Value& components = root["components"] =
  191. Json::Value(Json::objectValue);
  192. for (auto& component : this->Parent->Components) {
  193. Json::Value& jsonComponent = components[component.first] =
  194. Json::Value(Json::objectValue);
  195. jsonComponent["name"] = component.second.Name;
  196. jsonComponent["displayName"] = component.second.DisplayName;
  197. if (component.second.Group) {
  198. jsonComponent["group"] = component.second.Group->Name;
  199. }
  200. jsonComponent["isRequired"] = component.second.IsRequired;
  201. jsonComponent["isHidden"] = component.second.IsHidden;
  202. jsonComponent["isDisabledByDefault"] =
  203. component.second.IsDisabledByDefault;
  204. jsonComponent["isDownloaded"] = component.second.IsDownloaded;
  205. jsonComponent["description"] = component.second.Description;
  206. jsonComponent["archiveFile"] = component.second.ArchiveFile;
  207. Json::Value& cmpInstallationTypes = jsonComponent["installationTypes"] =
  208. Json::Value(Json::arrayValue);
  209. for (auto& installationType : component.second.InstallationTypes) {
  210. cmpInstallationTypes.append(installationType->Name);
  211. }
  212. Json::Value& dependencies = jsonComponent["dependencies"] =
  213. Json::Value(Json::arrayValue);
  214. for (auto& dep : component.second.Dependencies) {
  215. dependencies.append(dep->Name);
  216. }
  217. }
  218. Json::Value& groups = root["componentGroups"] =
  219. Json::Value(Json::objectValue);
  220. for (auto& group : this->Parent->ComponentGroups) {
  221. Json::Value& jsonGroup = groups[group.first] =
  222. Json::Value(Json::objectValue);
  223. jsonGroup["name"] = group.second.Name;
  224. jsonGroup["displayName"] = group.second.DisplayName;
  225. jsonGroup["description"] = group.second.Description;
  226. jsonGroup["isBold"] = group.second.IsBold;
  227. jsonGroup["isExpandedByDefault"] = group.second.IsExpandedByDefault;
  228. if (group.second.ParentGroup) {
  229. jsonGroup["parentGroup"] = group.second.ParentGroup->Name;
  230. }
  231. Json::Value& subgroups = jsonGroup["subgroups"] =
  232. Json::Value(Json::arrayValue);
  233. for (auto& subgroup : group.second.Subgroups) {
  234. subgroups.append(subgroup->Name);
  235. }
  236. Json::Value& groupComponents = jsonGroup["components"] =
  237. Json::Value(Json::arrayValue);
  238. for (auto& component : group.second.Components) {
  239. groupComponents.append(component->Name);
  240. }
  241. }
  242. return 1;
  243. }