cmCPackGenerator: Add GetOptionIfSet() to avoid duplicate calls

This commit is contained in:
Vitaly Stakhovsky
2024-11-04 12:00:00 -05:00
parent 384dbef61e
commit 17ee28728b
7 changed files with 108 additions and 110 deletions
+16 -14
View File
@@ -191,15 +191,16 @@ std::string cmCPackArchiveGenerator::GetArchiveComponentFileName(
std::string componentUpper(cmSystemTools::UpperCase(component)); std::string componentUpper(cmSystemTools::UpperCase(component));
std::string packageFileName; std::string packageFileName;
if (this->IsSet("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME")) { if (cmValue v = this->GetOptionIfSet("CPACK_ARCHIVE_" + componentUpper +
"_FILE_NAME")) {
packageFileName += *v;
} else if ((v = this->GetOptionIfSet("CPACK_ARCHIVE_FILE_NAME"))) {
packageFileName += packageFileName +=
*this->GetOption("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME"); this->GetComponentPackageFileName(*v, component, isGroupName);
} else if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) {
packageFileName += this->GetComponentPackageFileName(
*this->GetOption("CPACK_ARCHIVE_FILE_NAME"), component, isGroupName);
} else { } else {
packageFileName += this->GetComponentPackageFileName( v = this->GetOption("CPACK_PACKAGE_FILE_NAME");
*this->GetOption("CPACK_PACKAGE_FILE_NAME"), component, isGroupName); packageFileName +=
this->GetComponentPackageFileName(*v, component, isGroupName);
} }
packageFileName += this->GetOutputExtension(); packageFileName += this->GetOutputExtension();
@@ -394,10 +395,11 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne()
this->packageFileNames.emplace_back(this->toplevel); this->packageFileNames.emplace_back(this->toplevel);
this->packageFileNames[0] += "/"; this->packageFileNames[0] += "/";
if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) { if (cmValue v = this->GetOptionIfSet("CPACK_ARCHIVE_FILE_NAME")) {
this->packageFileNames[0] += *this->GetOption("CPACK_ARCHIVE_FILE_NAME"); this->packageFileNames[0] += *v;
} else { } else {
this->packageFileNames[0] += *this->GetOption("CPACK_PACKAGE_FILE_NAME"); v = this->GetOption("CPACK_PACKAGE_FILE_NAME");
this->packageFileNames[0] += *v;
} }
this->packageFileNames[0] += this->GetOutputExtension(); this->packageFileNames[0] += this->GetOutputExtension();
@@ -481,10 +483,10 @@ int cmCPackArchiveGenerator::GetThreadCount() const
int threads = 1; int threads = 1;
// CPACK_ARCHIVE_THREADS overrides CPACK_THREADS // CPACK_ARCHIVE_THREADS overrides CPACK_THREADS
if (this->IsSet("CPACK_ARCHIVE_THREADS")) { if (cmValue v = this->GetOptionIfSet("CPACK_ARCHIVE_THREADS")) {
threads = std::stoi(*this->GetOption("CPACK_ARCHIVE_THREADS")); threads = std::stoi(*v);
} else if (this->IsSet("CPACK_THREADS")) { } else if (cmValue v2 = this->GetOptionIfSet("CPACK_THREADS")) {
threads = std::stoi(*this->GetOption("CPACK_THREADS")); threads = std::stoi(*v2);
} }
return threads; return threads;
+9 -9
View File
@@ -101,13 +101,12 @@ int cmCPackDragNDropGenerator::InitializeInternal()
} }
this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path); this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path);
if (this->IsSet("CPACK_DMG_SLA_DIR")) { if (cmValue v = this->GetOptionIfSet("CPACK_DMG_SLA_DIR")) {
slaDirectory = this->GetOption("CPACK_DMG_SLA_DIR"); slaDirectory = *v;
if (!slaDirectory.empty() && if (!slaDirectory.empty() &&
this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE") && this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE") &&
this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) { (v = this->GetOptionIfSet("CPACK_RESOURCE_FILE_LICENSE"))) {
std::string license_file = std::string license_file = *v;
this->GetOption("CPACK_RESOURCE_FILE_LICENSE");
if (!license_file.empty() && if (!license_file.empty() &&
(license_file.find("CPack.GenericLicense.txt") == (license_file.find("CPack.GenericLicense.txt") ==
std::string::npos)) { std::string::npos)) {
@@ -119,7 +118,8 @@ int cmCPackDragNDropGenerator::InitializeInternal()
singleLicense = true; singleLicense = true;
} }
} }
if (!this->IsSet("CPACK_DMG_SLA_LANGUAGES")) { cmValue lang = this->GetOptionIfSet("CPACK_DMG_SLA_LANGUAGES");
if (!lang) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_DMG_SLA_DIR set but no languages defined " "CPACK_DMG_SLA_DIR set but no languages defined "
"(set CPACK_DMG_SLA_LANGUAGES)" "(set CPACK_DMG_SLA_LANGUAGES)"
@@ -132,7 +132,7 @@ int cmCPackDragNDropGenerator::InitializeInternal()
return 0; return 0;
} }
cmList languages{ this->GetOption("CPACK_DMG_SLA_LANGUAGES") }; cmList languages{ *lang };
if (languages.empty()) { if (languages.empty()) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl); "CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl);
@@ -742,8 +742,8 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallSuffix(
std::string componentFileName = cmStrCat( std::string componentFileName = cmStrCat(
"CPACK_DMG_", cmSystemTools::UpperCase(componentName), "_FILE_NAME"); "CPACK_DMG_", cmSystemTools::UpperCase(componentName), "_FILE_NAME");
if (this->IsSet(componentFileName)) { if (cmValue v = this->GetOptionIfSet(componentFileName)) {
return this->GetOption(componentFileName); return *v;
} }
return GetComponentPackageFileName(package_file_name, componentName, false); return GetComponentPackageFileName(package_file_name, componentName, false);
} }
+9
View File
@@ -1318,6 +1318,15 @@ bool cmCPackGenerator::IsSet(const std::string& name) const
return this->MakefileMap->IsSet(name); return this->MakefileMap->IsSet(name);
} }
cmValue cmCPackGenerator::GetOptionIfSet(const std::string& name) const
{
cmValue ret = this->MakefileMap->GetDefinition(name);
if (!ret || ret->empty() || cmIsNOTFOUND(*ret)) {
return {};
}
return ret;
}
bool cmCPackGenerator::IsOn(const std::string& name) const bool cmCPackGenerator::IsOn(const std::string& name) const
{ {
return this->GetOption(name).IsOn(); return this->GetOption(name).IsOn();
+1
View File
@@ -103,6 +103,7 @@ public:
cmValue GetOption(const std::string& op) const; cmValue GetOption(const std::string& op) const;
std::vector<std::string> GetOptions() const; std::vector<std::string> GetOptions() const;
bool IsSet(const std::string& name) const; bool IsSet(const std::string& name) const;
cmValue GetOptionIfSet(const std::string& name) const;
bool IsOn(const std::string& name) const; bool IsOn(const std::string& name) const;
bool IsSetToOff(const std::string& op) const; bool IsSetToOff(const std::string& op) const;
bool IsSetToEmpty(const std::string& op) const; bool IsSetToEmpty(const std::string& op) const;
+38 -44
View File
@@ -97,9 +97,8 @@ int cmCPackInnoSetupGenerator::InitializeInternal()
int cmCPackInnoSetupGenerator::PackageFiles() int cmCPackInnoSetupGenerator::PackageFiles()
{ {
// Includes // Includes
if (IsSet("CPACK_INNOSETUP_EXTRA_SCRIPTS")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_EXTRA_SCRIPTS")) {
const cmList extraScripts(GetOption("CPACK_INNOSETUP_EXTRA_SCRIPTS")); const cmList extraScripts(*v);
for (const std::string& i : extraScripts) { for (const std::string& i : extraScripts) {
includeDirectives.emplace_back(cmStrCat( includeDirectives.emplace_back(cmStrCat(
"#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel)))); "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel))));
@@ -133,9 +132,8 @@ int cmCPackInnoSetupGenerator::PackageFiles()
} }
// [Code] section // [Code] section
if (IsSet("CPACK_INNOSETUP_CODE_FILES")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_CODE_FILES")) {
const cmList codeFiles(GetOption("CPACK_INNOSETUP_CODE_FILES")); const cmList codeFiles(*v);
for (const std::string& i : codeFiles) { for (const std::string& i : codeFiles) {
codeIncludes.emplace_back(cmStrCat( codeIncludes.emplace_back(cmStrCat(
"#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel)))); "#include ", QuotePath(cmSystemTools::CollapseFullPath(i, toplevel))));
@@ -168,26 +166,26 @@ bool cmCPackInnoSetupGenerator::ProcessSetupSection()
} }
setupDirectives["AppPublisher"] = GetOption("CPACK_PACKAGE_VENDOR"); setupDirectives["AppPublisher"] = GetOption("CPACK_PACKAGE_VENDOR");
if (IsSet("CPACK_PACKAGE_HOMEPAGE_URL")) { if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_HOMEPAGE_URL")) {
setupDirectives["AppPublisherURL"] = setupDirectives["AppPublisherURL"] = *v;
GetOption("CPACK_PACKAGE_HOMEPAGE_URL"); setupDirectives["AppSupportURL"] = *v;
setupDirectives["AppSupportURL"] = GetOption("CPACK_PACKAGE_HOMEPAGE_URL"); setupDirectives["AppUpdatesURL"] = *v;
setupDirectives["AppUpdatesURL"] = GetOption("CPACK_PACKAGE_HOMEPAGE_URL");
} }
SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE", "OFF"); SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE", "OFF");
if (IsSet("CPACK_RESOURCE_FILE_LICENSE") && if (!GetOption("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE").IsOn()) {
!GetOption("CPACK_INNOSETUP_IGNORE_LICENSE_PAGE").IsOn()) { if (cmValue v = GetOptionIfSet("CPACK_RESOURCE_FILE_LICENSE")) {
setupDirectives["LicenseFile"] = cmSystemTools::ConvertToWindowsOutputPath( setupDirectives["LicenseFile"] =
GetOption("CPACK_RESOURCE_FILE_LICENSE")); cmSystemTools::ConvertToWindowsOutputPath(*v);
}
} }
SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_README_PAGE", "ON"); SetOptionIfNotSet("CPACK_INNOSETUP_IGNORE_README_PAGE", "ON");
if (IsSet("CPACK_RESOURCE_FILE_README") && if (!GetOption("CPACK_INNOSETUP_IGNORE_README_PAGE").IsOn()) {
!GetOption("CPACK_INNOSETUP_IGNORE_README_PAGE").IsOn()) { if (cmValue v = GetOptionIfSet("CPACK_RESOURCE_FILE_README")) {
setupDirectives["InfoBeforeFile"] = setupDirectives["InfoBeforeFile"] =
cmSystemTools::ConvertToWindowsOutputPath( cmSystemTools::ConvertToWindowsOutputPath(*v);
GetOption("CPACK_RESOURCE_FILE_README")); }
} }
SetOptionIfNotSet("CPACK_INNOSETUP_USE_MODERN_WIZARD", "OFF"); SetOptionIfNotSet("CPACK_INNOSETUP_USE_MODERN_WIZARD", "OFF");
@@ -201,16 +199,14 @@ bool cmCPackInnoSetupGenerator::ProcessSetupSection()
setupDirectives["SetupIconFile"] = "compiler:SetupClassicIcon.ico"; setupDirectives["SetupIconFile"] = "compiler:SetupClassicIcon.ico";
} }
if (IsSet("CPACK_INNOSETUP_ICON_FILE")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_ICON_FILE")) {
setupDirectives["SetupIconFile"] = setupDirectives["SetupIconFile"] =
cmSystemTools::ConvertToWindowsOutputPath( cmSystemTools::ConvertToWindowsOutputPath(*v);
GetOption("CPACK_INNOSETUP_ICON_FILE"));
} }
if (IsSet("CPACK_PACKAGE_ICON")) { if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_ICON")) {
setupDirectives["WizardSmallImageFile"] = setupDirectives["WizardSmallImageFile"] =
cmSystemTools::ConvertToWindowsOutputPath( cmSystemTools::ConvertToWindowsOutputPath(*v);
GetOption("CPACK_PACKAGE_ICON"));
} }
if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) { if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) {
@@ -238,8 +234,8 @@ bool cmCPackInnoSetupGenerator::ProcessSetupSection()
toplevelProgramFolder = false; toplevelProgramFolder = false;
} }
if (IsSet("CPACK_INNOSETUP_PASSWORD")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_PASSWORD")) {
setupDirectives["Password"] = GetOption("CPACK_INNOSETUP_PASSWORD"); setupDirectives["Password"] = *v;
setupDirectives["Encryption"] = "yes"; setupDirectives["Encryption"] = "yes";
} }
@@ -306,9 +302,9 @@ bool cmCPackInnoSetupGenerator::ProcessSetupSection()
bool cmCPackInnoSetupGenerator::ProcessFiles() bool cmCPackInnoSetupGenerator::ProcessFiles()
{ {
std::map<std::string, std::string> customFileInstructions; std::map<std::string, std::string> customFileInstructions;
if (IsSet("CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS")) { if (cmValue v =
const cmList instructions( GetOptionIfSet("CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS")) {
GetOption("CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS")); const cmList instructions(*v);
if (instructions.size() % 2 != 0) { if (instructions.size() % 2 != 0) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS should " "CPACK_INNOSETUP_CUSTOM_INSTALL_INSTRUCTIONS should "
@@ -328,8 +324,8 @@ bool cmCPackInnoSetupGenerator::ProcessFiles()
toplevelProgramFolder ? "{autoprograms}\\" : "{group}\\"; toplevelProgramFolder ? "{autoprograms}\\" : "{group}\\";
std::map<std::string, std::string> icons; std::map<std::string, std::string> icons;
if (IsSet("CPACK_PACKAGE_EXECUTABLES")) { if (cmValue v = GetOptionIfSet("CPACK_PACKAGE_EXECUTABLES")) {
const cmList executables(GetOption("CPACK_PACKAGE_EXECUTABLES")); const cmList executables(*v);
if (executables.size() % 2 != 0) { if (executables.size() % 2 != 0) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_PACKAGE_EXECUTABLES should should contain pairs of " "CPACK_PACKAGE_EXECUTABLES should should contain pairs of "
@@ -345,13 +341,13 @@ bool cmCPackInnoSetupGenerator::ProcessFiles()
} }
std::vector<std::string> desktopIcons; std::vector<std::string> desktopIcons;
if (IsSet("CPACK_CREATE_DESKTOP_LINKS")) { if (cmValue v = GetOptionIfSet("CPACK_CREATE_DESKTOP_LINKS")) {
cmExpandList(GetOption("CPACK_CREATE_DESKTOP_LINKS"), desktopIcons); cmExpandList(*v, desktopIcons);
} }
std::vector<std::string> runExecutables; std::vector<std::string> runExecutables;
if (IsSet("CPACK_INNOSETUP_RUN_EXECUTABLES")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_RUN_EXECUTABLES")) {
cmExpandList(GetOption("CPACK_INNOSETUP_RUN_EXECUTABLES"), runExecutables); cmExpandList(*v, runExecutables);
} }
for (const std::string& i : files) { for (const std::string& i : files) {
@@ -507,8 +503,8 @@ bool cmCPackInnoSetupGenerator::ProcessFiles()
static cmsys::RegularExpression urlRegex( static cmsys::RegularExpression urlRegex(
"^(mailto:|(ftps?|https?|news)://).*$"); "^(mailto:|(ftps?|https?|news)://).*$");
if (IsSet("CPACK_INNOSETUP_MENU_LINKS")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_MENU_LINKS")) {
const cmList menuIcons(GetOption("CPACK_INNOSETUP_MENU_LINKS")); const cmList menuIcons(*v);
if (menuIcons.size() % 2 != 0) { if (menuIcons.size() % 2 != 0) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_INNOSETUP_MENU_LINKS should " "CPACK_INNOSETUP_MENU_LINKS should "
@@ -784,8 +780,7 @@ bool cmCPackInnoSetupGenerator::ConfigureISScript()
const std::string& defaultMessage = const std::string& defaultMessage =
"; CPack didn't find any entries for this section"; "; CPack didn't find any entries for this section";
if (IsSet("CPACK_CREATE_DESKTOP_LINKS") && if (!IsSetToEmpty("CPACK_CREATE_DESKTOP_LINKS")) {
!GetOption("CPACK_CREATE_DESKTOP_LINKS").Get()->empty()) {
cmCPackInnoSetupKeyValuePairs tasks; cmCPackInnoSetupKeyValuePairs tasks;
tasks["Name"] = "\"desktopicon\""; tasks["Name"] = "\"desktopicon\"";
tasks["Description"] = "\"{cm:CreateDesktopIcon}\""; tasks["Description"] = "\"{cm:CreateDesktopIcon}\"";
@@ -858,9 +853,8 @@ bool cmCPackInnoSetupGenerator::Compile()
} }
} }
if (IsSet("CPACK_INNOSETUP_EXECUTABLE_ARGUMENTS")) { if (cmValue v = GetOptionIfSet("CPACK_INNOSETUP_EXECUTABLE_ARGUMENTS")) {
const cmList args(GetOption("CPACK_INNOSETUP_EXECUTABLE_ARGUMENTS")); const cmList args(*v);
isccArgs.insert(isccArgs.end(), args.begin(), args.end()); isccArgs.insert(isccArgs.end(), args.begin(), args.end());
} }
+33 -39
View File
@@ -130,23 +130,20 @@ int cmCPackNSISGenerator::PackageFiles()
if (this->IsSet("CPACK_NSIS_MUI_ICON") || if (this->IsSet("CPACK_NSIS_MUI_ICON") ||
this->IsSet("CPACK_NSIS_MUI_UNIICON")) { this->IsSet("CPACK_NSIS_MUI_UNIICON")) {
std::string installerIconCode; std::string installerIconCode;
if (this->IsSet("CPACK_NSIS_MUI_ICON")) { if (cmValue icon = this->GetOptionIfSet("CPACK_NSIS_MUI_ICON")) {
installerIconCode += cmStrCat( installerIconCode += cmStrCat("!define MUI_ICON \"", *icon, "\"\n");
"!define MUI_ICON \"", this->GetOption("CPACK_NSIS_MUI_ICON"), "\"\n");
} }
if (this->IsSet("CPACK_NSIS_MUI_UNIICON")) { if (cmValue icon = this->GetOptionIfSet("CPACK_NSIS_MUI_UNIICON")) {
installerIconCode += installerIconCode += cmStrCat("!define MUI_UNICON \"", *icon, "\"\n");
cmStrCat("!define MUI_UNICON \"",
this->GetOption("CPACK_NSIS_MUI_UNIICON"), "\"\n");
} }
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE",
installerIconCode.c_str()); installerIconCode.c_str());
} }
std::string installerHeaderImage; std::string installerHeaderImage;
if (this->IsSet("CPACK_NSIS_MUI_HEADERIMAGE")) { if (cmValue img = this->GetOptionIfSet("CPACK_NSIS_MUI_HEADERIMAGE")) {
installerHeaderImage = *this->GetOption("CPACK_NSIS_MUI_HEADERIMAGE"); installerHeaderImage = *img;
} else if (this->IsSet("CPACK_PACKAGE_ICON")) { } else if (cmValue icon = this->GetOptionIfSet("CPACK_PACKAGE_ICON")) {
installerHeaderImage = *this->GetOption("CPACK_PACKAGE_ICON"); installerHeaderImage = *icon;
} }
if (!installerHeaderImage.empty()) { if (!installerHeaderImage.empty()) {
std::string installerIconCode = cmStrCat( std::string installerIconCode = cmStrCat(
@@ -155,35 +152,33 @@ int cmCPackNSISGenerator::PackageFiles()
installerIconCode); installerIconCode);
} }
if (this->IsSet("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP")) { if (cmValue v =
std::string installerBitmapCode = cmStrCat( this->GetOptionIfSet("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP")) {
"!define MUI_WELCOMEFINISHPAGE_BITMAP \"", std::string installerBitmapCode =
this->GetOption("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP"), "\"\n"); cmStrCat("!define MUI_WELCOMEFINISHPAGE_BITMAP \"", *v, "\"\n");
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE",
installerBitmapCode); installerBitmapCode);
} }
if (this->IsSet("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP")) { if (cmValue v =
std::string installerBitmapCode = cmStrCat( this->GetOptionIfSet("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP")) {
"!define MUI_UNWELCOMEFINISHPAGE_BITMAP \"", std::string installerBitmapCode =
this->GetOption("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP"), "\"\n"); cmStrCat("!define MUI_UNWELCOMEFINISHPAGE_BITMAP \"", *v, "\"\n");
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE",
installerBitmapCode); installerBitmapCode);
} }
if (this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN")) { if (cmValue v = this->GetOptionIfSet("CPACK_NSIS_MUI_FINISHPAGE_RUN")) {
std::string installerRunCode = std::string installerRunCode = cmStrCat(
cmStrCat("!define MUI_FINISHPAGE_RUN \"$INSTDIR\\", "!define MUI_FINISHPAGE_RUN \"$INSTDIR\\",
this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY"), '\\', this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY"), '\\', *v, "\"\n");
this->GetOption("CPACK_NSIS_MUI_FINISHPAGE_RUN"), "\"\n");
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE",
installerRunCode); installerRunCode);
} }
if (this->IsSet("CPACK_NSIS_WELCOME_TITLE")) { if (cmValue v = this->GetOptionIfSet("CPACK_NSIS_WELCOME_TITLE")) {
std::string welcomeTitleCode = std::string welcomeTitleCode =
cmStrCat("!define MUI_WELCOMEPAGE_TITLE \"", cmStrCat("!define MUI_WELCOMEPAGE_TITLE \"", *v, "\"");
this->GetOption("CPACK_NSIS_WELCOME_TITLE"), "\"");
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_WELCOME_TITLE_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_WELCOME_TITLE_CODE",
welcomeTitleCode); welcomeTitleCode);
} }
@@ -193,10 +188,9 @@ int cmCPackNSISGenerator::PackageFiles()
"!define MUI_WELCOMEPAGE_TITLE_3LINES"); "!define MUI_WELCOMEPAGE_TITLE_3LINES");
} }
if (this->IsSet("CPACK_NSIS_FINISH_TITLE")) { if (cmValue v = this->GetOptionIfSet("CPACK_NSIS_FINISH_TITLE")) {
std::string finishTitleCode = std::string finishTitleCode =
cmStrCat("!define MUI_FINISHPAGE_TITLE \"", cmStrCat("!define MUI_FINISHPAGE_TITLE \"", *v, "\"");
this->GetOption("CPACK_NSIS_FINISH_TITLE"), "\"");
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_FINISH_TITLE_CODE", this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_FINISH_TITLE_CODE",
finishTitleCode); finishTitleCode);
} }
@@ -211,28 +205,28 @@ int cmCPackNSISGenerator::PackageFiles()
"ManifestDPIAware true"); "ManifestDPIAware true");
} }
if (this->IsSet("CPACK_NSIS_BRANDING_TEXT")) { if (cmValue brandingText =
this->GetOptionIfSet("CPACK_NSIS_BRANDING_TEXT")) {
// Default position to LEFT // Default position to LEFT
std::string brandingTextPosition = "LEFT"; std::string brandingTextPosition = "LEFT";
if (this->IsSet("CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION")) { if (cmValue wantedPosition =
std::string wantedPosition = this->GetOptionIfSet("CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION")) {
this->GetOption("CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION"); if (!wantedPosition->empty()) {
if (!wantedPosition.empty()) {
const std::set<std::string> possiblePositions{ "CENTER", "LEFT", const std::set<std::string> possiblePositions{ "CENTER", "LEFT",
"RIGHT" }; "RIGHT" };
if (possiblePositions.find(wantedPosition) == if (possiblePositions.find(*wantedPosition) ==
possiblePositions.end()) { possiblePositions.end()) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"Unsupported branding text trim position " "Unsupported branding text trim position "
<< wantedPosition << std::endl); << *wantedPosition << std::endl);
return false; return false;
} }
brandingTextPosition = wantedPosition; brandingTextPosition = *wantedPosition;
} }
} }
std::string brandingTextCode = std::string brandingTextCode =
cmStrCat("BrandingText /TRIM", brandingTextPosition, " \"", cmStrCat("BrandingText /TRIM", brandingTextPosition, " \"",
this->GetOption("CPACK_NSIS_BRANDING_TEXT"), "\"\n"); *brandingText, "\"\n");
this->SetOptionIfNotSet("CPACK_NSIS_BRANDING_TEXT_CODE", brandingTextCode); this->SetOptionIfNotSet("CPACK_NSIS_BRANDING_TEXT_CODE", brandingTextCode);
} }
@@ -60,10 +60,8 @@ int cmCPackProductBuildGenerator::PackageFiles()
std::string resDir = cmStrCat(packageDirFileName, "/Contents"); std::string resDir = cmStrCat(packageDirFileName, "/Contents");
if (this->IsSet("CPACK_PRODUCTBUILD_RESOURCES_DIR")) { if (cmValue v = this->GetOptionIfSet("CPACK_PRODUCTBUILD_RESOURCES_DIR")) {
std::string userResDir = std::string userResDir = *v;
this->GetOption("CPACK_PRODUCTBUILD_RESOURCES_DIR");
if (!cmSystemTools::CopyADirectory(userResDir, resDir)) { if (!cmSystemTools::CopyADirectory(userResDir, resDir)) {
cmCPackLogger(cmCPackLog::LOG_ERROR, cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem copying the resource files" << std::endl); "Problem copying the resource files" << std::endl);