|
| 1 | +# ============================================================================== |
| 2 | +# Copyright (C) 2026 Intel Corporation |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +# ============================================================================== |
| 6 | + |
| 7 | +; NSIS script template for CPack |
| 8 | +; Based on CMake/Modules/Internal/CPack/NSIS.template.in |
| 9 | + |
| 10 | +;-------------------------------- |
| 11 | +;Defines |
| 12 | + |
| 13 | + !define VERSION "@CPACK_PACKAGE_VERSION@" |
| 14 | + !define VERSION_MAJOR "@CPACK_PACKAGE_VERSION_MAJOR@" |
| 15 | + !define VERSION_MINOR "@CPACK_PACKAGE_VERSION_MINOR@" |
| 16 | + !define VERSION_PATCH "@CPACK_PACKAGE_VERSION_PATCH@" |
| 17 | + !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@" |
| 18 | + |
| 19 | +;-------------------------------- |
| 20 | +;Includes |
| 21 | + |
| 22 | + !include "MUI2.nsh" |
| 23 | + !include "Sections.nsh" |
| 24 | + |
| 25 | +;-------------------------------- |
| 26 | +;General |
| 27 | + |
| 28 | + ;Name and file |
| 29 | + Name "@CPACK_NSIS_PACKAGE_NAME@" |
| 30 | + OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@" |
| 31 | + |
| 32 | + ;Default installation folder |
| 33 | + InstallDir "@CPACK_NSIS_INSTALL_ROOT@\@CPACK_PACKAGE_INSTALL_DIRECTORY@" |
| 34 | + |
| 35 | + ;Set compression |
| 36 | + SetCompressor @CPACK_NSIS_COMPRESSOR@ |
| 37 | + |
| 38 | + ;Require administrator access |
| 39 | + RequestExecutionLevel admin |
| 40 | +@CPACK_NSIS_DEFINES@ |
| 41 | +@CPACK_NSIS_DLSTREAMER_DEFINES@ |
| 42 | + |
| 43 | +;--- Component support macros: --- |
| 44 | +; The code for the add/remove functionality is from: |
| 45 | +; https://nsis.sourceforge.io/Add/Remove_Functionality |
| 46 | +; It has been modified slightly and extended to provide |
| 47 | +; inter-component dependencies. |
| 48 | +Var AR_SecFlags |
| 49 | +Var AR_RegFlags |
| 50 | +@CPACK_NSIS_SECTION_SELECTED_VARS@ |
| 51 | + |
| 52 | +; Loads the "selected" flag for the section named SecName into the |
| 53 | +; variable VarName. |
| 54 | +!macro LoadSectionSelectedIntoVar SecName VarName |
| 55 | + SectionGetFlags ${${SecName}} $${VarName} |
| 56 | + IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits |
| 57 | +!macroend |
| 58 | + |
| 59 | +; Loads the value of a variable... can we get around this? |
| 60 | +!macro LoadVar VarName |
| 61 | + IntOp $R0 0 + $${VarName} |
| 62 | +!macroend |
| 63 | + |
| 64 | +; Sets the value of a variable |
| 65 | +!macro StoreVar VarName IntValue |
| 66 | + IntOp $${VarName} 0 + ${IntValue} |
| 67 | +!macroend |
| 68 | + |
| 69 | +!macro InitSection SecName |
| 70 | + ; This macro reads component installed flag from the registry and |
| 71 | + ;changes checked state of the section on the components page. |
| 72 | + ;Input: section index constant name specified in Section command. |
| 73 | + |
| 74 | + ClearErrors |
| 75 | + ;Reading component status from registry |
| 76 | + ReadRegDWORD $AR_RegFlags HKLM "${UNINSTALL_REGISTRY_KEY}" "${SecName}_Installed" |
| 77 | + IfErrors "default_${SecName}" |
| 78 | + ;Status will stay default if registry value not found |
| 79 | + ;(component was never installed) |
| 80 | + IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits |
| 81 | + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags |
| 82 | + IntOp $AR_SecFlags $AR_SecFlags & ${SECTION_OFF} ;Turn lowest (selected) bit off |
| 83 | + IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit |
| 84 | + |
| 85 | + ; Note whether this component was installed before |
| 86 | + !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags |
| 87 | + |
| 88 | + ;Writing modified flags |
| 89 | + SectionSetFlags ${${SecName}} $AR_SecFlags |
| 90 | + |
| 91 | + "default_${SecName}:" |
| 92 | + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected |
| 93 | +!macroend |
| 94 | + |
| 95 | +!macro FinishSection SecName |
| 96 | + ; This macro reads section flag set by user |
| 97 | + ;Then it writes component installed flag to registry |
| 98 | + ;Input: section index constant name specified in Section command. |
| 99 | + |
| 100 | + SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags |
| 101 | + IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED} ;Checking lowest bit |
| 102 | + WriteRegDWORD HKLM "${UNINSTALL_REGISTRY_KEY}" "${SecName}_Installed" $AR_SecFlags |
| 103 | +!macroend |
| 104 | + |
| 105 | +!macro RemoveSection_CPack SecName |
| 106 | + ; This macro is used to call section's Remove_... macro |
| 107 | + ;from the uninstaller. |
| 108 | + ;Input: section index constant name specified in Section command. |
| 109 | + |
| 110 | + ;Reading component status from registry |
| 111 | + ReadRegDWORD $AR_RegFlags HKLM "${UNINSTALL_REGISTRY_KEY}" "${SecName}_Installed" |
| 112 | + IfErrors "remove_${SecName}" |
| 113 | + IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits |
| 114 | + !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags |
| 115 | + "remove_${SecName}:" |
| 116 | + !insertmacro "Remove_${${SecName}}" |
| 117 | +!macroend |
| 118 | + |
| 119 | +; Determine whether the selection of SecName changed |
| 120 | +!macro MaybeSelectionChanged SecName |
| 121 | + !insertmacro LoadVar ${SecName}_selected |
| 122 | + SectionGetFlags ${${SecName}} $R1 |
| 123 | + IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits |
| 124 | + |
| 125 | + ; See if the status has changed: |
| 126 | + IntCmp $R0 $R1 "${SecName}_unchanged" |
| 127 | + !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected |
| 128 | + |
| 129 | + IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected" |
| 130 | + !insertmacro "Deselect_required_by_${SecName}" |
| 131 | + goto "${SecName}_unchanged" |
| 132 | + |
| 133 | + "${SecName}_was_selected:" |
| 134 | + !insertmacro "Select_${SecName}_depends" |
| 135 | + |
| 136 | + "${SecName}_unchanged:" |
| 137 | +!macroend |
| 138 | +;--- End of Add/Remove macros --- |
| 139 | + |
| 140 | +Function ConditionalAddToRegistry |
| 141 | + Pop $0 |
| 142 | + Pop $1 |
| 143 | + StrCmp "$0" "" ConditionalAddToRegistry_EmptyString |
| 144 | + WriteRegStr SHCTX "${UNINSTALL_REGISTRY_KEY}" "$1" "$0" |
| 145 | + ;MessageBox MB_OK "Set Registry: '$1' to '$0'" |
| 146 | + DetailPrint "Set install registry entry: '$1' to '$0'" |
| 147 | + ConditionalAddToRegistry_EmptyString: |
| 148 | +FunctionEnd |
| 149 | + |
| 150 | +;-------------------------------- |
| 151 | +; Define some macro setting for the gui |
| 152 | +!define MUI_ABORTWARNING |
| 153 | +@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@ |
| 154 | +@CPACK_NSIS_INSTALLER_ICON_CODE@ |
| 155 | + |
| 156 | +;-------------------------------- |
| 157 | +;Pages |
| 158 | + !insertmacro MUI_PAGE_WELCOME |
| 159 | + @CPACK_NSIS_LICENSE_PAGE@ |
| 160 | + !insertmacro MUI_PAGE_DIRECTORY |
| 161 | + !define MUI_PAGE_CUSTOMFUNCTION_SHOW ${CUSTOMFUNCTION_COMPONENTS_SHOW} |
| 162 | + !define MUI_PAGE_CUSTOMFUNCTION_LEAVE ${CUSTOMFUNCTION_COMPONENTS_LEAVE} |
| 163 | + !insertmacro MUI_PAGE_COMPONENTS |
| 164 | + !insertmacro MUI_PAGE_INSTFILES |
| 165 | + !insertmacro MUI_PAGE_FINISH |
| 166 | + |
| 167 | + !define MUI_PAGE_CUSTOMFUNCTION_SHOW ${CUSTOMFUNCTION_CONFIRM_SHOW} |
| 168 | + !define MUI_PAGE_CUSTOMFUNCTION_LEAVE ${CUSTOMFUNCTION_CONFIRM_LEAVE} |
| 169 | + !insertmacro MUI_UNPAGE_CONFIRM |
| 170 | + !insertmacro MUI_UNPAGE_INSTFILES |
| 171 | + |
| 172 | +;-------------------------------- |
| 173 | +;Languages |
| 174 | + !insertmacro MUI_LANGUAGE "English" ;first language is the default language |
| 175 | + !insertmacro MUI_LANGUAGE "Afrikaans" |
| 176 | + !insertmacro MUI_LANGUAGE "Albanian" |
| 177 | + !insertmacro MUI_LANGUAGE "Arabic" |
| 178 | + !insertmacro MUI_LANGUAGE "Asturian" |
| 179 | + !insertmacro MUI_LANGUAGE "Basque" |
| 180 | + !insertmacro MUI_LANGUAGE "Belarusian" |
| 181 | + !insertmacro MUI_LANGUAGE "Bosnian" |
| 182 | + !insertmacro MUI_LANGUAGE "Breton" |
| 183 | + !insertmacro MUI_LANGUAGE "Bulgarian" |
| 184 | + !insertmacro MUI_LANGUAGE "Catalan" |
| 185 | + !insertmacro MUI_LANGUAGE "Corsican" |
| 186 | + !insertmacro MUI_LANGUAGE "Croatian" |
| 187 | + !insertmacro MUI_LANGUAGE "Czech" |
| 188 | + !insertmacro MUI_LANGUAGE "Danish" |
| 189 | + !insertmacro MUI_LANGUAGE "Dutch" |
| 190 | + !insertmacro MUI_LANGUAGE "Esperanto" |
| 191 | + !insertmacro MUI_LANGUAGE "Estonian" |
| 192 | + !insertmacro MUI_LANGUAGE "Farsi" |
| 193 | + !insertmacro MUI_LANGUAGE "Finnish" |
| 194 | + !insertmacro MUI_LANGUAGE "French" |
| 195 | + !insertmacro MUI_LANGUAGE "Galician" |
| 196 | + !insertmacro MUI_LANGUAGE "German" |
| 197 | + !insertmacro MUI_LANGUAGE "Greek" |
| 198 | + !insertmacro MUI_LANGUAGE "Hebrew" |
| 199 | + !insertmacro MUI_LANGUAGE "Hungarian" |
| 200 | + !insertmacro MUI_LANGUAGE "Icelandic" |
| 201 | + !insertmacro MUI_LANGUAGE "Indonesian" |
| 202 | + !insertmacro MUI_LANGUAGE "Irish" |
| 203 | + !insertmacro MUI_LANGUAGE "Italian" |
| 204 | + !insertmacro MUI_LANGUAGE "Japanese" |
| 205 | + !insertmacro MUI_LANGUAGE "Korean" |
| 206 | + !insertmacro MUI_LANGUAGE "Kurdish" |
| 207 | + !insertmacro MUI_LANGUAGE "Latvian" |
| 208 | + !insertmacro MUI_LANGUAGE "Lithuanian" |
| 209 | + !insertmacro MUI_LANGUAGE "Luxembourgish" |
| 210 | + !insertmacro MUI_LANGUAGE "Macedonian" |
| 211 | + !insertmacro MUI_LANGUAGE "Malay" |
| 212 | + !insertmacro MUI_LANGUAGE "Mongolian" |
| 213 | + !insertmacro MUI_LANGUAGE "Norwegian" |
| 214 | + !insertmacro MUI_LANGUAGE "NorwegianNynorsk" |
| 215 | + !insertmacro MUI_LANGUAGE "Pashto" |
| 216 | + !insertmacro MUI_LANGUAGE "Polish" |
| 217 | + !insertmacro MUI_LANGUAGE "Portuguese" |
| 218 | + !insertmacro MUI_LANGUAGE "PortugueseBR" |
| 219 | + !insertmacro MUI_LANGUAGE "Romanian" |
| 220 | + !insertmacro MUI_LANGUAGE "Russian" |
| 221 | + !insertmacro MUI_LANGUAGE "ScotsGaelic" |
| 222 | + !insertmacro MUI_LANGUAGE "Serbian" |
| 223 | + !insertmacro MUI_LANGUAGE "SerbianLatin" |
| 224 | + !insertmacro MUI_LANGUAGE "SimpChinese" |
| 225 | + !insertmacro MUI_LANGUAGE "Slovak" |
| 226 | + !insertmacro MUI_LANGUAGE "Slovenian" |
| 227 | + !insertmacro MUI_LANGUAGE "Spanish" |
| 228 | + !insertmacro MUI_LANGUAGE "SpanishInternational" |
| 229 | + !insertmacro MUI_LANGUAGE "Swedish" |
| 230 | + !insertmacro MUI_LANGUAGE "Tatar" |
| 231 | + !insertmacro MUI_LANGUAGE "Thai" |
| 232 | + !insertmacro MUI_LANGUAGE "TradChinese" |
| 233 | + !insertmacro MUI_LANGUAGE "Turkish" |
| 234 | + !insertmacro MUI_LANGUAGE "Ukrainian" |
| 235 | + !insertmacro MUI_LANGUAGE "Uzbek" |
| 236 | + !insertmacro MUI_LANGUAGE "Vietnamese" |
| 237 | + !insertmacro MUI_LANGUAGE "Welsh" |
| 238 | + |
| 239 | +;-------------------------------- |
| 240 | +; Installation types |
| 241 | +@CPACK_NSIS_INSTALLATION_TYPES@ |
| 242 | + |
| 243 | +;-------------------------------- |
| 244 | +; Component sections |
| 245 | +@CPACK_NSIS_COMPONENT_SECTIONS@ |
| 246 | +@CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@ |
| 247 | +;-------------------------------- |
| 248 | +;Installer Sections |
| 249 | + |
| 250 | +Section "-Core installation" |
| 251 | + ;Use the entire tree produced by the INSTALL target. Keep the |
| 252 | + ;list of directories here in sync with the RMDir commands below. |
| 253 | + SetOutPath "$INSTDIR" |
| 254 | + |
| 255 | + ;Store installation folder |
| 256 | + WriteRegStr SHCTX "${DLSTREAMER_REGISTRY_KEY}" "InstallDir" $INSTDIR |
| 257 | + |
| 258 | + ;Create uninstaller |
| 259 | + WriteUninstaller "$INSTDIR\@CPACK_NSIS_UNINSTALL_NAME@.exe" |
| 260 | + Push "DisplayName" |
| 261 | + Push "@CPACK_NSIS_DISPLAY_NAME@" |
| 262 | + Call ConditionalAddToRegistry |
| 263 | + Push "DisplayVersion" |
| 264 | + Push "@CPACK_PACKAGE_VERSION@" |
| 265 | + Call ConditionalAddToRegistry |
| 266 | + Push "Publisher" |
| 267 | + Push "@CPACK_PACKAGE_VENDOR@" |
| 268 | + Call ConditionalAddToRegistry |
| 269 | + Push "UninstallString" |
| 270 | + Push "$\"$INSTDIR\@CPACK_NSIS_UNINSTALL_NAME@.exe$\"" |
| 271 | + Call ConditionalAddToRegistry |
| 272 | + Push "NoRepair" |
| 273 | + Push "1" |
| 274 | + Call ConditionalAddToRegistry |
| 275 | + Push "NoModify" |
| 276 | + Push "1" |
| 277 | + Call ConditionalAddToRegistry |
| 278 | + Push "DisplayIcon" |
| 279 | + Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@" |
| 280 | + Call ConditionalAddToRegistry |
| 281 | + Push "QuietUninstallString" |
| 282 | + Push "$\"$INSTDIR\@CPACK_NSIS_UNINSTALL_NAME@.exe$\" /S" |
| 283 | + Call ConditionalAddToRegistry |
| 284 | + |
| 285 | + ${DLSTREAMER_EXTRA_INSTALL_COMMANDS} |
| 286 | +SectionEnd |
| 287 | + |
| 288 | +;--- Add/Remove callback functions: --- |
| 289 | +!macro SectionList MacroName |
| 290 | + ;This macro used to perform operation on multiple sections. |
| 291 | + ;List all of your components in following manner here. |
| 292 | +@CPACK_NSIS_COMPONENT_SECTION_LIST@ |
| 293 | +!macroend |
| 294 | + |
| 295 | +Section -FinishComponents |
| 296 | + ;Removes unselected components and writes component status to registry |
| 297 | + !insertmacro SectionList "FinishSection" |
| 298 | +SectionEnd |
| 299 | +;--- End of Add/Remove callback functions --- |
| 300 | + |
| 301 | +;-------------------------------- |
| 302 | +; Component dependencies |
| 303 | +Function .onSelChange |
| 304 | + !insertmacro SectionList MaybeSelectionChanged |
| 305 | +FunctionEnd |
| 306 | + |
| 307 | +${DLSTREAMER_DEPENDENCIES_CHECK} |
| 308 | + |
| 309 | +;-------------------------------- |
| 310 | +;Uninstaller Section |
| 311 | + |
| 312 | +Section "Uninstall" |
| 313 | + ${DLSTREAMER_EXTRA_UNINSTALL_COMMANDS} |
| 314 | + |
| 315 | + ; Removes all optional components |
| 316 | + !insertmacro SectionList "RemoveSection_CPack" |
| 317 | + |
| 318 | + ; Remove the uninstaller itself. |
| 319 | + Delete "$INSTDIR\@CPACK_NSIS_UNINSTALL_NAME@.exe" |
| 320 | + |
| 321 | + ; Remove the installation directory if it is empty. |
| 322 | + RMDir "$INSTDIR" |
| 323 | + |
| 324 | + ; Remove the registry entries. |
| 325 | + DeleteRegKey SHCTX "${UNINSTALL_REGISTRY_KEY}" |
| 326 | + DeleteRegKey SHCTX "${DLSTREAMER_REGISTRY_KEY}" |
| 327 | +SectionEnd |
| 328 | + |
| 329 | +Function .onInit |
| 330 | + ${DLSTREAMER_INSTALLER_ONINIT} |
| 331 | +FunctionEnd |
| 332 | + |
| 333 | +Function un.onInit |
| 334 | + ${DLSTREAMER_UNINSTALLER_ONINIT} |
| 335 | +FunctionEnd |
0 commit comments