cmake/Source/CPack/IFW/cmCPackIFWCommon.cxx

135 lines
3.2 KiB
C++
Raw Normal View History

2017-07-20 19:35:53 +02:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCPackIFWCommon.h"
2020-08-30 11:54:41 +02:00
#include <cstddef> // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include <sstream>
#include <utility>
#include <vector>
2017-07-20 19:35:53 +02:00
#include "cmCPackGenerator.h"
#include "cmCPackIFWGenerator.h"
#include "cmCPackLog.h" // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-07-20 19:35:53 +02:00
#include "cmSystemTools.h"
#include "cmTimestamp.h"
#include "cmVersionConfig.h"
#include "cmXMLWriter.h"
cmCPackIFWCommon::cmCPackIFWCommon()
2018-01-26 17:06:56 +01:00
: Generator(nullptr)
2017-07-20 19:35:53 +02:00
{
}
2021-11-20 13:41:27 +01:00
cmValue cmCPackIFWCommon::GetOption(const std::string& op) const
2017-07-20 19:35:53 +02:00
{
return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op)
2018-01-26 17:06:56 +01:00
: nullptr;
2017-07-20 19:35:53 +02:00
}
bool cmCPackIFWCommon::IsOn(const std::string& op) const
{
2022-03-29 21:10:50 +02:00
return this->Generator && this->Generator->cmCPackGenerator::IsOn(op);
2017-07-20 19:35:53 +02:00
}
bool cmCPackIFWCommon::IsSetToOff(const std::string& op) const
{
2022-03-29 21:10:50 +02:00
return this->Generator && this->Generator->cmCPackGenerator::IsSetToOff(op);
2017-07-20 19:35:53 +02:00
}
bool cmCPackIFWCommon::IsSetToEmpty(const std::string& op) const
{
2022-03-29 21:10:50 +02:00
return this->Generator &&
this->Generator->cmCPackGenerator::IsSetToEmpty(op);
2017-07-20 19:35:53 +02:00
}
2021-09-14 00:13:48 +02:00
bool cmCPackIFWCommon::IsVersionLess(const char* version) const
2017-07-20 19:35:53 +02:00
{
if (!this->Generator) {
return false;
}
return cmSystemTools::VersionCompare(
2021-11-20 13:41:27 +01:00
cmSystemTools::OP_LESS, this->Generator->FrameworkVersion, version);
2017-07-20 19:35:53 +02:00
}
2021-09-14 00:13:48 +02:00
bool cmCPackIFWCommon::IsVersionGreater(const char* version) const
2017-07-20 19:35:53 +02:00
{
if (!this->Generator) {
return false;
}
return cmSystemTools::VersionCompare(
2021-11-20 13:41:27 +01:00
cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion, version);
2017-07-20 19:35:53 +02:00
}
2021-09-14 00:13:48 +02:00
bool cmCPackIFWCommon::IsVersionEqual(const char* version) const
2017-07-20 19:35:53 +02:00
{
if (!this->Generator) {
return false;
}
return cmSystemTools::VersionCompare(
2021-11-20 13:41:27 +01:00
cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion, version);
2017-07-20 19:35:53 +02:00
}
void cmCPackIFWCommon::ExpandListArgument(
const std::string& arg, std::map<std::string, std::string>& argsOut)
{
2020-02-01 23:06:01 +01:00
std::vector<std::string> args = cmExpandedList(arg, false);
2017-07-20 19:35:53 +02:00
if (args.empty()) {
return;
}
std::size_t i = 0;
std::size_t c = args.size();
if (c % 2) {
argsOut[""] = args[i];
++i;
}
--c;
for (; i < c; i += 2) {
argsOut[args[i]] = args[i + 1];
}
}
void cmCPackIFWCommon::ExpandListArgument(
const std::string& arg, std::multimap<std::string, std::string>& argsOut)
{
2020-02-01 23:06:01 +01:00
std::vector<std::string> args = cmExpandedList(arg, false);
2017-07-20 19:35:53 +02:00
if (args.empty()) {
return;
}
std::size_t i = 0;
std::size_t c = args.size();
if (c % 2) {
argsOut.insert(std::pair<std::string, std::string>("", args[i]));
++i;
}
--c;
for (; i < c; i += 2) {
argsOut.insert(std::pair<std::string, std::string>(args[i], args[i + 1]));
}
}
2021-09-14 00:13:48 +02:00
void cmCPackIFWCommon::WriteGeneratedByToStrim(cmXMLWriter& xout) const
2017-07-20 19:35:53 +02:00
{
if (!this->Generator) {
return;
}
std::ostringstream comment;
comment << "Generated by CPack " << CMake_VERSION << " IFW generator "
<< "for QtIFW ";
if (this->IsVersionEqual("1.9.9")) {
comment << "less 2.0";
} else {
comment << this->Generator->FrameworkVersion;
}
comment << " tools at " << cmTimestamp().CurrentTime("", true);
xout.Comment(comment.str().c_str());
}