cmake_minimum_required ( VERSION 3.13 )
if ( POLICY CMP0092 )
cmake_policy ( SET CMP0092 NEW )
endif ( )
if ( POLICY CMP0083 )
cmake_policy ( SET CMP0083 NEW )
endif ( )
if ( POLICY CMP0111 )
cmake_policy ( SET CMP0111 NEW )
endif ( )
# Projects added via `add_subdirectory` or `FetchContent` may have a lower
# `cmake_minimum_required` than we set here. Set policies that we require
# to their new value so that they still apply.
set ( CMAKE_POLICY_DEFAULT_CMP0069 NEW )
set ( CMAKE_POLICY_DEFAULT_CMP0077 NEW )
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist" )
message ( "-- Detected a source distribution with the required FetchContent dependencies and devilutionx.mpq included" )
set ( SRC_DIST ON )
add_subdirectory ( dist )
endif ( )
if ( ${ CMAKE_SOURCE_DIR } STREQUAL ${ CMAKE_BINARY_DIR } )
message ( WARNING [[In-source build detected, please eg. create a new directory and use `cmake ..`]] )
endif ( )
include ( CMakeDependentOption )
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" )
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake/finders" )
include ( functions/genex )
DEBUG_OPTION ( ASAN "Enable address sanitizer" )
DEBUG_OPTION ( UBSAN "Enable undefined behaviour sanitizer" )
option ( TSAN "Enable thread sanitizer (not compatible with ASAN=ON)" OFF )
DEBUG_OPTION ( DEBUG "Enable debug mode in engine" )
option ( GPERF "Build with GPerfTools profiler" OFF )
cmake_dependent_option ( GPERF_HEAP_FIRST_GAME_ITERATION "Save heap profile of the first game iteration" OFF "GPERF" OFF )
option ( BUILD_TESTING "Build tests." ON )
option ( DISABLE_LTO "Disable link-time optimization (by default enabled in release mode)" OFF )
cmake_dependent_option ( PIE "Generate position-independent code" OFF "BUILD_TESTING" ON )
option ( MACOSX_STANDALONE_APP_BUNDLE "Generate a portable app bundle to use on other devices (requires sudo)" OFF )
option ( USE_SDL1 "Use SDL1.2 instead of SDL2" OFF )
option ( NONET "Disable network support" OFF )
RELEASE_OPTION ( DEVILUTIONX_STATIC_CXX_STDLIB "Link C++ standard library statically (if available)" )
cmake_dependent_option ( DISABLE_TCP "Disable TCP multiplayer option" OFF "NOT NONET" ON )
cmake_dependent_option ( DISABLE_ZERO_TIER "Disable ZeroTier multiplayer option" OFF "NOT NONET" ON )
cmake_dependent_option ( PACKET_ENCRYPTION "Encrypt network packets" ON "NOT NONET" OFF )
option ( NOSOUND "Disable sound support" OFF )
option ( ENABLE_CODECOVERAGE "Instrument code for code coverage (only enabled with BUILD_TESTING)" OFF )
option ( DISCORD_INTEGRATION "Build with Discord SDK for rich presence support" OFF )
option ( DISABLE_STREAMING_MUSIC "Disable streaming music (to work around broken platform implementations)" OFF )
mark_as_advanced ( DISABLE_STREAMING_MUSIC )
option ( DISABLE_STREAMING_SOUNDS "Disable streaming sounds (to work around broken platform implementations)" OFF )
mark_as_advanced ( DISABLE_STREAMING_SOUNDS )
option ( STREAM_ALL_AUDIO "Stream all the audio. For extremely RAM-constrained platforms." )
mark_as_advanced ( STREAM_ALL_AUDIO )
option ( DEVILUTIONX_RESAMPLER_SPEEX "Build with Speex resampler" ON )
option ( DEVILUTIONX_RESAMPLER_SDL "Build with SDL resampler" ON )
option ( DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT "Whether to use a lookup table for transparency blending with black. This improves performance of blending transparent black overlays, such as quest dialog background, at the cost of 128 KiB of RAM." ON )
cmake_dependent_option ( DEVILUTIONX_DISABLE_RTTI "Disable RTTI" ON "NONET" OFF )
cmake_dependent_option ( DEVILUTIONX_DISABLE_EXCEPTIONS "Disable exceptions" ON "NONET" OFF )
if ( TSAN )
set ( ASAN OFF )
endif ( )
# By default, devilutionx.mpq is built only if smpq is installed.
if ( NOT DEFINED BUILD_ASSETS_MPQ AND NOT SRC_DIST )
find_program ( SMPQ smpq )
elseif ( BUILD_ASSETS_MPQ )
find_program ( SMPQ smpq REQUIRED )
endif ( )
if ( SMPQ )
set ( _has_smpq ON )
else ( )
set ( _has_smpq OFF )
endif ( )
option ( BUILD_ASSETS_MPQ "If true, assets are packaged into devilutionx.mpq." ${ _has_smpq } )
# The gettext[tools] package takes a very long time to install
if ( CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg.cmake$" )
option ( USE_GETTEXT_FROM_VCPKG "Add vcpkg dependency for gettext[tools] for compiling translations" OFF )
endif ( )
RELEASE_OPTION ( CPACK "Configure CPack" )
# These must be included after the options above but before the `project` call.
include ( VcPkgManifestFeatures )
# Set up the `project` early so that properties such as `TARGET_SUPPORTS_SHARED_LIBS` are defined.
if ( NOT VERSION_NUM )
include ( functions/git )
get_git_tag ( VERSION_NUM )
if ( NOT "${VERSION_NUM}" STREQUAL "" )
string ( REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${ VERSION_NUM } )
endif ( )
if ( NOT VERSION_SUFFIX )
get_git_commit_hash ( GIT_COMMIT_HASH )
set ( VERSION_SUFFIX "${GIT_COMMIT_HASH}" )
endif ( )
endif ( )
if ( NOT VERSION_SUFFIX )
set ( VERSION_SUFFIX "debug" )
endif ( )
if ( VERSION_NUM MATCHES untagged )
project ( DevilutionX LANGUAGES C CXX )
else ( )
project ( DevilutionX
V E R S I O N $ { V E R S I O N _ N U M }
L A N G U A G E S C C X X )
endif ( )
set ( PROJECT_VERSION_WITH_SUFFIX "${PROJECT_VERSION}$<$<CONFIG:Debug>:-${VERSION_SUFFIX}>" )
if ( MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT DISABLE_LTO )
# Work around MSVC + CMake bug when LTO is enabled.
# See https://github.com/diasurgical/devilutionX/issues/3778
# and https://gitlab.kitware.com/cmake/cmake/-/issues/23035
set ( BUILD_TESTING OFF )
endif ( )
# This built-in CMake module adds a BUILD_TESTING option (ON by default).
# Must be included in the top-level `CMakeLists.txt` after calling `project`.
# Because we must include `VcPkgManifestFeatures` before the `project` call,
# we add a BUILD_TESTING option ourselves above as well.
include ( CTest )
# Platform definitions can override options and we want `cmake_dependent_option` to see the effects,
# so ideally we would include Platforms.cmake before definining the options.
#
# However, `Platforms` require `project` to have been called (to get access to toolchain defs),
# but `project` must be called after `VcPkgManifestFeatures`, and `VcPkgManifestFeatures` need
# to be after the options.
include ( Platforms )
# Note: `CMAKE_CROSSCOMPILING` is only available after the `project` call.
if ( CMAKE_CROSSCOMPILING )
set ( BUILD_TESTING OFF )
endif ( )
# Recalculate the dependent options after including the Platforms:
if ( BUILD_TESTING )
# For tests, we build a libdevilutionx.so shared library.
# When this libdevilutionx.so is linked against certain static libraries,
# they must be compiled with `-fPIC`.
set ( PIE ON )
endif ( )
if ( PIE )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
endif ( )
if ( NONET )
set ( DISABLE_TCP ON )
set ( DISABLE_ZERO_TIER ON )
set ( DISABLE_RTTI ON )
set ( DISABLE_EXCEPTIONS ON )
set ( PACKET_ENCRYPTION OFF )
endif ( )
if ( USE_SDL1 )
set ( DEVILUTIONX_RESAMPLER_SDL OFF )
endif ( )
if ( DEVILUTIONX_RESAMPLER_SPEEX )
list ( APPEND _resamplers Speex )
endif ( )
if ( DEVILUTIONX_RESAMPLER_SDL )
list ( APPEND _resamplers SDL )
endif ( )
list ( GET _resamplers 0 _default_resampler )
set ( DEVILUTIONX_DEFAULT_RESAMPLER ${ _default_resampler } CACHE STRING "Default resampler" )
set_property ( CACHE DEVILUTIONX_DEFAULT_RESAMPLER PROPERTY STRINGS ${ _resamplers } )
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
endif ( )
if ( DEVILUTIONX_DISABLE_RTTI )
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti" )
elseif ( MSVC )
string ( REGEX REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
endif ( )
endif ( )
if ( DEVILUTIONX_DISABLE_EXCEPTIONS )
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions" )
elseif ( MSVC )
string ( REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
endif ( )
endif ( )
# Remove unused symbols in non-debug mode.
# This is useful even with LTO (-84 KiB with MinSizeRel).
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
# For some reason, adding to CMAKE_CXX_FLAGS results in a slightly smaller
# binary than using `add_compile/link_options`
set ( _extra_flags "-ffunction-sections -fdata-sections -Wl,--gc-sections" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_extra_flags}" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${_extra_flags}" )
set ( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${_extra_flags}" )
endif ( )
# Not a genexp because CMake doesn't support it
# https://gitlab.kitware.com/cmake/cmake/-/issues/20546
if ( NOT DISABLE_LTO )
# LTO if supported:
include ( CheckIPOSupported )
check_ipo_supported ( RESULT is_ipo_supported OUTPUT lto_error )
if ( is_ipo_supported )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON )
endif ( )
endif ( )
if ( GPERF )
set ( DEVILUTIONX_STATIC_CXX_STDLIB OFF )
if ( GPERF_HEAP_FIRST_GAME_ITERATION )
set ( GPERF_HEAP_MAIN ON )
endif ( )
# Compile with information about file and line numbers for everything
# even in non-Debug build types.
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
add_compile_options ( "$<$<NOT:$<CONFIG:Debug>>:-g2>" )
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
# Use the more size-efficient `-gmlt` option on clang.
add_compile_options ( "$<$<NOT:$<CONFIG:Debug>>:-gmlt>" )
endif ( )
endif ( )
set ( CMAKE_CXX_STANDARD 20 )
set ( CMAKE_CXX_EXTENSIONS OFF )
set ( CMAKE_CXX_STANDARD_REQUIRED OFF )
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON ) # for clang-tidy
set ( CMAKE_THREAD_PREFER_PTHREAD ON )
set ( THREADS_PREFER_PTHREAD_FLAG ON )
find_package ( Threads REQUIRED )
# Dependencies must be included after Platforms.
include ( Dependencies )
add_subdirectory ( Source )
set ( BIN_TARGET devilutionx )
if ( NINTENDO_3DS )
set ( BIN_TARGET ${ BIN_TARGET } .elf )
endif ( )
if ( ANDROID )
add_library ( ${ BIN_TARGET } SHARED Source/main.cpp )
elseif ( UWP_LIB )
add_custom_target ( ${ BIN_TARGET } ) # we only need libdevilutionx
else ( )
add_executable ( ${ BIN_TARGET }
WIN32
M A C O S X _ B U N D L E
S o u r c e / m a i n . c p p
P a c k a g i n g / w i n d o w s / d e v i l u t i o n x . e x e . m a n i f e s t
P a c k a g i n g / w i n d o w s / d e v i l u t i o n x . r c
P a c k a g i n g / a p p l e / A p p I c o n . i c n s
P a c k a g i n g / a p p l e / L a u n c h S c r e e n . s t o r y b o a r d )
endif ( )
if ( NOT UWP_LIB )
target_link_libraries ( ${ BIN_TARGET } PRIVATE libdevilutionx )
endif ( )
if ( GPERF )
target_link_libraries ( ${ BIN_TARGET } PUBLIC ${ GPERFTOOLS_LIBRARIES } )
endif ( )
# Must be included after `BIN_TARGET` and `libdevilutionx` are defined.
include ( Assets )
if ( EMSCRIPTEN )
target_link_options ( ${ BIN_TARGET } PRIVATE --preload-file assets )
endif ( )
if ( NOT USE_SDL1 AND NOT UWP_LIB )
target_link_libraries ( ${ BIN_TARGET } PUBLIC ${ SDL2_MAIN } )
endif ( )
if ( BUILD_TESTING )
add_subdirectory ( test )
endif ( )
include ( functions/set_relative_file_macro )
set_relative_file_macro ( ${ BIN_TARGET } )
if ( APPLE )
set_source_files_properties ( "./Packaging/apple/AppIcon.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
set ( MACOSX_BUNDLE_GUI_IDENTIFIER com.diasurgical.devilutionx )
set ( MACOSX_BUNDLE_COPYRIGHT Unlicense )
set ( MACOSX_BUNDLE_BUNDLE_NAME devilutionx )
set ( MACOSX_BUNDLE_DISPLAY_NAME DevilutionX )
set ( MACOSX_BUNDLE_INFO_STRING ${ PROJECT_VERSION } )
set ( MACOSX_BUNDLE_BUNDLE_VERSION ${ PROJECT_VERSION } )
set ( MACOSX_BUNDLE_SHORT_VERSION_STRING ${ PROJECT_VERSION } )
set ( MACOSX_BUNDLE_LONG_VERSION_STRING "Version ${PROJECT_VERSION}" )
if ( IOS )
set_target_properties ( ${ BIN_TARGET } PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" )
set ( CMAKE_OSX_DEPLOYMENT_TARGET "9.0" )
else ( )
set ( CMAKE_OSX_DEPLOYMENT_TARGET "10.12.0" )
endif ( )
set_target_properties ( ${ BIN_TARGET } PROPERTIES MACOSX_BUNDLE_ICON_FILE "AppIcon.icns" )
set_target_properties ( ${ BIN_TARGET } PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Packaging/apple/Info.plist" )
install ( TARGETS ${ BIN_TARGET } DESTINATION ./ )
if ( MACOSX_STANDALONE_APP_BUNDLE )
install ( CODE "
include ( BundleUtilities )
fixup_bundle ( ${ CMAKE_BINARY_DIR } / ${ MACOSX_BUNDLE_BUNDLE_NAME } .app \"\" \"\")
"
C O M P O N E N T R u n t i m e )
endif ( )
find_library ( COREFOUNDATION_LIBRARY CoreFoundation )
if ( COREFOUNDATION_LIBRARY )
target_link_libraries ( libdevilutionx PUBLIC "${COREFOUNDATION_LIBRARY}" )
target_compile_definitions ( libdevilutionx PRIVATE USE_COREFOUNDATION )
endif ( )
set ( MACOSX_BUNDLE_LONG_VERSION_STRING "Version ${PROJECT_VERSION}" )
set ( CPACK On )
endif ( )
if ( NINTENDO_SWITCH )
set ( APP_ROMFS "${CMAKE_BINARY_DIR}/romfs" )
add_custom_target ( romfs_directory
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { A P P _ R O M F S } )
add_custom_target ( romfs_files
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { D E V I L U T I O N X _ M P Q } $ { A P P _ R O M F S }
D E P E N D S $ { D E V I L U T I O N X _ M P Q } )
# the romfs_directory target will create this directory at build time,
# but the nx_create_nro function requires it to also exist at configure time
file ( MAKE_DIRECTORY ${ APP_ROMFS } )
add_dependencies ( romfs_files romfs_directory devilutionx_mpq )
nx_generate_nacp ( ${ BIN_TARGET } .nacp
N A M E " D e v i l u t i o n X "
A U T H O R " D e v i l u t i o n T e a m "
V E R S I O N " $ { P R O J E C T _ V E R S I O N } "
)
nx_create_nro ( ${ BIN_TARGET }
N A C P $ { B I N _ T A R G E T } . n a c p
I C O N " $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / s w i t c h / i c o n . j p g "
R O M F S $ { A P P _ R O M F S }
)
add_dependencies ( ${ BIN_TARGET } _nro romfs_files )
endif ( )
if ( VITA )
set ( VITA_APP_NAME "devilutionX" )
set ( VITA_TITLEID "DVLX00001" )
set ( VITA_VERSION "01.00" )
set ( VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1" )
set ( VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d ATTRIBUTE2=12" )
vita_create_self ( devilutionx.self devilutionx UNSAFE )
if ( BUILD_ASSETS_MPQ OR SRC_DIST )
vita_create_vpk ( devilutionx.vpk ${ VITA_TITLEID } devilutionx.self
V E R S I O N $ { V I T A _ V E R S I O N }
N A M E $ { V I T A _ A P P _ N A M E }
F I L E P a c k a g i n g / v i t a / s c e _ s y s s c e _ s y s
F I L E $ { D E V I L U T I O N X _ M P Q } d e v i l u t i o n x . m p q
)
else ( )
vita_create_vpk ( devilutionx.vpk ${ VITA_TITLEID } devilutionx.self
V E R S I O N $ { V I T A _ V E R S I O N }
N A M E $ { V I T A _ A P P _ N A M E }
F I L E P a c k a g i n g / v i t a / s c e _ s y s s c e _ s y s
F I L E P a c k a g i n g / r e s o u r c e s / a s s e t s a s s e t s
$ { V I T A _ T R A N S L A T I O N S _ L I S T }
)
endif ( )
endif ( )
if ( PS4 )
add_custom_command (
T A R G E T d e v i l u t i o n x _ m p q P O S T _ B U I L D
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { D E V I L U T I O N X _ M P Q } " $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / p s 4 / " )
add_self ( ${ BIN_TARGET } )
add_pkg ( ${ BIN_TARGET } "${PROJECT_SOURCE_DIR}/Packaging/ps4"
" D V L X 0 0 0 0 1 " " D e v i l u t i o n X " " $ { P R O J E C T _ V E R S I O N } " )
endif ( )
if ( NINTENDO_3DS )
set ( APP_TITLE "DevilutionX" )
set ( APP_DESCRIPTION "DevilutionX port for 3DS" )
set ( APP_AUTHOR "Diasurgical Team" )
set ( APP_ICON "${PROJECT_SOURCE_DIR}/Packaging/ctr/icon.png" )
set ( APP_BANNER "${PROJECT_SOURCE_DIR}/Packaging/ctr/banner.png" )
set ( APP_AUDIO "${CMAKE_BINARY_DIR}/banner_audio.wav" )
set ( APP_RSF "${PROJECT_SOURCE_DIR}/Packaging/ctr/template.rsf" )
set ( APP_ROMFS "${CMAKE_BINARY_DIR}/romfs" )
list ( APPEND APP_ROMFS_FILES ${ DEVILUTIONX_MPQ } )
set ( APP_VERSION ${ PROJECT_VERSION } )
find_program ( FFMPEG ffmpeg )
if ( FFMPEG )
add_custom_command ( OUTPUT ${ APP_AUDIO }
C O M M A N D $ { F F M P E G } - y - s s 3 . 3 - t 3 - i " $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / r e s o u r c e s / s h a r e w a r e - s t a r t u p . w a v " - a f " a f a d e = t = i n : s t = 0 : d = 0 . 1 , a f a d e = t = o u t : s t = 2 . 9 : d = 0 . 1 " $ { A P P _ A U D I O }
D E P E N D S $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / r e s o u r c e s / s h a r e w a r e - s t a r t u p . w a v
V E R B A T I M )
else ( )
add_custom_command ( OUTPUT ${ APP_AUDIO }
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / c t r / a u d i o _ s i l e n t . w a v $ { A P P _ A U D I O }
D E P E N D S $ { P R O J E C T _ S O U R C E _ D I R } / P a c k a g i n g / c t r / a u d i o _ s i l e n t . w a v
V E R B A T I M )
endif ( )
add_custom_target ( romfs_directory
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { A P P _ R O M F S } )
add_custom_target ( romfs_files
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { A P P _ R O M F S _ F I L E S } $ { A P P _ R O M F S }
D E P E N D S $ { A P P _ R O M F S _ F I L E S } )
add_dependencies ( romfs_files romfs_directory devilutionx_mpq )
include ( Tools3DS )
add_3dsx_target ( ${ BIN_TARGET } )
add_cia_target ( ${ BIN_TARGET } ${ APP_RSF } ${ APP_BANNER } ${ APP_AUDIO } )
get_filename_component ( APP_TARGET_PREFIX ${ BIN_TARGET } NAME_WE )
add_dependencies ( ${ APP_TARGET_PREFIX } _3dsx romfs_files )
add_dependencies ( ${ APP_TARGET_PREFIX } _cia romfs_files )
endif ( )
if ( UWP_LIB )
target_compile_definitions ( libdevilutionx PRIVATE __UWP__=1 )
endif ( )
if ( CPACK AND ( APPLE OR BUILD_ASSETS_MPQ OR SRC_DIST ) )
if ( WIN32 )
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
set ( SDL2_WIN32_DLLS_DIR "${CMAKE_BINARY_DIR}" )
else ( )
set ( SDL2_WIN32_DLLS_DIR "${SDL2_EXEC_PREFIX}/bin" )
endif ( )
set ( SDL2_WIN32_LICENSES_DIR "${PROJECT_SOURCE_DIR}/Packaging/resources" )
file ( GLOB SDL2_WIN32_ALL_DLLS
L I S T _ D I R E C T O R I E S f a l s e
" $ { S D L 2 _ W I N 3 2 _ D L L S _ D I R } / * . d l l " )
file ( GLOB SDL2_WIN32_ALL_LICENSES
L I S T _ D I R E C T O R I E S f a l s e
" $ { S D L 2 _ W I N 3 2 _ L I C E N S E S _ D I R } / L I C E N S E * . t x t "
" $ { S D L 2 _ W I N 3 2 _ L I C E N S E S _ D I R } / R E A D M E * . t x t " )
set ( CPACK_PACKAGE_FILE_NAME "devilutionx" )
set ( CPACK_PACKAGE_NAME ${ project_name } )
set ( CPACK_GENERATOR "ZIP" )
set ( CPACK_STRIP_FILES TRUE )
install ( TARGETS ${ BIN_TARGET } DESTINATION . )
install ( FILES "${PROJECT_SOURCE_DIR}/Packaging/windows/README.txt"
D E S T I N A T I O N " . "
)
install ( FILES "${DEVILUTIONX_MPQ}"
D E S T I N A T I O N " . "
)
foreach ( _SDL2_WIN32_DLL_PATH ${ SDL2_WIN32_ALL_DLLS } )
install ( FILES "${_SDL2_WIN32_DLL_PATH}"
D E S T I N A T I O N " . "
)
endforeach ( )
foreach ( _SDL2_WIN32_LICENSE_PATH ${ SDL2_WIN32_ALL_LICENSES } )
install ( FILES "${_SDL2_WIN32_LICENSE_PATH}"
D E S T I N A T I O N " L I C E N S E "
)
endforeach ( )
if ( DISCORD_SHARED_LIB )
install ( FILES "${DISCORD_SHARED_LIB}"
D E S T I N A T I O N " . "
)
endif ( )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
string ( TOLOWER ${ PROJECT_NAME } project_name )
set ( CPACK_PACKAGE_NAME ${ project_name } )
set ( CPACK_GENERATOR "7Z" )
# Common *nix files
set ( CPACK_STRIP_FILES TRUE )
install ( TARGETS ${ BIN_TARGET } DESTINATION bin )
set ( desktop_file "${PROJECT_SOURCE_DIR}/Packaging/nix/${project_name}.desktop" )
set ( desktop_file_hellfire "${PROJECT_SOURCE_DIR}/Packaging/nix/${project_name}-hellfire.desktop" )
find_program ( DFI desktop-file-install )
if ( DFI )
execute_process ( COMMAND ${ DFI } --dir= ${ CMAKE_BINARY_DIR } ${ desktop_file } )
set ( desktop_file "${CMAKE_BINARY_DIR}/${project_name}.desktop" )
execute_process ( COMMAND ${ DFI } --dir= ${ CMAKE_BINARY_DIR } ${ desktop_file_hellfire } )
set ( desktop_file_hellfire "${CMAKE_BINARY_DIR}/${project_name}-hellfire.desktop" )
endif ( )
install ( FILES "${desktop_file}"
D E S T I N A T I O N " s h a r e / a p p l i c a t i o n s "
)
install ( FILES "${desktop_file_hellfire}"
D E S T I N A T I O N " s h a r e / a p p l i c a t i o n s "
)
install ( FILES "${PROJECT_SOURCE_DIR}/Packaging/nix/README.txt"
D E S T I N A T I O N " s h a r e / d i a s u r g i c a l / $ { p r o j e c t _ n a m e } "
)
install ( FILES "${DEVILUTIONX_MPQ}"
D E S T I N A T I O N " s h a r e / d i a s u r g i c a l / $ { p r o j e c t _ n a m e } "
)
install ( FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/icon.png"
D E S T I N A T I O N " s h a r e / i c o n s / h i c o l o r / 5 1 2 x 5 1 2 / a p p s "
R E N A M E " $ { p r o j e c t _ n a m e } . p n g "
)
install ( FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/hellfire.png"
D E S T I N A T I O N " s h a r e / i c o n s / h i c o l o r / 5 1 2 x 5 1 2 / a p p s "
R E N A M E " $ { p r o j e c t _ n a m e } - h e l l f i r e . p n g "
)
install ( FILES "${PROJECT_SOURCE_DIR}/Packaging/nix/devilutionx.metainfo.xml"
D E S T I N A T I O N " s h a r e / m e t a i n f o "
R E N A M E " $ { p r o j e c t _ n a m e } . m e t a i n f o . x m l "
)
# -G DEB
set ( CPACK_PACKAGE_CONTACT "anders@jenbo.dk" )
if ( USE_SDL1 )
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl1.2debian" )
else ( )
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "libsdl2-2.0-0" )
endif ( )
set ( CPACK_DEBIAN_FILE_NAME DEB-DEFAULT )
# -G RPM
set ( CPACK_RPM_FILE_NAME RPM-DEFAULT )
find_program ( RPMBUILD rpmbuild )
if ( RPMBUILD )
list ( APPEND CPACK_GENERATOR "RPM" )
endif ( )
find_program ( DPKG dpkg )
if ( DPKG )
list ( APPEND CPACK_GENERATOR "DEB" )
endif ( )
elseif ( APPLE )
set ( CPACK_PACKAGE_FILE_NAME "devilutionx" )
set ( CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK "ON" )
set ( CPACK_STRIP_FILES TRUE )
set ( CPACK_GENERATOR "DragNDrop" )
endif ( )
set ( CPACK_PACKAGE_VERSION_MAJOR ${ PROJECT_VERSION_MAJOR } )
set ( CPACK_PACKAGE_VERSION_MINOR ${ PROJECT_VERSION_MINOR } )
set ( CPACK_PACKAGE_VERSION_PATCH ${ PROJECT_VERSION_PATCH } )
include ( CPack )
endif ( )