summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie Shprung <lshprung@tutanota.com>2024-07-25 16:06:34 -0400
committerLouie S <louie@example.com>2024-07-25 16:59:51 -0400
commit02add8bb097104dc02066fe390ec01465910fc76 (patch)
tree8b71cb1ea4f1fd7a5a7ff8f3e89f97b8b4d78900
parentc34930425fadfc4083067b9306159cd8e8ecf6c6 (diff)
Use installer.nsi instead of cpack -G NSISHEADmaster
-rw-r--r--CMakeLists.txt99
-rw-r--r--README.md2
-rw-r--r--nsis/installer.nsi.in102
3 files changed, 126 insertions, 77 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35125b9..a0d70d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ project(assignment-list VERSION 0.0.${patchdate} HOMEPAGE_URL "https://github.co
set(ORGANIZATION_NAME "assignment-list-qt")
set(PROJECT_TITLE "Assignment List")
+set(NSIS_PRODUCT_VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}.0")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED)
@@ -36,6 +37,7 @@ option(IS_RELEASE "Set if this is a release candidate" no)
if(IS_RELEASE)
unset(CMAKE_PROJECT_VERSION_PATCH)
message("Marked as release: excluding patch in version number")
+ set(NSIS_PRODUCT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.0.0")
endif()
set(qt_components "Core" "Gui" "Sql" "UiTools" "Widgets")
@@ -130,6 +132,9 @@ set(project_sources_full
)
configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
+if(CMAKE_SYSTEM MATCHES "Windows*")
+ configure_file(nsis/installer.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/installer.nsi @ONLY)
+endif()
#add_executable(assignment-list
# ${project_sources_full}
@@ -165,14 +170,11 @@ target_link_libraries(assignment-list PUBLIC ${qt_libraries})
# Installation
include(GNUInstallDirs)
-# Do not install normally if on Windows (we will install to / rather than /bin of install location)
-if(NOT CMAKE_SYSTEM MATCHES "Windows*")
- install(TARGETS assignment-list
- BUNDLE DESTINATION .
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
-endif()
+install(TARGETS assignment-list
+ BUNDLE DESTINATION .
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
# install desktop entry and icon
if(CMAKE_SYSTEM MATCHES "Linux.*")
@@ -197,74 +199,19 @@ set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(CPACK_PACKAGE_CONTACT "Louie Shprung <lshprung@tutanota.com>")
set(CPACK_SOURCE_IGNORE_FILES "/\.git.*;/\.cache;/build;/compile_commands\.json$;/config\.h$;/data/assignment-list\.desktop$")
-## CPack NSIS configuration
-## Allow regular users to run installer
-#set(CPACK_NSIS_DEFINES "RequestExecutionLevel user")
-## Set installer icons
-#set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/data/assignment-list.ico")
-#set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/data/assignment-list.ico")
-## Install a StartMenu Shortcut
-#set(CPACK_NSIS_CREATE_ICONS_EXTRA
-# "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\${PROJECT_TITLE}.lnk' '$INSTDIR\\\\assignment-list.exe'"
-#)
-#set(CPACK_NSIS_DELETE_ICONS_EXTRA
-# "Delete '$SMPROGRAMS\\\\$START_MENU\\\\${PROJECT_TITLE}.lnk'"
-#)
-## Set FinishPage
-#set(CPACK_NSIS_EXECUTABLES_DIRECTORY "/")
-#set(CPACK_NSIS_MUI_FINISHPAGE_RUN "assignment-list.exe")
-## Based on https://stackoverflow.com/q/69139412
-#if(CMAKE_SYSTEM MATCHES "Windows*")
-# set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_TITLE})
-# include(InstallRequiredSystemLibraries)
-# find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
-# add_custom_command(TARGET assignment-list POST_BUILD
-# COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/qtDeploy/
-# COMMAND ${WINDEPLOYQT_EXECUTABLE}
-# --dir ${CMAKE_BINARY_DIR}/qtDeploy $<TARGET_FILE:assignment-list>
-# )
-## Install dlls
-# install(CODE "set(CMAKE_MINGW_SYSTEM_LIBRARY_PATH \"${CMAKE_FIND_ROOT_PATH}/bin/\")")
-# install(
-# DIRECTORY ${CMAKE_BINARY_DIR}/qtDeploy/
-# DESTINATION /
-# FILES_MATCHING PATTERN "*.*"
-# )
-## FIXME this only works on MSYS2 with NO flexibility!
-# find_file(SQLITE_DLL "libsqlite3-0.dll" PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} ${CMAKE_MINGW_SYSTEM_LIBRARY_PATH} NO_DEFAULT_PATH)
-# target_link_libraries(assignment-list PRIVATE ${SQLITE_DLL})
-# install(FILES ${SQLITE_DLL} DESTINATION /)
-## Based on https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782
-## and https://discourse.cmake.org/t/get-runtime-dependencies-does-not-seem-to-work-with-mingw/2239
-# install(TARGETS assignment-list
-# RUNTIME_DEPENDENCIES
-# PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
-# POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
-# DIRECTORIES ${CMAKE_SYSTEM_LIBRARY_PATH} ${CMAKE_MINGW_SYSTEM_LIBRARY_PATH}
-# DESTINATION /
-# )
-# #install(CODE [[
-# # file(GET_RUNTIME_DEPENDENCIES
-# # LIBRARIES "$<TARGET_FILE:assignment-list>"
-# # RESOLVED_DEPENDENCIES_VAR _r_deps
-# # UNRESOLVED_DEPENDENCIES_VAR _u_deps
-# # DIRECTORIES ${DEPENDENCY_PATHS}
-# # PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
-# # POST_EXCLUDE_REGEXES" ".*system32/.*\\.dll"
-# # )
-# # foreach(_file ${_r_deps})
-# # file(INSTALL
-# # DESTINATION "${CMAKE_INSTALL_BINDIR}"
-# # TYPE SHARED_LIBRARY
-# # FILES "${_file}"
-# # )
-# # endforeach()
-# # list(LENGTH _u_deps _u_length)
-# # if("${_u_length}" GREATER 0)
-# # message(WARNING "Unresolved dependencies detected!")
-# # endif()
-# #]])
-#endif()
+# Get Windows dependencies/dlls for nsis
+# Based on https://stackoverflow.com/q/69139412
+if(CMAKE_SYSTEM MATCHES "Windows*")
+ set(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_TITLE})
+ include(InstallRequiredSystemLibraries)
+ find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
+ add_custom_command(TARGET assignment-list POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/qtDeploy/
+ COMMAND ${WINDEPLOYQT_EXECUTABLE}
+ --dir ${CMAKE_BINARY_DIR}/qtDeploy
+ --compiler-runtime $<TARGET_FILE:assignment-list>
+ )
+endif()
# CPack Deb configuration
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
diff --git a/README.md b/README.md
index 1c9df51..5303dc3 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,7 @@ Building installer packages using CPack is also supported for the following pack
- DEB (`cpack -G DEB`)
- RPM (`cpack -G RPM`)
-- Windows Installer (`cpack -G NSIS`)
+- Windows Installer (`makensis installer.nsi`)
### Caveats
diff --git a/nsis/installer.nsi.in b/nsis/installer.nsi.in
new file mode 100644
index 0000000..d731007
--- /dev/null
+++ b/nsis/installer.nsi.in
@@ -0,0 +1,102 @@
+;-------------------------------------------------------------------------------
+; Includes
+!include "MUI2.nsh"
+!include "LogicLib.nsh"
+!include "WinVer.nsh"
+!include "x64.nsh"
+
+;-------------------------------------------------------------------------------
+; Constants
+!define PRODUCT_NAME "@PROJECT_TITLE@"
+!define PRODUCT_DESCRIPTION "TODO"
+!define COPYRIGHT "GNU GPLv3"
+!define PRODUCT_VERSION "@NSIS_PRODUCT_VERSION@"
+!define SETUP_VERSION 1.0.0.0
+
+;-------------------------------------------------------------------------------
+; Attributes
+Name "@PROJECT_TITLE@"
+OutFile "@PROJECT_TITLE@ @NSIS_PRODUCT_VERSION@ Setup.exe"
+InstallDir "$PROGRAMFILES\@PROJECT_TITLE@"
+InstallDirRegKey HKCU "Software\Louie S\@PROJECT_TITLE@" ""
+RequestExecutionLevel user ; user|highest|admin
+
+;-------------------------------------------------------------------------------
+; Version Info
+VIProductVersion "${PRODUCT_VERSION}"
+VIAddVersionKey "ProductName" "${PRODUCT_NAME}"
+VIAddVersionKey "ProductVersion" "${PRODUCT_VERSION}"
+VIAddVersionKey "FileDescription" "${PRODUCT_DESCRIPTION}"
+VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
+VIAddVersionKey "FileVersion" "${SETUP_VERSION}"
+
+;-------------------------------------------------------------------------------
+; Modern UI Appearance
+;!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
+!define MUI_ICON "..\data\assignment-list.ico"
+!define MUI_UNIICON "..\data\assignment-list.ico"
+!define MUI_HEADERIMAGE
+;!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
+;!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange.bmp"
+!define MUI_FINISHPAGE_NOAUTOCLOSE
+!define MUI_FINISHPAGE_RUN "@PROJECT_NAME@.exe" ; FIXME Currently does not work
+!define MUI_FINISHPAGE_SHOWREADME ""
+!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
+!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
+!define MUI_FINISHPAGE_SHOWREADME_FUNCTION installDesktopShortcut
+
+;-------------------------------------------------------------------------------
+; Installer Pages
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
+!insertmacro MUI_PAGE_COMPONENTS
+!insertmacro MUI_PAGE_DIRECTORY
+Var StartMenuFolder
+!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
+!insertmacro MUI_PAGE_INSTFILES
+!insertmacro MUI_PAGE_FINISH
+
+;-------------------------------------------------------------------------------
+; Uninstaller Pages
+!insertmacro MUI_UNPAGE_WELCOME
+!insertmacro MUI_UNPAGE_CONFIRM
+!insertmacro MUI_UNPAGE_INSTFILES
+!insertmacro MUI_UNPAGE_FINISH
+
+;-------------------------------------------------------------------------------
+; Languages
+!insertmacro MUI_LANGUAGE "English"
+
+;-------------------------------------------------------------------------------
+; Installer Sections
+Section "My Application" MyApp
+ SetOutPath $INSTDIR
+ File "@CMAKE_CURRENT_BINARY_DIR@\@PROJECT_NAME@.exe"
+ File /r "qtDeploy\*.*" ; FIXME need to include additional dlls to make fully portable
+ ;File "Readme.txt" ; TODO consider breaking into bin/ so that README can be included in the base, or in doc/
+ !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
+ CreateDirectory "$SMPROGRAMS\$StartMenuFolder\"
+ CreateShortCut "$SMPROGRAMS\$StartMenuFolder\@PROJECT_TITLE@.lnk" "$INSTDIR\@PROJECT_NAME@.exe"
+ CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
+ !insertmacro MUI_STARTMENU_WRITE_END
+ WriteUninstaller "$INSTDIR\Uninstall.exe"
+SectionEnd
+
+Function installDesktopShortcut
+ CreateShortCut "$Desktop\@PROJECT_TITLE@.lnk" "$INSTDIR\@PROJECT_NAME@.exe"
+FunctionEnd
+
+;-------------------------------------------------------------------------------
+; Uninstaller Sections
+Section "Uninstall"
+ #Delete "$INSTDIR\@PROJECT_NAME@.exe"
+ #Delete "$INSTDIR\*.dll"
+ #Delete "$INSTDIR\Uninstall.exe"
+ Delete "$Desktop\@PROJECT_TITLE@.lnk"
+ !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
+ Delete "$SMPROGRAMS\$StartMenuFolder\@PROJECT_TITLE@.lnk"
+ Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk"
+ RMDir "$SMPROGRAMS\$StartMenuFolder"
+ RMDir /r "$INSTDIR"
+ ;DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
+SectionEnd