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