Skip to content

Commit

Permalink
[CMake] Move all "portable" build handling to CPack
Browse files Browse the repository at this point in the history
Define CPACK_WZ_PORTABLE=ON when calling CPack to package a portable NSIS installer.
  • Loading branch information
past-due committed Jun 10, 2021
1 parent bb09510 commit 3f9df62
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ include(CMakeDependentOption)

OPTION(ENABLE_DOCS "Enable documentation generation" ON)
OPTION(ENABLE_NLS "Native Language Support" ON)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(_enableOSOptions_Windows TRUE)
endif()
cmake_dependent_option(WZ_PORTABLE "Portable build (Windows-only)" ON "_enableOSOptions_Windows" OFF)
unset(_enableOSOptions_Windows)
OPTION(WZ_ENABLE_WARNINGS "Enable (additional) warnings" OFF)
OPTION(WZ_ENABLE_WARNINGS_AS_ERRORS "Enable compiler flags that treat (most) warnings as errors" ON)
OPTION(WZ_ENABLE_BACKEND_VULKAN "Enable Vulkan backend" ON)
Expand All @@ -32,12 +27,6 @@ set(WZ_DISTRIBUTOR "UNKNOWN" CACHE STRING "Name of distributor compiling this pa

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Handle options
if(WZ_PORTABLE AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
message( WARNING "Portable build is only supported on Windows; Ignoring WZ_PORTABLE option" )
unset(WZ_PORTABLE CACHE)
endif()

# Disallow in-source builds
include(DisallowInSourceBuilds)

Expand Down
22 changes: 10 additions & 12 deletions pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ set(CPACK_COMPONENT_FONTS_REQUIRED ON)
set(CPACK_COMPONENT_FONTS_DESCRIPTION "Fonts")
set(CPACK_COMPONENT_FONTS_GROUP "CoreGroup")

set(CPACK_COMPONENT_PORTABLECONFIG_DISPLAY_NAME "Portable Configuration")
set(CPACK_COMPONENT_PORTABLECONFIG_DESCRIPTION "Portable Configuration")
set(CPACK_COMPONENT_PORTABLECONFIG_GROUP "CoreGroup")
set(CPACK_COMPONENT_PORTABLECONFIG_HIDDEN ON)

set(CPACK_COMPONENT_MANPAGES_GROUP "CoreGroup")

set(CPACK_COMPONENT_GROUP_COREGROUP_DISPLAY_NAME "Core files")
Expand Down Expand Up @@ -155,19 +160,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
endif()

set(PACKAGE "${_warzone_target_output_name}")
if(WZ_PORTABLE)
set(PACKAGE_NAME "Warzone 2100 Portable")

# For the portable build, install `launch_warzone.bat` in the base folder
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/nsis/launch_warzone.bat"
COMPONENT Core DESTINATION "."
)
else()
set(PACKAGE_NAME "Warzone 2100")
endif()
set(CPACK_NSIS_DISPLAY_NAME PACKAGE_NAME)
set(CPACK_NSIS_PACKAGE_NAME PACKAGE_NAME)
# For the portable build, install `launch_warzone.bat` in the base folder
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/nsis/launch_warzone.bat"
COMPONENT PortableConfig DESTINATION "."
)

set(SOURCE_DIR "${CMAKE_SOURCE_DIR}")
set(BUILD_DIR "${CMAKE_BINARY_DIR}")
Expand Down
16 changes: 16 additions & 0 deletions pkg/CPackConfigVersion.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,25 @@ endif()

execute_process(COMMAND ${CMAKE_COMMAND} -E echo "++Setting CPACK_PACKAGE_VERSION: ${CPACK_PACKAGE_VERSION}")

if(CPACK_WZ_PORTABLE)
list(APPEND CPACK_COMPONENTS_ALL PortableConfig)
else()
list(REMOVE_ITEM CPACK_COMPONENTS_ALL PortableConfig)
endif()

if(CPACK_GENERATOR MATCHES "NSIS")
# For the NSIS installer

if(CPACK_WZ_PORTABLE)
set(PACKAGE_NAME "Warzone 2100 Portable")
else()
set(PACKAGE_NAME "Warzone 2100")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "++PACKAGE_NAME: ${PACKAGE_NAME}")
set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
set(CPACK_NSIS_DISPLAY_NAME "${PACKAGE_NAME}")
set(CPACK_NSIS_PACKAGE_NAME "${PACKAGE_NAME}")

# Compute the installer version #
set(INSTALLER_VERSION "${CPACK_PACKAGE_VERSION}.0" CACHE STRING "NSIS version")

Expand Down
4 changes: 0 additions & 4 deletions pkg/nsis/NSIS.definitions.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
!define PACKAGE "@PACKAGE@"
!if "@WZ_PORTABLE@" == "ON"
!define PORTABLE "ON"
!endif
!define PACKAGE_NAME "@PACKAGE_NAME@"
!define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
!define TOP_SRCDIR "@SOURCE_DIR@"
!define TOP_BUILDDIR "@BUILD_DIR@"
Expand Down
4 changes: 4 additions & 0 deletions pkg/nsis/NSIS.version.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
!if "@CPACK_WZ_PORTABLE@" == "ON"
!define PORTABLE "ON"
!endif
!define PACKAGE_NAME "@PACKAGE_NAME@"
!define PACKAGE_VERSION "@PACKAGE_VERSION@"
!define VERSIONNUM "@INSTALLER_VERSION@"
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,8 @@ endif()
# Install
install(TARGETS warzone2100 COMPONENT Core DESTINATION "${WZ_APP_INSTALL_DEST}")

if(WZ_PORTABLE)
install(FILES "${CMAKE_SOURCE_DIR}/pkg/portable.in" COMPONENT Core DESTINATION "${WZ_APP_INSTALL_DEST}" RENAME ".portable")
endif()
# For Portable packages only, copy the ".portable" file that triggers portable mode (Windows-only)
install(FILES "${CMAKE_SOURCE_DIR}/pkg/portable.in" COMPONENT PortableConfig DESTINATION "${WZ_APP_INSTALL_DEST}" RENAME ".portable")

#####################
# Installing Required Runtime Dependencies
Expand Down

0 comments on commit 3f9df62

Please sign in to comment.