cmCPackIFWCommon.cxx 3.2 KB

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