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 "cmCPackGenerator.h"
  5. #include "cmCPackIFWGenerator.h"
  6. #include "cmCPackLog.h" // IWYU pragma: keep
  7. #include "cmSystemTools.h"
  8. #include "cmTimestamp.h"
  9. #include "cmVersionConfig.h"
  10. #include "cmXMLWriter.h"
  11. #include <sstream>
  12. #include <utility>
  13. #include <vector>
  14. cmCPackIFWCommon::cmCPackIFWCommon()
  15. : Generator(nullptr)
  16. {
  17. }
  18. const char* cmCPackIFWCommon::GetOption(const std::string& op) const
  19. {
  20. return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op)
  21. : nullptr;
  22. }
  23. bool cmCPackIFWCommon::IsOn(const std::string& op) const
  24. {
  25. return this->Generator ? this->Generator->cmCPackGenerator::IsOn(op) : false;
  26. }
  27. bool cmCPackIFWCommon::IsSetToOff(const std::string& op) const
  28. {
  29. return this->Generator ? this->Generator->cmCPackGenerator::IsSetToOff(op)
  30. : false;
  31. }
  32. bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const
  33. {
  34. return this->Generator ? this->Generator->cmCPackGenerator::IsSetToEmpty(op)
  35. : false;
  36. }
  37. bool cmCPackIFWCommon::IsVersionLess(const char* version)
  38. {
  39. if (!this->Generator) {
  40. return false;
  41. }
  42. return cmSystemTools::VersionCompare(
  43. cmSystemTools::OP_LESS, this->Generator->FrameworkVersion.data(), version);
  44. }
  45. bool cmCPackIFWCommon::IsVersionGreater(const char* version)
  46. {
  47. if (!this->Generator) {
  48. return false;
  49. }
  50. return cmSystemTools::VersionCompare(
  51. cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion.data(),
  52. version);
  53. }
  54. bool cmCPackIFWCommon::IsVersionEqual(const char* version)
  55. {
  56. if (!this->Generator) {
  57. return false;
  58. }
  59. return cmSystemTools::VersionCompare(
  60. cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion.data(),
  61. 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;
  67. cmSystemTools::ExpandListArgument(arg, args, false);
  68. if (args.empty()) {
  69. return;
  70. }
  71. std::size_t i = 0;
  72. std::size_t c = args.size();
  73. if (c % 2) {
  74. argsOut[""] = args[i];
  75. ++i;
  76. }
  77. --c;
  78. for (; i < c; i += 2) {
  79. argsOut[args[i]] = args[i + 1];
  80. }
  81. }
  82. void cmCPackIFWCommon::ExpandListArgument(
  83. const std::string& arg, std::multimap<std::string, std::string>& argsOut)
  84. {
  85. std::vector<std::string> args;
  86. cmSystemTools::ExpandListArgument(arg, args, 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. }