cmCPackIFWCommon.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. const char* 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)
  40. {
  41. if (!this->Generator) {
  42. return false;
  43. }
  44. return cmSystemTools::VersionCompare(
  45. cmSystemTools::OP_LESS, this->Generator->FrameworkVersion.data(), version);
  46. }
  47. bool cmCPackIFWCommon::IsVersionGreater(const char* version)
  48. {
  49. if (!this->Generator) {
  50. return false;
  51. }
  52. return cmSystemTools::VersionCompare(
  53. cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion.data(),
  54. version);
  55. }
  56. bool cmCPackIFWCommon::IsVersionEqual(const char* version)
  57. {
  58. if (!this->Generator) {
  59. return false;
  60. }
  61. return cmSystemTools::VersionCompare(
  62. cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion.data(),
  63. version);
  64. }
  65. void cmCPackIFWCommon::ExpandListArgument(
  66. const std::string& arg, std::map<std::string, std::string>& argsOut)
  67. {
  68. std::vector<std::string> args = cmExpandedList(arg, false);
  69. if (args.empty()) {
  70. return;
  71. }
  72. std::size_t i = 0;
  73. std::size_t c = args.size();
  74. if (c % 2) {
  75. argsOut[""] = args[i];
  76. ++i;
  77. }
  78. --c;
  79. for (; i < c; i += 2) {
  80. argsOut[args[i]] = args[i + 1];
  81. }
  82. }
  83. void cmCPackIFWCommon::ExpandListArgument(
  84. const std::string& arg, std::multimap<std::string, std::string>& argsOut)
  85. {
  86. std::vector<std::string> args = cmExpandedList(arg, false);
  87. if (args.empty()) {
  88. return;
  89. }
  90. std::size_t i = 0;
  91. std::size_t c = args.size();
  92. if (c % 2) {
  93. argsOut.insert(std::pair<std::string, std::string>("", args[i]));
  94. ++i;
  95. }
  96. --c;
  97. for (; i < c; i += 2) {
  98. argsOut.insert(std::pair<std::string, std::string>(args[i], args[i + 1]));
  99. }
  100. }
  101. void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout)
  102. {
  103. if (!this->Generator) {
  104. return;
  105. }
  106. std::ostringstream comment;
  107. comment << "Generated by CPack " << CMake_VERSION << " IFW generator "
  108. << "for QtIFW ";
  109. if (this->IsVersionEqual("1.9.9")) {
  110. comment << "less 2.0";
  111. } else {
  112. comment << this->Generator->FrameworkVersion;
  113. }
  114. comment << " tools at " << cmTimestamp().CurrentTime("", true);
  115. xout.Comment(comment.str().c_str());
  116. }