From 0aabeb0c30bae9509f46fdd2d27e8b724b853d6e Mon Sep 17 00:00:00 2001 From: Johnny Jazeix Date: Sun, 7 Feb 2021 16:10:57 +0100 Subject: CPack/NSIS: Add option for setting branding text See https://nsis.sourceforge.io/Reference/BrandingText for more information. Fixes: #21479 --- Help/cpack_gen/nsis.rst | 13 +++++++++++++ Help/release/dev/cpack-nsis-branding-text.rst | 7 +++++++ Modules/Internal/CPack/NSIS.template.in | 1 + Source/CPack/cmCPackNSISGenerator.cxx | 19 +++++++++++++++++++ Tests/CPackNSISGenerator/CMakeLists.txt | 2 ++ Tests/CPackNSISGenerator/RunCPackVerifyResult.cmake | 8 ++++++++ 6 files changed, 50 insertions(+) create mode 100644 Help/release/dev/cpack-nsis-branding-text.rst diff --git a/Help/cpack_gen/nsis.rst b/Help/cpack_gen/nsis.rst index 33198e7..eaef8ae 100644 --- a/Help/cpack_gen/nsis.rst +++ b/Help/cpack_gen/nsis.rst @@ -180,3 +180,16 @@ on Windows Nullsoft Scriptable Install System. .. versionadded:: 3.18 If set, declares that the installer is DPI-aware. + +.. variable:: CPACK_NSIS_BRANDING_TEXT + + .. versionadded:: 3.20 + + If set, updates the text at the bottom of the install window. + To set the string to blank, use a space (" "). + +.. variable:: CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION + + .. versionadded:: 3.20 + + If set, trim down the size of the control to the size of the branding text string. diff --git a/Help/release/dev/cpack-nsis-branding-text.rst b/Help/release/dev/cpack-nsis-branding-text.rst new file mode 100644 index 0000000..28a80ce --- /dev/null +++ b/Help/release/dev/cpack-nsis-branding-text.rst @@ -0,0 +1,7 @@ +cpack-nsis-branding-text +------------------------ + +* The :cpack_gen:`CPack NSIS Generator` gained new variables + :variable:`CPACK_NSIS_BRANDING_TEXT` and + :variable:`CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION` to change the + text at the bottom of the install window and change its trim position diff --git a/Modules/Internal/CPack/NSIS.template.in b/Modules/Internal/CPack/NSIS.template.in index b448c76..e6439ad 100644 --- a/Modules/Internal/CPack/NSIS.template.in +++ b/Modules/Internal/CPack/NSIS.template.in @@ -42,6 +42,7 @@ @CPACK_NSIS_DEFINES@ @CPACK_NSIS_MANIFEST_DPI_AWARE_CODE@ +@CPACK_NSIS_BRANDING_TEXT_CODE@ !include Sections.nsh diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 435f0ec..263adfd 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -209,6 +209,25 @@ int cmCPackNSISGenerator::PackageFiles() "ManifestDPIAware true"); } + if (this->IsSet("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"); + const std::set possiblePositions{ "CENTER", "LEFT", + "RIGHT" }; + if (possiblePositions.find(wantedPosition) != possiblePositions.end()) { + brandingTextPosition = wantedPosition; + } + } + std::string brandingTextCode = + cmStrCat("BrandingText /TRIM", brandingTextPosition, " \"", + this->GetOption("CPACK_NSIS_BRANDING_TEXT"), "\"\n"); + this->SetOptionIfNotSet("CPACK_NSIS_BRANDING_TEXT_CODE", + brandingTextCode.c_str()); + } + // Setup all of the component sections if (this->Components.empty()) { this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", ""); diff --git a/Tests/CPackNSISGenerator/CMakeLists.txt b/Tests/CPackNSISGenerator/CMakeLists.txt index 8ed4d59..64a8ef6 100644 --- a/Tests/CPackNSISGenerator/CMakeLists.txt +++ b/Tests/CPackNSISGenerator/CMakeLists.txt @@ -17,5 +17,7 @@ set(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}\\\\uninstall.ico") set(CPACK_GENERATOR "NSIS") set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) set(CPACK_NSIS_MANIFEST_DPI_AWARE ON) +set(CPACK_NSIS_BRANDING_TEXT "CMake branding text") +set(CPACK_NSIS_BRANDING_TEXT_TRIM_POSITION "RIGHT") include(CPack) diff --git a/Tests/CPackNSISGenerator/RunCPackVerifyResult.cmake b/Tests/CPackNSISGenerator/RunCPackVerifyResult.cmake index bfbcf9c..8bfcf26 100644 --- a/Tests/CPackNSISGenerator/RunCPackVerifyResult.cmake +++ b/Tests/CPackNSISGenerator/RunCPackVerifyResult.cmake @@ -52,3 +52,11 @@ if("${output_index}" EQUAL "-1") else() message(STATUS "Found DPI-aware") endif() + +file(STRINGS "${project_file}" line REGEX "^BrandingText /TRIMRIGHT \"CMake branding text\"") +string(FIND "${line}" "TRIMRIGHT" output_index) +if("${output_index}" EQUAL "-1") + message(FATAL_ERROR "BrandingText not found in the project") +else() + message(STATUS "Found BrandingText") +endif() -- cgit v0.12