@ -9,6 +9,9 @@ endif()
if ( POLICY CMP0111 )
cmake_policy ( SET CMP0111 NEW )
endif ( )
if ( POLICY CMP0126 )
cmake_policy ( SET CMP0126 NEW )
endif ( )
# P r o j e c t s a d d e d v i a ` a d d _ s u b d i r e c t o r y ` o r ` F e t c h C o n t e n t ` m a y h a v e a l o w e r
# ` c m a k e _ m i n i m u m _ r e q u i r e d ` t h a n w e s e t h e r e . S e t p o l i c i e s t h a t w e r e q u i r e
@ -32,69 +35,24 @@ 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 )
# O p t i o n s r e q u i r e d b y ` V c P k g M a n i f e s t F e a t u r e s ` , w h i c h m u s t b e i n c l u d e d b e f o r e t h e ` p r o j e c t ` c a l l .
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 ( )
# B y d e f a u l t , d e v i l u t i o n x . m p q i s b u i l t o n l y i f s m p q i s i n s t a l l e d .
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 } )
# T h e g e t t e x t [ t o o l s ] p a c k a g e t a k e s a v e r y l o n g t i m e t o i n s t a l l
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" )
option ( BUILD_TESTING "Build tests." ON )
# T h e s e m u s t b e i n c l u d e d a f t e r t h e o p t i o n s a b o v e b u t b e f o r e t h e ` p r o j e c t ` c a l l .
include ( VcPkgManifestFeatures )
# S e t u p t h e ` p r o j e c t ` e a r l y s o t h a t p r o p e r t i e s s u c h a s ` T A R G E T _ S U P P O R T S _ S H A R E D _ L I B S ` a r e d e f i n e d .
# S e t u p t h e ` p r o j e c t ` b e f o r e t h e r e s t o f t h e o p t i o n s s o t h a t :
#
# 1 . P r o p e r t i e s s u c h a s ` T A R G E T _ S U P P O R T S _ S H A R E D _ L I B S ` a r e d e f i n e d .
# 2 . T o o l c h a i n f i l e i s e v a l u a t e d , r e q u i r e d f o r ` P l a t f o r m s . c m a k e ` ,
# w h i c h c a n o v e r r i d e t h e o p t i o n s .
if ( NOT VERSION_NUM )
include ( functions/git )
get_git_tag ( VERSION_NUM )
@ -118,12 +76,9 @@ else()
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 )
# W o r k a r o u n d MSVC + C M a k e b u g w h e n L T O i s e n a b l e d .
# S e e h t t p s : / / g i t h u b . c o m / d i a s u r g i c a l / d e v i l u t i o n X / i s s u e s / 3 7 7 8
# a n d h t t p s : / / g i t l a b . k i t w a r e . c o m / c m a k e / c m a k e / - / i s s u e s / 2 3 0 3 5
set ( BUILD_TESTING OFF )
endif ( )
# P l a t f o r m d e f i n i t i o n s c a n o v e r r i d e o p t i o n s a n d w e w a n t ` c m a k e _ d e p e n d e n t _ o p t i o n ` t o s e e t h e e f f e c t s .
# N o t e t h a t a f e w o p t i o n s a r e s t i l l d e f i n e d b e f o r e t h i s b e c a u s e t h e y ' r e n e e d e d b y ` V c P k g M a n i f e s t F e a t u r e s . c m a k e ` .
include ( Platforms )
# T h i s b u i l t - i n C M a k e m o d u l e a d d s a B U I L D _ T E S T I N G option ( ON by default ) .
# M u s t b e i n c l u d e d i n t h e t o p - l e v e l ` C M a k e L i s t s . t x t ` a f t e r c a l l i n g ` p r o j e c t ` .
@ -131,51 +86,105 @@ endif()
# w e a d d a B U I L D _ T E S T I N G o p t i o n o u r s e l v e s a b o v e a s w e l l .
include ( CTest )
# P l a t f o r m d e f i n i t i o n s c a n o v e r r i d e o p t i o n s a n d w e w a n t ` c m a k e _ d e p e n d e n t _ o p t i o n ` t o s e e t h e e f f e c t s ,
# s o i d e a l l y w e w o u l d i n c l u d e P l a t f o r m s . c m a k e b e f o r e d e f i n i n i n g t h e o p t i o n s .
#
# H o w e v e r , ` P l a t f o r m s ` r e q u i r e ` p r o j e c t ` t o h a v e b e e n called ( to get access to toolchain defs ) ,
# b u t ` p r o j e c t ` m u s t b e c a l l e d a f t e r ` V c P k g M a n i f e s t F e a t u r e s ` , a n d ` V c P k g M a n i f e s t F e a t u r e s ` n e e d
# t o b e a f t e r t h e o p t i o n s .
include ( Platforms )
# D e b u g g i n g / p r o f i l i n g o p t i o n s
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 ( ENABLE_CODECOVERAGE "Instrument code for code coverage (only enabled with BUILD_TESTING)" OFF )
# P a c k a g i n g o p t i o n s
RELEASE_OPTION ( CPACK "Configure CPack" )
option ( MACOSX_STANDALONE_APP_BUNDLE "Generate a portable app bundle to use on other devices (requires sudo)" OFF )
# N e t w o r k o p t i o n s
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 )
# S o u n d o p t i o n s
option ( NOSOUND "Disable sound support" OFF )
option ( DEVILUTIONX_RESAMPLER_SPEEX "Build with Speex resampler" ON )
cmake_dependent_option ( DEVILUTIONX_RESAMPLER_SDL "Build with SDL resampler" ON "NOT USE_SDL1" OFF )
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 } )
# O p t i m i z a t i o n / l i n k o p t i o n s
option ( DISABLE_LTO "Disable link-time optimization (by default enabled in release mode)" OFF )
option ( PIE "Generate position-independent code" OFF )
cmake_dependent_option ( DEVILUTIONX_DISABLE_RTTI "Disable RTTI" ON "NONET" OFF )
cmake_dependent_option ( DEVILUTIONX_DISABLE_EXCEPTIONS "Disable exceptions" ON "NONET" OFF )
RELEASE_OPTION ( DEVILUTIONX_STATIC_CXX_STDLIB "Link C++ standard library statically (if available)" )
# M e m o r y / p e r f o r m a n c e t r a d e - o f f o p t i o n s
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_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 )
mark_as_advanced ( DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT )
# A d d i t i o n a l f e a t u r e s
option ( DISCORD_INTEGRATION "Build with Discord SDK for rich presence support" OFF )
# B y d e f a u l t , d e v i l u t i o n x . m p q i s b u i l t o n l y i f s m p q i s i n s t a l l e d .
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 } )
# = = = O p t i o n o v e r r i d e s = = =
# T S A N i s n o t c o m p a t i b l e w i t h A S A N .
if ( TSAN )
set ( ASAN OFF )
endif ( )
if ( MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT DISABLE_LTO )
# W o r k a r o u n d MSVC + C M a k e b u g w h e n L T O i s e n a b l e d .
# S e e h t t p s : / / g i t h u b . c o m / d i a s u r g i c a l / d e v i l u t i o n X / i s s u e s / 3 7 7 8
# a n d h t t p s : / / g i t l a b . k i t w a r e . c o m / c m a k e / c m a k e / - / i s s u e s / 2 3 0 3 5
set ( BUILD_TESTING OFF )
endif ( )
# N o t e : ` C M A K E _ C R O S S C O M P I L I N G ` i s o n l y a v a i l a b l e a f t e r t h e ` p r o j e c t ` c a l l .
if ( CMAKE_CROSSCOMPILING )
set ( BUILD_TESTING OFF )
endif ( )
# R e c a l c u l a t e t h e d e p e n d e n t o p t i o n s a f t e r i n c l u d i n g t h e P l a t f o r m s :
if ( BUILD_TESTING )
# F o r t e s t s , w e b u i l d a l i b d e v i l u t i o n x . s o s h a r e d l i b r a r y .
# W h e n t h i s l i b d e v i l u t i o n x . s o i s l i n k e d a g a i n s t c e r t a i n s t a t i c l i b r a r i e s ,
# t h e y m u s t b e c o m p i l e d w i t h ` - f P I C ` .
# W h e n t e s t s a r e e n a b l e d , w e b u i l d a s h a r e d d e v i l u t i o n x _ s o l i b r a r y , w h i c h n e e d s t o b e P I C t o l i n k .
set ( PIE ON )
endif ( )
if ( PIE )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
endif ( )
# R e c a l c u l a t e t h e d e p e n d e n t o p t i o n s t h a t a r e d e f i n e d b e f o r e ` include ( Platforms ) ` :
if ( NONET )
set ( DISABLE_TCP ON )
set ( DISABLE_ZERO_TIER ON )
set ( DISABLE_RTTI ON )
set ( DISABLE_EXCEPTIONS ON )
# P A C K E T _ E N C R Y P T I O N i s d e f i n e d b e f o r e ` P l a t f o r m s . c m a k e ` i s i n c l u d e d .
# T h i s m e a n s t h a t i f a ` P l a t f o r m s . c m a k e ` s e t s N O N E T t o O F F , P A C K E T _ E N C R Y P T I O N w i l l n o t a u t o m a t i c a l l y
# r e f l e c t t h a t .
set ( PACKET_ENCRYPTION OFF )
endif ( )
# = = = E n d o f o p t i o n o v e r r i d e s = = =
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 )
if ( PIE )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
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 )
@ -203,11 +212,14 @@ endif()
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
# F o r s o m e r e a s o n , a d d i n g t o C M A K E _ C X X _ F L A G S r e s u l t s i n a s l i g h t l y s m a l l e r
# b i n a r y t h a n u s i n g ` a d d _ c o m p i l e / l i n k _ o p t i o n s `
set ( _extra_flags "-ffunction-sections -fdata-sections -Wl,--gc-sections" )
set ( _extra_flags "-ffunction-sections -fdata-sections -Wl,--gc-sections,--as-needed " )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_extra_flags}" )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${_extra_flags}" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${_extra_flags}" )
set ( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${_extra_flags}" )
set ( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${_extra_flags}" )
set ( CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${_extra_flags}" )
endif ( )
# N o t a g e n e x p b e c a u s e C M a k e d o e s n ' t s u p p o r t i t