Building BulbCalculator windows setup
Posted on Sat 22 February 2020 in Programming
Well, after too much time, I decided to make a binary release for windows of BulbCalculator and prepare two setups, one for 64 bit and one for 32 bit (if someone still use it).
After trying to use the Qt Installation framework, failing to build a working setup, I switched back to NSIS, which was used to build a very old setup for bulbcalculator.
After some tweaking of the old .nsi file, I got two more or less working setup for both win32 and win64.
But how to do it ?
Well, the procedure is reasonably easy.
The first step is to build the package for the target platform (you don't say, right ?). After this, what you need to do is to copy all the dependencies of your executable. To do this there is a nice program to find (almost) all of them: windeployqt. Just call it with your executable as argument and it will copy all the needed modules and Dll in the executable directory. Please not that you need to use the correct (32 or 64 bit) version, else it will copy the wrong files.
After that I just moved all the files to a working directory, just for convenience, and tried to run from here. This allow to discover if there are some other missing files. Onche the executable works fine, you are ready to build the setup package.
To do this, you need to write a NSIS script to look something like this:
bulbcalculator_setup64.nsi
;BulbCalculator Installer
!define PRODUCT_NAME "BulbCalculator"
!define PRODUCT_VERSION "3.0.0"
!define PRODUCT_DIR_REGKEY "Software\${PRODUCT_NAME}"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "bulbcalculator-${PRODUCT_VERSION}-win64.exe"
SetCompressor lzma
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKCU "${PRODUCT_DIR_REGKEY}" ""
!include "MUI.nsh"
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_LICENSE "COPYING"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\bulbcalculator.exe"
!define MUI_FINISHPAGE_LINK "Visit the BulbCalculator website"
!define MUI_FINISHPAGE_LINK_LOCATION "http://www.bulbcalculator.com/"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "BulbCalculator" SecBulbCalculator
SectionIn RO
SetOutPath "$INSTDIR"
WriteRegStr HKCU "${PRODUCT_DIR_REGKEY}" "" $INSTDIR
File setup_64\bulbcalculator.exe
File setup_64\*.dll
File COPYING
File /r setup_64\iconengines
File /r setup_64\styles
File /r setup_64\translations
File /r setup_64\imageformats
File /r setup_64\platforms
File /r setup_64\printsupport
WriteUninstaller "$INSTDIR\uninstall.exe"
SectionEnd
Section "Create Desktop Shortcut" DescShortcut
CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\bulbcalculator.exe" "" "$INSTDIR\share\images\bulbcalculator.ico"
SectionEnd
Section "Start Menu Shortcuts" SecShortcut
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\BulbCalculator.lnk" "$INSTDIR\bulbcalculator.exe" "" "$INSTDIR\share\images\bulbcalculator.ico"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecBulbCalculator} "Installs BulbCalculator."
!insertmacro MUI_DESCRIPTION_TEXT ${DescShortcut} "Installs BulbCalculator."
!insertmacro MUI_DESCRIPTION_TEXT ${SecShortcut} "Adds share to your start menu for easy access."
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Section "Uninstall"
DeleteRegKey HKCR "BulbCalculator.blb"
DeleteRegKey HKCR ".blb"
DeleteRegKey HKCU "${PRODUCT_DIR_REGKEY}"
RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
Delete "$INSTDIR\bulbcalculator.exe"
Delete "$INSTDIR\*.dll"
Delete "$INSTDIR\ChangeLog"
Delete "$INSTDIR\COPYING"
Delete "$INSTDIR\README"
RMDir /r "$INSTDIR\iconengines"
RMDir /r "$INSTDIR\styles"
RMDir /r "$INSTDIR\translations"
RMDir /r "$INSTDIR\imageformats"
RMDir /r "$INSTDIR\platforms"
RMDir /r "$INSTDIR\printsupport"
Delete "$INSTDIR\uninstall.exe"
RMDir "$INSTDIR"
SectionEnd
This script refer to the 64 bit version, but it is the same for the 32 bit, just some different path.
After that, you just need to compile the NSIS script and if all goes well, you will obtain a setup to test.