cmake/Source/CPack/IFW/cmCPackIFWPackage.cxx

760 lines
22 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-04-27 22:25:09 +02:00
#include "cmCPackIFWPackage.h"
2020-02-01 23:06:01 +01:00
#include <cstddef>
#include <map>
#include <sstream>
#include <utility>
2021-09-14 00:13:48 +02:00
#include <cm/string_view>
2017-07-20 19:35:53 +02:00
#include "cmCPackComponentGroup.h"
#include "cmCPackIFWCommon.h"
2015-04-27 22:25:09 +02:00
#include "cmCPackIFWGenerator.h"
2016-10-30 18:24:19 +01:00
#include "cmCPackIFWInstaller.h"
2017-07-20 19:35:53 +02:00
#include "cmCPackLog.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include "cmGeneratedFileStream.h"
2023-07-02 19:51:09 +02:00
#include "cmList.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
#include "cmTimestamp.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2016-10-30 18:24:19 +01:00
#include "cmXMLWriter.h"
2015-04-27 22:25:09 +02:00
//---------------------------------------------------------- CompareStruct ---
2016-07-09 11:21:54 +02:00
cmCPackIFWPackage::CompareStruct::CompareStruct()
2017-07-20 19:35:53 +02:00
: Type(cmCPackIFWPackage::CompareNone)
2015-04-27 22:25:09 +02:00
{
}
//------------------------------------------------------- DependenceStruct ---
2019-11-11 23:01:05 +01:00
cmCPackIFWPackage::DependenceStruct::DependenceStruct() = default;
2015-04-27 22:25:09 +02:00
cmCPackIFWPackage::DependenceStruct::DependenceStruct(
2016-07-09 11:21:54 +02:00
const std::string& dependence)
2015-04-27 22:25:09 +02:00
{
2021-09-14 00:13:48 +02:00
// Preferred format is name and version are separated by a colon (:), but
// note that this is only supported with QtIFW 3.1 or later. Backward
// compatibility allows a hyphen (-) as a separator instead, but names then
// cannot contain a hyphen.
size_t pos;
if ((pos = dependence.find(':')) == std::string::npos) {
pos = dependence.find('-');
}
if (pos != std::string::npos) {
this->Name = dependence.substr(0, pos);
++pos;
if (pos == dependence.size()) {
// Nothing after the separator. Treat this as no version constraint.
return;
}
const auto versionPart =
cm::string_view(dependence.data() + pos, dependence.size() - pos);
if (cmHasLiteralPrefix(versionPart, "<=")) {
this->Compare.Type = cmCPackIFWPackage::CompareLessOrEqual;
this->Compare.Value = std::string(versionPart.substr(2));
} else if (cmHasLiteralPrefix(versionPart, ">=")) {
this->Compare.Type = cmCPackIFWPackage::CompareGreaterOrEqual;
this->Compare.Value = std::string(versionPart.substr(2));
} else if (cmHasPrefix(versionPart, '<')) {
this->Compare.Type = cmCPackIFWPackage::CompareLess;
this->Compare.Value = std::string(versionPart.substr(1));
} else if (cmHasPrefix(versionPart, '=')) {
this->Compare.Type = cmCPackIFWPackage::CompareEqual;
this->Compare.Value = std::string(versionPart.substr(1));
} else if (cmHasPrefix(versionPart, '>')) {
this->Compare.Type = cmCPackIFWPackage::CompareGreater;
this->Compare.Value = std::string(versionPart.substr(1));
} else {
// We found no operator but a version specification is still expected to
// follow. The default behavior is to treat this the same as =. We
// explicitly record that as our type (it simplifies our logic a little
// and is also clearer).
this->Compare.Type = cmCPackIFWPackage::CompareEqual;
this->Compare.Value = std::string(versionPart);
}
} else {
this->Name = dependence;
}
2015-04-27 22:25:09 +02:00
}
std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const
{
2017-07-20 19:35:53 +02:00
std::string result = this->Name;
2021-09-14 00:13:48 +02:00
if (this->Name.find('-') != std::string::npos) {
// When a name contains a hyphen, we must use a colon after the name to
// prevent the hyphen from being parsed by QtIFW as the separator between
// the name and the version. Note that a colon is only supported with
// QtIFW 3.1 or later.
result += ":";
} else if (this->Compare.Type != cmCPackIFWPackage::CompareNone ||
!this->Compare.Value.empty()) {
// No hyphen in the name and we know a version part will follow. Use a
// hyphen as a separator since this works for all QtIFW versions.
2017-04-14 19:02:05 +02:00
result += "-";
}
2017-07-20 19:35:53 +02:00
if (this->Compare.Type == cmCPackIFWPackage::CompareLessOrEqual) {
2015-04-27 22:25:09 +02:00
result += "<=";
2017-07-20 19:35:53 +02:00
} else if (this->Compare.Type == cmCPackIFWPackage::CompareGreaterOrEqual) {
2015-04-27 22:25:09 +02:00
result += ">=";
2017-07-20 19:35:53 +02:00
} else if (this->Compare.Type == cmCPackIFWPackage::CompareLess) {
2015-04-27 22:25:09 +02:00
result += "<";
2017-07-20 19:35:53 +02:00
} else if (this->Compare.Type == cmCPackIFWPackage::CompareEqual) {
2015-04-27 22:25:09 +02:00
result += "=";
2017-07-20 19:35:53 +02:00
} else if (this->Compare.Type == cmCPackIFWPackage::CompareGreater) {
2015-04-27 22:25:09 +02:00
result += ">";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
result += this->Compare.Value;
2015-04-27 22:25:09 +02:00
return result;
}
//------------------------------------------------------ cmCPackIFWPackage ---
2016-07-09 11:21:54 +02:00
cmCPackIFWPackage::cmCPackIFWPackage()
2018-01-26 17:06:56 +01:00
: Installer(nullptr)
2015-08-17 11:37:30 +02:00
{
}
2016-07-09 11:21:54 +02:00
std::string cmCPackIFWPackage::GetComponentName(cmCPackComponent* component)
2015-04-27 22:25:09 +02:00
{
2016-10-30 18:24:19 +01:00
if (!component) {
2016-07-09 11:21:54 +02:00
return "";
2016-10-30 18:24:19 +01:00
}
2021-11-20 13:41:27 +01:00
cmValue option =
2017-07-20 19:35:53 +02:00
this->GetOption("CPACK_IFW_COMPONENT_" +
cmsys::SystemTools::UpperCase(component->Name) + "_NAME");
2021-11-20 13:41:27 +01:00
return option ? *option : component->Name;
2015-04-27 22:25:09 +02:00
}
void cmCPackIFWPackage::DefaultConfiguration()
{
2017-07-20 19:35:53 +02:00
this->DisplayName.clear();
this->Description.clear();
2018-01-26 17:06:56 +01:00
this->Version.clear();
this->ReleaseDate.clear();
this->Script.clear();
2017-07-20 19:35:53 +02:00
this->Licenses.clear();
this->UserInterfaces.clear();
this->Translations.clear();
2018-01-26 17:06:56 +01:00
this->SortingPriority.clear();
this->UpdateText.clear();
this->Default.clear();
this->Essential.clear();
this->Virtual.clear();
this->ForcedInstallation.clear();
this->RequiresAdminRights.clear();
2015-04-27 22:25:09 +02:00
}
2018-08-09 18:06:22 +02:00
// Default configuration (all in one package)
2015-04-27 22:25:09 +02:00
int cmCPackIFWPackage::ConfigureFromOptions()
{
2018-08-09 18:06:22 +02:00
// Restore default configuration
2017-07-20 19:35:53 +02:00
this->DefaultConfiguration();
2015-04-27 22:25:09 +02:00
// Name
2017-07-20 19:35:53 +02:00
this->Name = this->Generator->GetRootPackageName();
2015-04-27 22:25:09 +02:00
// Display name
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption("CPACK_PACKAGE_NAME")) {
this->DisplayName[""] = *option;
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->DisplayName[""] = "Your package";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Description
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY")) {
this->Description[""] = *option;
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->Description[""] = "Your package description";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Version
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption("CPACK_PACKAGE_VERSION")) {
this->Version = *option;
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->Version = "1.0.0";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
this->ForcedInstallation = "true";
2015-04-27 22:25:09 +02:00
return 1;
}
2016-07-09 11:21:54 +02:00
int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component)
2015-04-27 22:25:09 +02:00
{
2016-10-30 18:24:19 +01:00
if (!component) {
2016-07-09 11:21:54 +02:00
return 0;
2016-10-30 18:24:19 +01:00
}
2015-04-27 22:25:09 +02:00
2018-08-09 18:06:22 +02:00
// Restore default configuration
2017-07-20 19:35:53 +02:00
this->DefaultConfiguration();
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
std::string prefix = "CPACK_IFW_COMPONENT_" +
cmsys::SystemTools::UpperCase(component->Name) + "_";
2015-04-27 22:25:09 +02:00
// Display name
2017-07-20 19:35:53 +02:00
this->DisplayName[""] = component->DisplayName;
2015-04-27 22:25:09 +02:00
// Description
2017-07-20 19:35:53 +02:00
this->Description[""] = component->Description;
2015-04-27 22:25:09 +02:00
// Version
2021-11-20 13:41:27 +01:00
if (cmValue optVERSION = this->GetOption(prefix + "VERSION")) {
this->Version = *optVERSION;
} else if (cmValue optPACKAGE_VERSION =
2017-07-20 19:35:53 +02:00
this->GetOption("CPACK_PACKAGE_VERSION")) {
2021-11-20 13:41:27 +01:00
this->Version = *optPACKAGE_VERSION;
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->Version = "1.0.0";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Script
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "SCRIPT")) {
this->Script = *option;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2016-10-30 18:24:19 +01:00
// User interfaces
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "USER_INTERFACES")) {
2017-07-20 19:35:53 +02:00
this->UserInterfaces.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(option, this->UserInterfaces);
2016-10-30 18:24:19 +01:00
}
2015-04-27 22:25:09 +02:00
// CMake dependencies
2016-07-09 11:21:54 +02:00
if (!component->Dependencies.empty()) {
2018-01-26 17:06:56 +01:00
for (cmCPackComponent* dep : component->Dependencies) {
this->Dependencies.insert(this->Generator->ComponentPackages[dep]);
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Licenses
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "LICENSES")) {
2017-07-20 19:35:53 +02:00
this->Licenses.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(option, this->Licenses);
2017-07-20 19:35:53 +02:00
if (this->Licenses.size() % 2 != 0) {
cmCPackIFWLogger(
WARNING,
prefix << "LICENSES"
<< " should contain pairs of <display_name> and <file_path>."
<< std::endl);
this->Licenses.clear();
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Priority
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "PRIORITY")) {
this->SortingPriority = *option;
2017-07-20 19:35:53 +02:00
cmCPackIFWLogger(
2018-08-09 18:06:22 +02:00
WARNING,
"The \"PRIORITY\" option is set "
2017-04-14 19:02:05 +02:00
<< "for component \"" << component->Name << "\", but there option is "
<< "deprecated. Please use \"SORTING_PRIORITY\" option instead."
<< std::endl);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Default
2017-07-20 19:35:53 +02:00
this->Default = component->IsDisabledByDefault ? "false" : "true";
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
// Essential
if (this->IsOn(prefix + "ESSENTIAL")) {
2017-07-20 19:35:53 +02:00
this->Essential = "true";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Virtual
2017-07-20 19:35:53 +02:00
this->Virtual = component->IsHidden ? "true" : "";
2015-04-27 22:25:09 +02:00
// ForcedInstallation
2017-07-20 19:35:53 +02:00
this->ForcedInstallation = component->IsRequired ? "true" : "false";
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
return this->ConfigureFromPrefix(prefix);
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group)
2015-04-27 22:25:09 +02:00
{
2016-10-30 18:24:19 +01:00
if (!group) {
2016-07-09 11:21:54 +02:00
return 0;
2016-10-30 18:24:19 +01:00
}
2015-04-27 22:25:09 +02:00
2018-08-09 18:06:22 +02:00
// Restore default configuration
2017-07-20 19:35:53 +02:00
this->DefaultConfiguration();
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
std::string prefix = "CPACK_IFW_COMPONENT_GROUP_" +
cmsys::SystemTools::UpperCase(group->Name) + "_";
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
this->DisplayName[""] = group->DisplayName;
this->Description[""] = group->Description;
2015-04-27 22:25:09 +02:00
// Version
2021-11-20 13:41:27 +01:00
if (cmValue optVERSION = this->GetOption(prefix + "VERSION")) {
this->Version = *optVERSION;
} else if (cmValue optPACKAGE_VERSION =
2017-07-20 19:35:53 +02:00
this->GetOption("CPACK_PACKAGE_VERSION")) {
2021-11-20 13:41:27 +01:00
this->Version = *optPACKAGE_VERSION;
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->Version = "1.0.0";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Script
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "SCRIPT")) {
this->Script = *option;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2016-10-30 18:24:19 +01:00
// User interfaces
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "USER_INTERFACES")) {
2017-07-20 19:35:53 +02:00
this->UserInterfaces.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(option, this->UserInterfaces);
2016-10-30 18:24:19 +01:00
}
2015-04-27 22:25:09 +02:00
// Licenses
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "LICENSES")) {
2017-07-20 19:35:53 +02:00
this->Licenses.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(option, this->Licenses);
2017-07-20 19:35:53 +02:00
if (this->Licenses.size() % 2 != 0) {
cmCPackIFWLogger(
WARNING,
prefix << "LICENSES"
<< " should contain pairs of <display_name> and <file_path>."
<< std::endl);
this->Licenses.clear();
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Priority
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "PRIORITY")) {
this->SortingPriority = *option;
2017-07-20 19:35:53 +02:00
cmCPackIFWLogger(
2018-08-09 18:06:22 +02:00
WARNING,
"The \"PRIORITY\" option is set "
2017-04-14 19:02:05 +02:00
<< "for component group \"" << group->Name
<< "\", but there option is "
<< "deprecated. Please use \"SORTING_PRIORITY\" option instead."
<< std::endl);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
return this->ConfigureFromPrefix(prefix);
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
int cmCPackIFWPackage::ConfigureFromGroup(const std::string& groupName)
2015-04-27 22:25:09 +02:00
{
// Group configuration
cmCPackComponentGroup group;
2016-07-09 11:21:54 +02:00
std::string prefix =
"CPACK_COMPONENT_GROUP_" + cmsys::SystemTools::UpperCase(groupName) + "_";
2015-04-27 22:25:09 +02:00
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "DISPLAY_NAME")) {
group.DisplayName = *option;
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
group.DisplayName = group.Name;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2021-11-20 13:41:27 +01:00
if (cmValue option = this->GetOption(prefix + "DESCRIPTION")) {
group.Description = *option;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
group.IsBold = this->IsOn(prefix + "BOLD_TITLE");
group.IsExpandedByDefault = this->IsOn(prefix + "EXPANDED");
2015-04-27 22:25:09 +02:00
// Package configuration
group.Name = groupName;
2021-09-14 00:13:48 +02:00
if (this->Generator) {
2017-07-20 19:35:53 +02:00
this->Name = this->Generator->GetGroupPackageName(&group);
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
this->Name = group.Name;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
return this->ConfigureFromGroup(&group);
2015-04-27 22:25:09 +02:00
}
2017-04-14 19:02:05 +02:00
// Common options for components and groups
int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
{
// Temporary variable for full option name
std::string option;
// Display name
option = prefix + "DISPLAY_NAME";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->DisplayName.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2023-05-23 16:38:00 +02:00
cmCPackIFWPackage::ExpandListArgument(*value, this->DisplayName);
2017-04-14 19:02:05 +02:00
}
// Description
option = prefix + "DESCRIPTION";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->Description.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2023-05-23 16:38:00 +02:00
cmCPackIFWPackage::ExpandListArgument(*value, this->Description);
2017-04-14 19:02:05 +02:00
}
// Release date
option = prefix + "RELEASE_DATE";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->ReleaseDate.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
this->ReleaseDate = *value;
2017-04-14 19:02:05 +02:00
}
// Sorting priority
option = prefix + "SORTING_PRIORITY";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->SortingPriority.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
this->SortingPriority = *value;
2017-04-14 19:02:05 +02:00
}
// Update text
option = prefix + "UPDATE_TEXT";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->UpdateText.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
this->UpdateText = *value;
2017-04-14 19:02:05 +02:00
}
// Translations
option = prefix + "TRANSLATIONS";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->Translations.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2017-07-20 19:35:53 +02:00
this->Translations.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(value, this->Translations);
2017-04-14 19:02:05 +02:00
}
// QtIFW dependencies
2023-07-02 19:51:09 +02:00
cmList deps;
2017-04-14 19:02:05 +02:00
option = prefix + "DEPENDS";
2021-11-20 13:41:27 +01:00
if (cmValue value = this->GetOption(option)) {
2023-07-02 19:51:09 +02:00
deps.assign(value);
2017-04-14 19:02:05 +02:00
}
option = prefix + "DEPENDENCIES";
2021-11-20 13:41:27 +01:00
if (cmValue value = this->GetOption(option)) {
2023-07-02 19:51:09 +02:00
deps.append(value);
2017-04-14 19:02:05 +02:00
}
2023-07-02 19:51:09 +02:00
for (auto const& d : deps) {
2018-01-26 17:06:56 +01:00
DependenceStruct dep(d);
2017-07-20 19:35:53 +02:00
if (this->Generator->Packages.count(dep.Name)) {
cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name];
2017-04-14 19:02:05 +02:00
dep.Name = depPkg.Name;
}
2017-07-20 19:35:53 +02:00
bool hasDep = this->Generator->DependentPackages.count(dep.Name) > 0;
DependenceStruct& depRef = this->Generator->DependentPackages[dep.Name];
2017-04-14 19:02:05 +02:00
if (!hasDep) {
depRef = dep;
}
2017-07-20 19:35:53 +02:00
this->AlienDependencies.insert(&depRef);
2017-04-14 19:02:05 +02:00
}
// Automatic dependency on
option = prefix + "AUTO_DEPEND_ON";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->AlienAutoDependOn.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2023-07-02 19:51:09 +02:00
cmList depsOn{ value };
2018-01-26 17:06:56 +01:00
for (std::string const& d : depsOn) {
DependenceStruct dep(d);
2017-07-20 19:35:53 +02:00
if (this->Generator->Packages.count(dep.Name)) {
cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name];
2017-04-14 19:02:05 +02:00
dep.Name = depPkg.Name;
}
2017-07-20 19:35:53 +02:00
bool hasDep = this->Generator->DependentPackages.count(dep.Name) > 0;
DependenceStruct& depRef = this->Generator->DependentPackages[dep.Name];
2017-04-14 19:02:05 +02:00
if (!hasDep) {
depRef = dep;
}
2017-07-20 19:35:53 +02:00
this->AlienAutoDependOn.insert(&depRef);
2017-04-14 19:02:05 +02:00
}
}
// Visibility
option = prefix + "VIRTUAL";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->Virtual.clear();
} else if (this->IsOn(option)) {
this->Virtual = "true";
2017-04-14 19:02:05 +02:00
}
// Default selection
option = prefix + "DEFAULT";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->Default.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2023-05-23 16:38:00 +02:00
std::string lowerValue = cmsys::SystemTools::LowerCase(*value);
2017-07-20 19:35:53 +02:00
if (lowerValue == "true") {
this->Default = "true";
} else if (lowerValue == "false") {
this->Default = "false";
} else if (lowerValue == "script") {
this->Default = "script";
2017-04-14 19:02:05 +02:00
} else {
2021-11-20 13:41:27 +01:00
this->Default = *value;
2017-04-14 19:02:05 +02:00
}
}
// Forsed installation
option = prefix + "FORCED_INSTALLATION";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->ForcedInstallation.clear();
} else if (this->IsOn(option)) {
this->ForcedInstallation = "true";
} else if (this->IsSetToOff(option)) {
this->ForcedInstallation = "false";
2017-04-14 19:02:05 +02:00
}
2018-01-26 17:06:56 +01:00
// Replaces
option = prefix + "REPLACES";
if (this->IsSetToEmpty(option)) {
this->Replaces.clear();
2021-11-20 13:41:27 +01:00
} else if (cmValue value = this->GetOption(option)) {
2018-01-26 17:06:56 +01:00
this->Replaces.clear();
2020-02-01 23:06:01 +01:00
cmExpandList(value, this->Replaces);
2018-01-26 17:06:56 +01:00
}
2017-04-14 19:02:05 +02:00
// Requires admin rights
option = prefix + "REQUIRES_ADMIN_RIGHTS";
2017-07-20 19:35:53 +02:00
if (this->IsSetToEmpty(option)) {
this->RequiresAdminRights.clear();
} else if (this->IsOn(option)) {
this->RequiresAdminRights = "true";
} else if (this->IsSetToOff(option)) {
this->RequiresAdminRights = "false";
2017-04-14 19:02:05 +02:00
}
2018-01-26 17:06:56 +01:00
// Checkable
option = prefix + "CHECKABLE";
if (this->IsSetToEmpty(option)) {
this->Checkable.clear();
} else if (this->IsOn(option)) {
this->Checkable = "true";
} else if (this->IsSetToOff(option)) {
this->Checkable = "false";
}
2017-04-14 19:02:05 +02:00
return 1;
}
2015-04-27 22:25:09 +02:00
void cmCPackIFWPackage::GeneratePackageFile()
{
// Lazy directory initialization
2017-07-20 19:35:53 +02:00
if (this->Directory.empty()) {
if (this->Installer) {
this->Directory = this->Installer->Directory + "/packages/" + this->Name;
} else if (this->Generator) {
this->Directory = this->Generator->toplevel + "/packages/" + this->Name;
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Output stream
2018-10-28 12:09:07 +01:00
cmGeneratedFileStream fout(this->Directory + "/meta/package.xml");
2016-07-09 11:21:54 +02:00
cmXMLWriter xout(fout);
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
xout.StartDocument();
2015-08-17 11:37:30 +02:00
2021-09-14 00:13:48 +02:00
this->WriteGeneratedByToStrim(xout);
2015-08-17 11:37:30 +02:00
2016-07-09 11:21:54 +02:00
xout.StartElement("Package");
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
// DisplayName (with translations)
2018-01-26 17:06:56 +01:00
for (auto const& dn : this->DisplayName) {
2017-07-20 19:35:53 +02:00
xout.StartElement("DisplayName");
2018-01-26 17:06:56 +01:00
if (!dn.first.empty()) {
xout.Attribute("xml:lang", dn.first);
2017-07-20 19:35:53 +02:00
}
2018-01-26 17:06:56 +01:00
xout.Content(dn.second);
2017-07-20 19:35:53 +02:00
xout.EndElement();
}
// Description (with translations)
2018-01-26 17:06:56 +01:00
for (auto const& d : this->Description) {
2017-07-20 19:35:53 +02:00
xout.StartElement("Description");
2018-01-26 17:06:56 +01:00
if (!d.first.empty()) {
xout.Attribute("xml:lang", d.first);
2017-07-20 19:35:53 +02:00
}
2018-01-26 17:06:56 +01:00
xout.Content(d.second);
2017-07-20 19:35:53 +02:00
xout.EndElement();
}
2017-04-14 19:02:05 +02:00
// Update text
2017-07-20 19:35:53 +02:00
if (!this->UpdateText.empty()) {
xout.Element("UpdateText", this->UpdateText);
2017-04-14 19:02:05 +02:00
}
2017-07-20 19:35:53 +02:00
xout.Element("Name", this->Name);
xout.Element("Version", this->Version);
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
if (!this->ReleaseDate.empty()) {
xout.Element("ReleaseDate", this->ReleaseDate);
2016-07-09 11:21:54 +02:00
} else {
xout.Element("ReleaseDate", cmTimestamp().CurrentTime("%Y-%m-%d", true));
}
2015-04-27 22:25:09 +02:00
// Script (copy to meta dir)
2017-07-20 19:35:53 +02:00
if (!this->Script.empty()) {
std::string name = cmSystemTools::GetFilenameName(this->Script);
std::string path = this->Directory + "/meta/" + name;
cmsys::SystemTools::CopyFileIfDifferent(this->Script, path);
2016-07-09 11:21:54 +02:00
xout.Element("Script", name);
}
2015-04-27 22:25:09 +02:00
2016-10-30 18:24:19 +01:00
// User Interfaces (copy to meta dir)
2021-09-14 00:13:48 +02:00
std::vector<std::string> userInterfaces = this->UserInterfaces;
2018-01-26 17:06:56 +01:00
for (std::string& userInterface : userInterfaces) {
std::string name = cmSystemTools::GetFilenameName(userInterface);
2017-07-20 19:35:53 +02:00
std::string path = this->Directory + "/meta/" + name;
2018-01-26 17:06:56 +01:00
cmsys::SystemTools::CopyFileIfDifferent(userInterface, path);
userInterface = name;
2016-10-30 18:24:19 +01:00
}
if (!userInterfaces.empty()) {
xout.StartElement("UserInterfaces");
2018-01-26 17:06:56 +01:00
for (std::string const& userInterface : userInterfaces) {
xout.Element("UserInterface", userInterface);
2016-10-30 18:24:19 +01:00
}
xout.EndElement();
}
2017-04-14 19:02:05 +02:00
// Translations (copy to meta dir)
2021-09-14 00:13:48 +02:00
std::vector<std::string> translations = this->Translations;
2018-01-26 17:06:56 +01:00
for (std::string& translation : translations) {
std::string name = cmSystemTools::GetFilenameName(translation);
2017-07-20 19:35:53 +02:00
std::string path = this->Directory + "/meta/" + name;
2018-01-26 17:06:56 +01:00
cmsys::SystemTools::CopyFileIfDifferent(translation, path);
translation = name;
2017-04-14 19:02:05 +02:00
}
if (!translations.empty()) {
xout.StartElement("Translations");
2018-01-26 17:06:56 +01:00
for (std::string const& translation : translations) {
xout.Element("Translation", translation);
2017-04-14 19:02:05 +02:00
}
xout.EndElement();
}
2015-04-27 22:25:09 +02:00
// Dependencies
2021-09-14 00:13:48 +02:00
const bool hyphensInNamesUnsupported = this->Generator &&
!this->Generator->FrameworkVersion.empty() && this->IsVersionLess("3.1");
bool warnUnsupportedNames = false;
2015-04-27 22:25:09 +02:00
std::set<DependenceStruct> compDepSet;
2018-01-26 17:06:56 +01:00
for (DependenceStruct* ad : this->AlienDependencies) {
compDepSet.insert(*ad);
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
for (cmCPackIFWPackage* d : this->Dependencies) {
compDepSet.insert(DependenceStruct(d->Name));
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Write dependencies
2016-07-09 11:21:54 +02:00
if (!compDepSet.empty()) {
2016-10-30 18:24:19 +01:00
std::ostringstream dependencies;
2020-02-01 23:06:01 +01:00
auto it = compDepSet.begin();
2021-09-14 00:13:48 +02:00
warnUnsupportedNames |=
hyphensInNamesUnsupported && it->Name.find('-') != std::string::npos;
2016-07-09 11:21:54 +02:00
dependencies << it->NameWithCompare();
2015-04-27 22:25:09 +02:00
++it;
2016-07-09 11:21:54 +02:00
while (it != compDepSet.end()) {
2021-09-14 00:13:48 +02:00
warnUnsupportedNames |=
hyphensInNamesUnsupported && it->Name.find('-') != std::string::npos;
2016-07-09 11:21:54 +02:00
dependencies << "," << it->NameWithCompare();
2015-04-27 22:25:09 +02:00
++it;
}
2016-07-09 11:21:54 +02:00
xout.Element("Dependencies", dependencies.str());
}
2015-04-27 22:25:09 +02:00
2017-04-14 19:02:05 +02:00
// Automatic dependency on
std::set<DependenceStruct> compAutoDepSet;
2018-01-26 17:06:56 +01:00
for (DependenceStruct* aad : this->AlienAutoDependOn) {
compAutoDepSet.insert(*aad);
2017-04-14 19:02:05 +02:00
}
// Write automatic dependency on
if (!compAutoDepSet.empty()) {
std::ostringstream dependencies;
2020-02-01 23:06:01 +01:00
auto it = compAutoDepSet.begin();
2021-09-14 00:13:48 +02:00
warnUnsupportedNames |=
hyphensInNamesUnsupported && it->Name.find('-') != std::string::npos;
2017-04-14 19:02:05 +02:00
dependencies << it->NameWithCompare();
++it;
while (it != compAutoDepSet.end()) {
2021-09-14 00:13:48 +02:00
warnUnsupportedNames |=
hyphensInNamesUnsupported && it->Name.find('-') != std::string::npos;
2017-04-14 19:02:05 +02:00
dependencies << "," << it->NameWithCompare();
++it;
}
xout.Element("AutoDependOn", dependencies.str());
}
2021-09-14 00:13:48 +02:00
if (warnUnsupportedNames) {
cmCPackIFWLogger(
WARNING,
"The dependencies for component \""
<< this->Name << "\" specify names that contain hyphens. "
<< "This requires QtIFW 3.1 or later, but you are using version "
<< this->Generator->FrameworkVersion << std::endl);
}
2015-04-27 22:25:09 +02:00
// Licenses (copy to meta dir)
2017-07-20 19:35:53 +02:00
std::vector<std::string> licenses = this->Licenses;
2016-07-09 11:21:54 +02:00
for (size_t i = 1; i < licenses.size(); i += 2) {
2015-04-27 22:25:09 +02:00
std::string name = cmSystemTools::GetFilenameName(licenses[i]);
2017-07-20 19:35:53 +02:00
std::string path = this->Directory + "/meta/" + name;
cmsys::SystemTools::CopyFileIfDifferent(licenses[i], path);
2015-04-27 22:25:09 +02:00
licenses[i] = name;
2016-07-09 11:21:54 +02:00
}
if (!licenses.empty()) {
xout.StartElement("Licenses");
for (size_t i = 0; i < licenses.size(); i += 2) {
xout.StartElement("License");
xout.Attribute("name", licenses[i]);
xout.Attribute("file", licenses[i + 1]);
xout.EndElement();
}
xout.EndElement();
}
2017-07-20 19:35:53 +02:00
if (!this->ForcedInstallation.empty()) {
xout.Element("ForcedInstallation", this->ForcedInstallation);
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
// Replaces
if (!this->Replaces.empty()) {
std::ostringstream replaces;
2020-02-01 23:06:01 +01:00
auto it = this->Replaces.begin();
2018-01-26 17:06:56 +01:00
replaces << *it;
++it;
while (it != this->Replaces.end()) {
replaces << "," << *it;
++it;
}
xout.Element("Replaces", replaces.str());
}
2017-07-20 19:35:53 +02:00
if (!this->RequiresAdminRights.empty()) {
xout.Element("RequiresAdminRights", this->RequiresAdminRights);
2017-04-14 19:02:05 +02:00
}
2017-07-20 19:35:53 +02:00
if (!this->Virtual.empty()) {
xout.Element("Virtual", this->Virtual);
} else if (!this->Default.empty()) {
xout.Element("Default", this->Default);
2016-07-09 11:21:54 +02:00
}
// Essential
2017-07-20 19:35:53 +02:00
if (!this->Essential.empty()) {
xout.Element("Essential", this->Essential);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
// Priority
2017-07-20 19:35:53 +02:00
if (!this->SortingPriority.empty()) {
xout.Element("SortingPriority", this->SortingPriority);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2018-01-26 17:06:56 +01:00
// Checkable
if (!this->Checkable.empty()) {
xout.Element("Checkable", this->Checkable);
}
2016-07-09 11:21:54 +02:00
xout.EndElement();
xout.EndDocument();
2015-04-27 22:25:09 +02:00
}