@ -23,8 +23,10 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
endif ( )
endif ( )
include ( CMakeDependentOption )
include ( CMakeDependentOption )
include ( CMake/out_of_tree.cmake )
include ( CMake/genex.cmake )
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" )
include ( out_of_tree )
include ( genex )
DEBUG_OPTION ( ASAN "Enable address sanitizer" )
DEBUG_OPTION ( ASAN "Enable address sanitizer" )
DEBUG_OPTION ( UBSAN "Enable undefined behaviour sanitizer" )
DEBUG_OPTION ( UBSAN "Enable undefined behaviour sanitizer" )
@ -53,6 +55,18 @@ mark_as_advanced(DISABLE_STREAMING_SOUNDS)
option ( STREAM_ALL_AUDIO "Stream all the audio. For extremely RAM-constrained platforms." )
option ( STREAM_ALL_AUDIO "Stream all the audio. For extremely RAM-constrained platforms." )
mark_as_advanced ( STREAM_ALL_AUDIO )
mark_as_advanced ( STREAM_ALL_AUDIO )
if ( PIE )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
endif ( )
if ( TSAN )
set ( ASAN OFF )
endif ( )
if ( USE_SDL1 )
set ( VIRTUAL_GAMEPAD 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 .
# 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 )
if ( NOT DEFINED BUILD_ASSETS_MPQ AND NOT SRC_DIST )
find_program ( SMPQ smpq )
find_program ( SMPQ smpq )
@ -73,6 +87,43 @@ endif()
RELEASE_OPTION ( CPACK "Configure CPack" )
RELEASE_OPTION ( CPACK "Configure CPack" )
# 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 .
if ( NOT VERSION_NUM )
include ( CMake/git.cmake )
get_git_tag ( VERSION_NUM )
if ( NOT "${VERSION_NUM}" STREQUAL "" )
string ( REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${ VERSION_NUM } )
endif ( )
get_git_commit_hash ( GIT_COMMIT_HASH )
if ( NOT VERSION_SUFFIX )
set ( VERSION_SUFFIX "$<$<NOT:$<CONFIG:Release>>:-${GIT_COMMIT_HASH}>" )
endif ( )
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 ( )
# 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 )
# 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 ( NONET )
set ( DISABLE_TCP ON )
set ( DISABLE_ZERO_TIER ON )
set ( PACKET_ENCRYPTION OFF )
endif ( )
if ( BINARY_RELEASE OR CMAKE_BUILD_TYPE STREQUAL "Release" )
if ( BINARY_RELEASE OR CMAKE_BUILD_TYPE STREQUAL "Release" )
set ( BINARY_RELEASE ON )
set ( BINARY_RELEASE ON )
@ -88,77 +139,11 @@ if(NIGHTLY_BUILD OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set ( CPACK ON )
set ( CPACK ON )
endif ( )
endif ( )
if ( USE_SDL1 )
list ( APPEND VCPKG_MANIFEST_FEATURES "sdl1" )
else ( )
list ( APPEND VCPKG_MANIFEST_FEATURES "sdl2" )
endif ( )
if ( PACKET_ENCRYPTION )
list ( APPEND VCPKG_MANIFEST_FEATURES "encryption" )
endif ( )
if ( USE_GETTEXT_FROM_VCPKG )
list ( APPEND VCPKG_MANIFEST_FEATURES "translations" )
endif ( )
if ( RUN_TESTS )
list ( APPEND VCPKG_MANIFEST_FEATURES "tests" )
endif ( )
if ( NOT NOSOUND )
option ( DEVILUTIONX_SYSTEM_SDL_AUDIOLIB "Use system-provided SDL_audiolib" OFF )
cmake_dependent_option ( DEVILUTIONX_STATIC_SDL_AUDIOLIB "Link static SDL_audiolib" OFF
" D E V I L U T I O N X _ S Y S T E M _ S D L _ A U D I O L I B A N D N O T D I S T " O N )
endif ( )
if ( PACKET_ENCRYPTION )
option ( DEVILUTIONX_SYSTEM_LIBSODIUM "Use system-provided libsodium" ON )
cmake_dependent_option ( DEVILUTIONX_STATIC_LIBSODIUM "Link static libsodium" OFF
" D E V I L U T I O N X _ S Y S T E M _ L I B S O D I U M A N D N O T D I S T " O N )
endif ( )
option ( DEVILUTIONX_SYSTEM_LIBFMT "Use system-provided libfmt" ON )
cmake_dependent_option ( DEVILUTIONX_STATIC_LIBFMT "Link static libfmt" OFF
" D E V I L U T I O N X _ S Y S T E M _ L I B F M T A N D N O T D I S T " O N )
if ( NOT USE_SDL1 )
option ( DEVILUTIONX_SYSTEM_SDL2 "Use system-provided SDL2" ON )
cmake_dependent_option ( DEVILUTIONX_STATIC_SDL2 "Link static SDL2" OFF
" D E V I L U T I O N X _ S Y S T E M _ S D L 2 A N D N O T D I S T " O N )
endif ( )
option ( DEVILUTIONX_SYSTEM_SDL_IMAGE "Use system-provided SDL_image" ON )
cmake_dependent_option ( DEVILUTIONX_STATIC_SDL_IMAGE "Link static SDL_image" OFF
" D E V I L U T I O N X _ S Y S T E M _ S D L _ I M A G E A N D N O T D I S T " O N )
option ( DEVILUTIONX_SYSTEM_BZIP2 "Use system-provided bzip2" ON )
cmake_dependent_option ( DEVILUTIONX_STATIC_BZIP2 "Link static bzip2" OFF
" D E V I L U T I O N X _ S Y S T E M _ B Z I P 2 A N D N O T D I S T " O N )
if ( NOT VERSION_NUM )
include ( CMake/git.cmake )
get_git_tag ( VERSION_NUM )
if ( NOT "${VERSION_NUM}" STREQUAL "" )
string ( REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${ VERSION_NUM } )
endif ( )
get_git_commit_hash ( GIT_COMMIT_HASH )
if ( NOT VERSION_SUFFIX )
set ( VERSION_SUFFIX "$<$<NOT:$<CONFIG:Release>>:-${GIT_COMMIT_HASH}>" )
endif ( )
endif ( )
find_program ( CCACHE_PROGRAM ccache )
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
if ( CCACHE_PROGRAM )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
endif ( )
endif ( )
if ( VERSION_NUM MATCHES untagged )
project ( DevilutionX
L A N G U A G E S C C X X )
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 ( )
# 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
# 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
# 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 0 5 4 6
# 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 0 5 4 6
if ( NOT DISABLE_LTO )
if ( NOT DISABLE_LTO )
@ -172,12 +157,6 @@ if(NOT DISABLE_LTO)
endif ( )
endif ( )
endif ( )
endif ( )
if ( TSAN )
set ( ASAN OFF )
endif ( )
list ( APPEND CMAKE_MODULE_PATH "${DevilutionX_SOURCE_DIR}/CMake" )
if ( GPERF )
if ( GPERF )
if ( GPERF_HEAP_FIRST_GAME_ITERATION )
if ( GPERF_HEAP_FIRST_GAME_ITERATION )
set ( GPERF_HEAP_MAIN ON )
set ( GPERF_HEAP_MAIN ON )
@ -193,218 +172,18 @@ if(GPERF)
endif ( )
endif ( )
endif ( )
endif ( )
if ( NINTENDO_SWITCH )
list ( APPEND CMAKE_MODULE_PATH "${DevilutionX_SOURCE_DIR}/CMake/switch" )
include ( switch_defs )
endif ( )
if ( VITA )
# W o r k a r o u n d a m i s s i n g s e t t i n g i n t h e t o o l c h a i n f i l e .
# F i x s e n t u p s t r e a m : h t t p s : / / g i t h u b . c o m / v i t a s d k / v i t a - t o o l c h a i n / p u l l / 1 8 2
set ( PKG_CONFIG_EXECUTABLE "$ENV{VITASDK}/bin/arm-vita-eabi-pkg-config" )
include ( "$ENV{VITASDK}/share/vita.cmake" REQUIRED )
include ( vita_defs )
endif ( )
set ( TARGET_PLATFORM host CACHE STRING "Target platform" )
set_property ( CACHE TARGET_PLATFORM PROPERTY STRINGS host retrofw rg350 gkd350h cpigamesh )
if ( TARGET_PLATFORM STREQUAL "lepus" )
include ( lepus_defs )
elseif ( TARGET_PLATFORM STREQUAL "retrofw" )
include ( retrofw_defs )
elseif ( TARGET_PLATFORM STREQUAL "rg350" )
include ( rg350_defs )
elseif ( TARGET_PLATFORM STREQUAL "gkd350h" )
include ( gkd350h_defs )
elseif ( TARGET_PLATFORM STREQUAL "cpigamesh" )
include ( cpigamesh_defs )
endif ( )
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "FreeBSD|NetBSD|OpenBSD|DragonFly" )
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "NetBSD" )
add_definitions ( -D_NETBSD_SOURCE )
else ( )
add_definitions ( -D_BSD_SOURCE )
set ( UBSAN OFF )
endif ( )
set ( ASAN OFF )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate" )
endif ( )
if ( WIN32 )
set ( ASAN OFF )
set ( UBSAN OFF )
set ( DIST ON )
endif ( )
if ( HAIKU )
set ( ASAN OFF )
set ( UBSAN OFF )
endif ( )
if ( AMIGA )
include ( amiga_defs )
endif ( )
if ( NINTENDO_3DS )
list ( APPEND CMAKE_MODULE_PATH "${DevilutionX_SOURCE_DIR}/CMake/ctr" )
include ( n3ds_defs )
endif ( )
if ( ANDROID )
include ( android_defs )
endif ( )
if ( IOS )
include ( ios_defs )
endif ( )
if ( PIE )
set ( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
endif ( )
if ( USE_SDL1 )
set ( VIRTUAL_GAMEPAD OFF )
endif ( )
if ( NONET )
# F i x d e p e n d e n t o p t i o n s i f p l a t f o r m d e f s d i s a b l e n e t w o r k
set ( DISABLE_TCP ON )
set ( DISABLE_ZERO_TIER ON )
set ( PACKET_ENCRYPTION OFF )
endif ( )
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_EXTENSIONS OFF )
set ( CMAKE_CXX_EXTENSIONS OFF )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON ) # f o r c l a n g - t i d y
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON ) # f o r c l a n g - t i d y
set ( CMAKE_THREAD_PREFER_PTHREAD ON )
set ( CMAKE_THREAD_PREFER_PTHREAD ON )
set ( THREADS_PREFER_PTHREAD_FLAG ON )
set ( THREADS_PREFER_PTHREAD_FLAG ON )
if ( NOT NINTENDO_3DS )
if ( NOT NINTENDO_3DS )
find_package ( Threads REQUIRED )
find_package ( Threads REQUIRED )
endif ( )
endif ( )
if ( PACKET_ENCRYPTION )
# D e p e n d e n c i e s m u s t b e i n c l u d e d a f t e r P l a t f o r m s .
if ( DEVILUTIONX_SYSTEM_LIBSODIUM )
include ( Dependencies )
set ( sodium_USE_STATIC_LIBS ${ DEVILUTIONX_STATIC_LIBSODIUM } )
find_package ( sodium REQUIRED )
else ( )
add_subdirectory ( 3rdParty/libsodium )
endif ( )
endif ( )
if ( DEVILUTIONX_SYSTEM_LIBFMT )
find_package ( fmt 7.0.0 QUIET )
if ( fmt_FOUND )
message ( "-- Found fmt ${fmt_VERSION}" )
else ( )
message ( "-- Suitable system fmt package not found, will use fmt from source" )
endif ( )
endif ( )
if ( NOT fmt_FOUND )
add_subdirectory ( 3rdParty/libfmt )
endif ( )
if ( NOT DEVILUTIONX_SYSTEM_BZIP2 )
add_subdirectory ( 3rdParty/bzip2 )
endif ( )
if ( USE_SDL1 )
find_package ( SDL REQUIRED )
include_directories ( ${ SDL_INCLUDE_DIR } )
else ( )
if ( DEVILUTIONX_SYSTEM_SDL2 )
find_package ( SDL2 REQUIRED )
if ( TARGET SDL2::SDL2 )
set ( SDL2_MAIN SDL2::SDL2main )
elseif ( TARGET SDL2::SDL2-static )
# O n s o m e d i s t r o s , s u c h a s v i t a s d k , o n l y t h e S D L 2 : : S D L 2 - s t a t i c t a r g e t i s a v a i l a b l e .
# A l i a s t o S D L 2 : : S D L 2 b e c a u s e s o m e f i n d e r s c r i p t s m a y r e f e r t o S D L 2 : : S D L 2 .
if ( CMAKE_VERSION VERSION_LESS "3.18" )
# A l i a s i n g l o c a l t a r g e t s i s n o t s u p p o r t e d o n C M a k e < 3 . 1 8 , s o m a k e i t g l o b a l .
set_target_properties ( SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE )
endif ( )
add_library ( SDL2::SDL2 ALIAS SDL2::SDL2-static )
set ( SDL2_MAIN SDL2::SDL2main )
else ( )
# A s s u m e a n o l d e r D e b i a n d e r i v a t e t h a t c o m e s w i t h a n s d l 2 - c o n f i g . c m a k e
# t h a t o n l y d e f i n e s ` S D L 2 _ L I B R A R I E S ` ( a s - l S D L 2 ) a n d ` S D L 2 _ I N C L U D E _ D I R S ` .
add_library ( SDL2_lib INTERFACE )
target_link_libraries ( SDL2_lib INTERFACE ${ SDL2_LIBRARIES } )
target_include_directories ( SDL2_lib INTERFACE ${ SDL2_INCLUDE_DIRS } )
# C a n ' t d e f i n e a n I N T E R F A C E t a r g e t w i t h : : , s o a l i a s i n s t e a d
add_library ( SDL2::SDL2 ALIAS SDL2_lib )
endif ( )
else ( )
add_subdirectory ( 3rdParty/SDL2 )
set ( SDL2_MAIN SDL2::SDL2main )
list ( APPEND CMAKE_MODULE_PATH "${DevilutionX_SOURCE_DIR}/3rdParty/SDL2/CMake" )
endif ( )
endif ( )
if ( NOT NONET AND NOT DISABLE_TCP )
add_subdirectory ( 3rdParty/asio )
if ( NINTENDO_3DS )
target_compile_definitions ( asio INTERFACE
A S I O _ D I S A B L E _ T H R E A D S = O N
A S I O _ H A S _ U N I S T D _ H = O N )
target_include_directories ( asio BEFORE INTERFACE CMake/ctr/asio/include )
elseif ( NINTENDO_SWITCH )
include ( asio_defs )
endif ( )
endif ( )
if ( DEVILUTIONX_SYSTEM_SDL_IMAGE )
if ( USE_SDL1 )
find_package ( SDL_image QUIET )
else ( )
# v c p k g u s e s s d l 2 - i m a g e a s t h e p a c k a g e n a m e
find_package ( sdl2-image QUIET )
set ( SDL_image_FOUND ${ sdl2-image_FOUND } )
if ( NOT SDL_image_FOUND )
# F a l l b a c k o n P k g C o n f i g v i a F i n d S D L 2 _ i m a g e . c m a k e
find_package ( SDL2_image QUIET )
set ( SDL_image_FOUND ${ SDL2_image_FOUND } )
endif ( )
endif ( )
if ( SDL_image_FOUND )
message ( "-- Found SDL_image" )
else ( )
message ( "-- Suitable system SDL_image package not found, will use SDL_image from source" )
endif ( )
endif ( )
if ( NOT SDL_image_FOUND )
add_subdirectory ( 3rdParty/SDL_image )
endif ( )
if ( NOT NOSOUND )
if ( DEVILUTIONX_SYSTEM_SDL_AUDIOLIB )
find_package ( SDL_audiolib REQUIRED )
else ( )
add_subdirectory ( 3rdParty/SDL_audiolib )
endif ( )
endif ( )
add_subdirectory ( 3rdParty/libsmackerdec )
if ( WIN32 )
add_subdirectory ( 3rdParty/find_steam_game )
endif ( )
add_subdirectory ( 3rdParty/simpleini )
add_subdirectory ( 3rdParty/libmpq )
add_subdirectory ( 3rdParty/hoehrmann_utf8 )
add_library ( PKWare STATIC
3 r d P a r t y / P K W a r e / e x p l o d e . c p p
3 r d P a r t y / P K W a r e / i m p l o d e . c p p )
target_include_directories ( PKWare PUBLIC 3rdParty/PKWare )
set ( libdevilutionx_SRCS
set ( libdevilutionx_SRCS
S o u r c e / a p p f a t . c p p
S o u r c e / a p p f a t . c p p
@ -665,7 +444,7 @@ if(RUN_TESTS)
endif ( )
endif ( )
add_library ( libdevilutionx OBJECT ${ libdevilutionx_SRCS } )
add_library ( libdevilutionx OBJECT ${ libdevilutionx_SRCS } )
if ( ANDROID )
if ( ANDROID )
add_library ( ${ BIN_TARGET } SHARED Source/main.cpp )
add_library ( ${ BIN_TARGET } SHARED Source/main.cpp )
else ( )
else ( )
add_executable ( ${ BIN_TARGET }
add_executable ( ${ BIN_TARGET }
@ -739,7 +518,7 @@ find_package(Gettext)
if ( Gettext_FOUND )
if ( Gettext_FOUND )
file ( MAKE_DIRECTORY "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}" )
file ( MAKE_DIRECTORY "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}" )
foreach ( lang ${ devilutionx_langs } )
foreach ( lang ${ devilutionx_langs } )
set ( _po_file "${DevilutionX _SOURCE_DIR}/Translations/${lang}.po" )
set ( _po_file "${CMAKE_CURRENT _SOURCE_DIR}/Translations/${lang}.po" )
set ( _gmo_file "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/${lang}.gmo" )
set ( _gmo_file "${DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY}/${lang}.gmo" )
set ( _lang_target devilutionx_lang_ ${ lang } )
set ( _lang_target devilutionx_lang_ ${ lang } )
add_custom_command (
add_custom_command (
@ -1087,6 +866,14 @@ if(NOT NOSOUND)
target_link_libraries ( libdevilutionx PUBLIC SDL_audiolib )
target_link_libraries ( libdevilutionx PUBLIC SDL_audiolib )
endif ( )
endif ( )
if ( NOT NONET AND NOT DISABLE_ZERO_TIER )
if ( NOT ANDROID )
target_link_libraries ( libdevilutionx PUBLIC zt-static )
else ( )
target_link_libraries ( libdevilutionx PUBLIC zt-shared )
endif ( )
endif ( )
if ( AMIGA )
if ( AMIGA )
target_link_libraries ( libdevilutionx PUBLIC
target_link_libraries ( libdevilutionx PUBLIC
$ { Z L I B _ L I B R A R Y } )
$ { Z L I B _ L I B R A R Y } )
@ -1391,12 +1178,3 @@ if(CPACK AND (APPLE OR BUILD_ASSETS_MPQ OR SRC_DIST))
set ( CPACK_PACKAGE_VERSION_PATCH ${ PROJECT_VERSION_PATCH } )
set ( CPACK_PACKAGE_VERSION_PATCH ${ PROJECT_VERSION_PATCH } )
include ( CPack )
include ( CPack )
endif ( )
endif ( )
if ( NOT NONET AND NOT DISABLE_ZERO_TIER )
add_subdirectory ( 3rdParty/libzt )
if ( NOT ANDROID )
target_link_libraries ( libdevilutionx PUBLIC zt-static )
else ( )
target_link_libraries ( libdevilutionx PUBLIC zt-shared )
endif ( )
endif ( )