cmCPackRPMGenerator.cxx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 "cmCPackRPMGenerator.h"
  11. #include "cmCPackLog.h"
  12. #include "cmSystemTools.h"
  13. //----------------------------------------------------------------------
  14. cmCPackRPMGenerator::cmCPackRPMGenerator()
  15. {
  16. }
  17. //----------------------------------------------------------------------
  18. cmCPackRPMGenerator::~cmCPackRPMGenerator()
  19. {
  20. }
  21. //----------------------------------------------------------------------
  22. int cmCPackRPMGenerator::InitializeInternal()
  23. {
  24. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  25. if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR")))
  26. {
  27. this->SetOption("CPACK_SET_DESTDIR", "I_ON");
  28. }
  29. return this->Superclass::InitializeInternal();
  30. }
  31. //----------------------------------------------------------------------
  32. int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
  33. {
  34. int retval = 1;
  35. /* Reset package file name list it will be populated during the
  36. * component packaging run*/
  37. packageFileNames.clear();
  38. std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
  39. // The default behavior is to have one package by component group
  40. // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
  41. if (!ignoreGroup)
  42. {
  43. std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
  44. for (compGIt=this->ComponentGroups.begin();
  45. compGIt!=this->ComponentGroups.end(); ++compGIt)
  46. {
  47. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
  48. << compGIt->first
  49. << std::endl);
  50. // Begin the archive for this group
  51. std::string localToplevel(initialTopLevel);
  52. std::string packageFileName(
  53. cmSystemTools::GetParentDirectory(toplevel.c_str())
  54. );
  55. std::string outputFileName(
  56. std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
  57. +"-"+compGIt->first + this->GetOutputExtension()
  58. );
  59. localToplevel += "/"+ compGIt->first;
  60. /* replace the TEMP DIRECTORY with the component one */
  61. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  62. packageFileName += "/"+ outputFileName;
  63. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  64. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  65. /* replace the TEMPORARY package file name */
  66. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  67. packageFileName.c_str());
  68. // Tell CPackRPM.cmake the name of the component GROUP.
  69. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compGIt->first.c_str());
  70. if (!this->ReadListFile("CPackRPM.cmake"))
  71. {
  72. cmCPackLogger(cmCPackLog::LOG_ERROR,
  73. "Error while execution CPackRPM.cmake" << std::endl);
  74. retval = 0;
  75. }
  76. // add the generated package to package file names list
  77. packageFileNames.push_back(packageFileName);
  78. }
  79. }
  80. // CPACK_COMPONENTS_IGNORE_GROUPS is set
  81. // We build 1 package per component
  82. else
  83. {
  84. std::map<std::string, cmCPackComponent>::iterator compIt;
  85. for (compIt=this->Components.begin();
  86. compIt!=this->Components.end(); ++compIt )
  87. {
  88. std::string localToplevel(initialTopLevel);
  89. std::string packageFileName(
  90. cmSystemTools::GetParentDirectory(toplevel.c_str())
  91. );
  92. std::string outputFileName(
  93. std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")
  94. )
  95. +"-"+compIt->first + this->GetOutputExtension());
  96. localToplevel += "/"+ compIt->first;
  97. /* replace the TEMP DIRECTORY with the component one */
  98. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  99. packageFileName += "/"+ outputFileName;
  100. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  101. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  102. /* replace the TEMPORARY package file name */
  103. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  104. packageFileName.c_str());
  105. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compIt->first.c_str());
  106. if (!this->ReadListFile("CPackRPM.cmake"))
  107. {
  108. cmCPackLogger(cmCPackLog::LOG_ERROR,
  109. "Error while execution CPackRPM.cmake" << std::endl);
  110. retval = 0;
  111. }
  112. // add the generated package to package file names list
  113. packageFileNames.push_back(packageFileName);
  114. }
  115. }
  116. return retval;
  117. }
  118. //----------------------------------------------------------------------
  119. int cmCPackRPMGenerator::PackageComponentsAllInOne(bool allComponent)
  120. {
  121. int retval = 1;
  122. std::string compInstDirName;
  123. /* Reset package file name list it will be populated during the
  124. * component packaging run*/
  125. packageFileNames.clear();
  126. std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
  127. // all GROUP in one vs all COMPONENT in one
  128. if (allComponent)
  129. {
  130. compInstDirName = "ALL_COMPONENTS_IN_ONE";
  131. }
  132. else
  133. {
  134. compInstDirName = "ALL_GROUPS_IN_ONE";
  135. }
  136. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  137. "Packaging all groups in one package..."
  138. "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
  139. << std::endl);
  140. // The ALL GROUPS in ONE package case
  141. std::string localToplevel(initialTopLevel);
  142. std::string packageFileName(
  143. cmSystemTools::GetParentDirectory(toplevel.c_str())
  144. );
  145. std::string outputFileName(
  146. std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
  147. + this->GetOutputExtension()
  148. );
  149. // all GROUP in one vs all COMPONENT in one
  150. localToplevel += "/"+compInstDirName;
  151. /* replace the TEMP DIRECTORY with the component one */
  152. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  153. packageFileName += "/"+ outputFileName;
  154. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  155. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  156. /* replace the TEMPORARY package file name */
  157. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  158. packageFileName.c_str());
  159. // Tell CPackRPM.cmake the name of the component GROUP.
  160. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compInstDirName.c_str());
  161. if (!this->ReadListFile("CPackRPM.cmake"))
  162. {
  163. cmCPackLogger(cmCPackLog::LOG_ERROR,
  164. "Error while execution CPackRPM.cmake" << std::endl);
  165. retval = 0;
  166. }
  167. // add the generated package to package file names list
  168. packageFileNames.push_back(packageFileName);
  169. return retval;
  170. }
  171. //----------------------------------------------------------------------
  172. int cmCPackRPMGenerator::PackageFiles()
  173. {
  174. int retval = 1;
  175. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
  176. << toplevel << std::endl);
  177. /* Are we in the component packaging case */
  178. if (SupportsComponentInstallation()) {
  179. // CASE 1 : COMPONENT ALL-IN-ONE package
  180. // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested
  181. // then the package file is unique and should be open here.
  182. if (allComponentInOne ||
  183. (allGroupInOne && (!this->ComponentGroups.empty()))
  184. )
  185. {
  186. return PackageComponentsAllInOne(allComponentInOne);
  187. }
  188. // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
  189. // There will be 1 package for each component group
  190. // however one may require to ignore component group and
  191. // in this case you'll get 1 package for each component.
  192. else if ((!this->ComponentGroups.empty()) || (ignoreComponentGroup))
  193. {
  194. return PackageComponents(ignoreComponentGroup);
  195. }
  196. }
  197. // CASE 3 : NON COMPONENT package.
  198. else
  199. {
  200. if (!this->ReadListFile("CPackRPM.cmake"))
  201. {
  202. cmCPackLogger(cmCPackLog::LOG_ERROR,
  203. "Error while execution CPackRPM.cmake" << std::endl);
  204. retval = 0;
  205. }
  206. }
  207. if (!this->IsSet("RPMBUILD_EXECUTABLE"))
  208. {
  209. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl);
  210. retval = 0;
  211. }
  212. return retval;
  213. }
  214. bool cmCPackRPMGenerator::SupportsComponentInstallation() const
  215. {
  216. if (IsOn("CPACK_RPM_COMPONENT_INSTALL"))
  217. {
  218. return true;
  219. }
  220. else
  221. {
  222. return false;
  223. }
  224. }
  225. std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
  226. const std::string& componentName)
  227. {
  228. if (ignoreComponentGroup) {
  229. return componentName;
  230. }
  231. if (allComponentInOne) {
  232. return std::string("ALL_COMPONENTS_IN_ONE");
  233. }
  234. // We have to find the name of the COMPONENT GROUP
  235. // the current COMPONENT belongs to.
  236. std::string groupVar = "CPACK_COMPONENT_" +
  237. cmSystemTools::UpperCase(componentName) + "_GROUP";
  238. if (NULL != GetOption(groupVar.c_str()))
  239. {
  240. if (allGroupInOne)
  241. {
  242. return std::string("ALL_GROUPS_IN_ONE");
  243. }
  244. else
  245. {
  246. return std::string(GetOption(groupVar.c_str()));
  247. }
  248. }
  249. else
  250. {
  251. return componentName;
  252. }
  253. }