cmCPackIFWCommon.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "cmCPackIFWCommon.h"
  4. #include <cstddef> // IWYU pragma: keep
  5. #include <sstream>
  6. #include <utility>
  7. #include <vector>
  8. #include "cmCPackGenerator.h"
  9. #include "cmCPackIFWGenerator.h"
  10. #include "cmCPackLog.h" // IWYU pragma: keep
  11. #include "cmStringAlgorithms.h"
  12. #include "cmSystemTools.h"
  13. #include "cmTimestamp.h"
  14. #include "cmVersionConfig.h"
  15. #include "cmXMLWriter.h"
  16. cmCPackIFWCommon::cmCPackIFWCommon()
  17. : Generator(nullptr)
  18. {
  19. }
  20. cmValue cmCPackIFWCommon::GetOption(const std::string& op) const
  21. {
  22. return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op)
  23. : nullptr;
  24. }
  25. bool cmCPackIFWCommon::IsOn(const std::string& op) const
  26. {
  27. return this->Generator ? this->Generator->cmCPackGenerator::IsOn(op) : false;
  28. }
  29. bool cmCPackIFWCommon::IsSetToOff(const std::string& op) const
  30. {
  31. return this->Generator ? this->Generator->cmCPackGenerator::IsSetToOff(op)
  32. : false;
  33. }
  34. bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const
  35. {
  36. return this->Generator ? this->Generator->cmCPackGenerator::IsSetToEmpty(op)
  37. : false;
  38. }
  39. bool cmCPackIFWCommon::IsVersionLess(const char* version) const
  40. {
  41. if (!this->Generator) {
  42. return false;
  43. }
  44. return cmSystemTools::VersionCompare(
  45. cmSystemTools::OP_LESS, this->Generator->FrameworkVersion, version);
  46. }
  47. bool cmCPackIFWCommon::IsVersionGreater(const char* version) const
  48. {
  49. if (!this->Generator) {
  50. return false;
  51. }
  52. return cmSystemTools::VersionCompare(
  53. cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion, version);
  54. }
  55. bool cmCPackIFWCommon::IsVersionEqual(const char* version) const
  56. {
  57. if (!this->Generator) {
  58. return false;
  59. }
  60. return cmSystemTools::VersionCompare(
  61. cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion, version);
  62. }
  63. void cmCPackIFWCommon::ExpandListArgument(
  64. const std::string& arg, std::map<std::string, std::string>& argsOut)
  65. {
  66. std::vector<std::string> args = cmExpandedList(arg, false);
  67. if (args.empty()) {
  68. return;
  69. }
  70. std::size_t i = 0;
  71. std::size_t c = args.size();
  72. if (c % 2) {
  73. argsOut[""] = args[i];
  74. ++i;
  75. }
  76. --c;
  77. for (; i < c; i += 2) {
  78. argsOut[args[i]] = args[i + 1];
  79. }
  80. }
  81. void cmCPackIFWCommon::ExpandListArgument(
  82. const std::string& arg, std::multimap<std::string, std::string>& argsOut)
  83. {
  84. std::vector<std::string> args = cmExpandedList(arg, false);
  85. if (args.empty()) {
  86. return;
  87. }
  88. std::size_t i = 0;
  89. std::size_t c = args.size();
  90. if (c % 2) {
  91. argsOut.insert(std::pair<std::string, std::string>("", args[i]));
  92. ++i;
  93. }
  94. --c;
  95. for (; i < c; i += 2) {
  96. argsOut.insert(std::pair<std::string, std::string>(args[i], args[i + 1]));
  97. }
  98. }
  99. void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout) const
  100. {
  101. if (!this->Generator) {
  102. return;
  103. }
  104. std::ostringstream comment;
  105. comment << "Generated by CPack " << CMake_VERSION << " IFW generator "
  106. << "for QtIFW ";
  107. if (this->IsVersionEqual("1.9.9")) {
  108. comment << "less 2.0";
  109. } else {
  110. comment << this->Generator->FrameworkVersion;
  111. }
  112. comment << " tools at " << cmTimestamp().CurrentTime("", true);
  113. xout.Comment(comment.str().c_str());
  114. }