cmCPackRPMGenerator.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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::PackageFiles()
  33. {
  34. int retval = 1;
  35. /* Digest Component grouping specification */
  36. retval = PrepareGroupingKind();
  37. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
  38. << toplevel << std::endl);
  39. /* Are we in the component packaging case */
  40. if (SupportsComponentInstallation() & (!this->ComponentGroups.empty()))
  41. {
  42. /* Reset package file name list it will be populated during the
  43. * component packaging run*/
  44. packageFileNames.clear();
  45. std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
  46. /* One Package per component CASE */
  47. /* Iterate over components */
  48. std::map<std::string, cmCPackComponent>::iterator compIt;
  49. for (compIt=this->Components.begin();
  50. compIt!=this->Components.end(); ++compIt )
  51. {
  52. std::string localToplevel(initialTopLevel);
  53. std::string packageFileName(
  54. cmSystemTools::GetParentDirectory(toplevel.c_str())
  55. );
  56. std::string outputFileName(
  57. std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")
  58. )
  59. +"-"+compIt->first + this->GetOutputExtension());
  60. localToplevel += "/"+ compIt->first;
  61. /* replace the TEMP DIRECTORY with the component one */
  62. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  63. packageFileName += "/"+ outputFileName;
  64. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  65. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  66. /* replace the TEMPORARY package file name */
  67. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  68. packageFileName.c_str());
  69. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compIt->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. /* This is the non component case */
  81. else
  82. {
  83. if (!this->ReadListFile("CPackRPM.cmake"))
  84. {
  85. cmCPackLogger(cmCPackLog::LOG_ERROR,
  86. "Error while execution CPackRPM.cmake" << std::endl);
  87. retval = 0;
  88. }
  89. }
  90. if (!this->IsSet("RPMBUILD_EXECUTABLE"))
  91. {
  92. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl);
  93. retval = 0;
  94. }
  95. return retval;
  96. }
  97. bool cmCPackRPMGenerator::SupportsComponentInstallation() const
  98. {
  99. if (IsOn("CPACK_RPM_COMPONENT_INSTALL"))
  100. {
  101. return true;
  102. }
  103. else
  104. {
  105. return false;
  106. }
  107. }