cmCPackIFWCommon.cxx 3.2 KB

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