2020-09-28 05:18:55 +00:00
# set minimum version
2021-12-15 07:49:52 +00:00
cmake_minimum_required ( VERSION 3.14 )
2017-11-17 16:28:52 +00:00
project ( wesnoth )
2008-05-07 08:13:25 +00:00
2012-06-09 21:41:05 +00:00
include ( CheckCXXCompilerFlag )
2022-04-29 23:59:19 +00:00
include ( CTest )
2012-06-09 21:41:05 +00:00
2008-05-05 21:06:14 +00:00
# use our own version of FindBoost.cmake and other Find* scripts
2015-11-07 08:53:36 +00:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
2008-05-04 20:11:11 +00:00
2017-11-20 08:22:19 +00:00
# function to remove a flag from a variable
function ( RemoveFlag VAR SCOPE FLAG DOCSTRING )
2017-11-22 19:39:35 +00:00
if ( NOT "${${VAR}}" STREQUAL "" )
MESSAGE ( "Removing ${FLAG} flag from ${VAR}" )
separate_arguments ( ${ VAR } )
list ( REMOVE_ITEM ${ VAR } ${ FLAG } )
string ( REPLACE ";" " " ${ VAR } "${${VAR}}" )
if ( "${SCOPE}" STREQUAL "CACHE" )
set ( ${ VAR } "${${VAR}}" CACHE STRING "${DOCSTRING}" FORCE )
elseif ( "${SCOPE}" STREQUAL "SCRIPT" )
set ( ${ VAR } "${${VAR}}" PARENT_SCOPE )
endif ( )
2017-11-20 08:22:19 +00:00
endif ( )
endfunction ( )
2015-09-09 09:42:29 +00:00
#
# Options
#
2017-11-17 16:28:52 +00:00
# Adhere to GNU filesystem layout conventions
include ( GNUInstallDirs )
2015-09-09 09:42:29 +00:00
#Path options
set ( DATADIRNAME "wesnoth" CACHE STRING "change the name of the directory for the read-only architecture-independent game data" )
set ( EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}" CACHE STRING "change the dir where binaries are placed right at compile time" )
2017-11-20 16:48:51 +00:00
set ( LOCALEDIR "translations" CACHE STRING "change the name of the locale data directory to a non-default name" )
2015-09-09 09:42:29 +00:00
set ( PREFERENCES_DIR "" CACHE STRING "Use a non-default preferences directory (.wesnoth on unix)" )
set ( DEFAULT_PREFS_FILE "" CACHE STRING "Set system wide preferences file" )
#server options
set ( SERVER_UID "" CACHE STRING "User id of the user who runs wesnothd" )
set ( SERVER_GID "" CACHE STRING "Group id of the user who runs wesnothd" )
set ( FIFO_DIR "/var/run/wesnothd" CACHE STRING "Directory for the wesnothd fifo socket file" )
#build options
option ( ENABLE_GAME "Enable compilation of the game" ON )
2018-01-21 23:08:05 +00:00
option ( ENABLE_CAMPAIGN_SERVER "Enable compilation of campaign(add-ons) server" )
option ( ENABLE_SERVER "Enable compilation of MP server" ON )
2018-03-02 08:20:14 +00:00
option ( ENABLE_MYSQL "Enable building MP/add-ons servers with mysql support" OFF )
2015-09-09 09:42:29 +00:00
option ( ENABLE_TESTS "Build unit tests" )
2018-02-08 21:07:05 +00:00
option ( ENABLE_NLS "Enable building of translations" ${ ENABLE_GAME } )
2015-08-16 09:43:45 +00:00
2024-09-08 15:25:45 +00:00
set ( BOOST_VERSION "1.67" )
2020-09-28 05:18:55 +00:00
Add CMake and SCons options to use system Lua 5.4 C++
scons/lua.py makes use of the vestigial luadir option from commit
e94dcecf171.
Like FindLua.cmake, scons/lua.py searches for the Lua headers and
library, instead of using pkg-config like the old scons/lua.py (removed
in commit 9929d3ca1cf) did, because even though distributions typically
provide .pc files for Lua, upstream Lua doesn't. It's likely that all
distributions that compile Lua as a C++ library will also provide .pc
files, but this check doesn't rely on that (just as the CMake module
doesn't).
Unfortunately, SCons.Conftest.CheckLib() prints up to eight messages
like "Checking for C++ library lua54-c++... no" until a working library
name is found.
Also conditionally include system Lua headers in src/lua/*.h and update
documentation in src/modules/lua_README.md, src/wesnoth_lua_config.h,
and src/wesnoth_lua_config.md. The two lines about "The primary commit,
after replacing the sources," in src/wesnoth_lua_config.md don't make
sense since the instructions were updated for submodule Lua in commit
d32cfb88c4f and make even less sense now with preceding commits for
updating CMake modules.
2024-01-06 23:54:56 +00:00
if ( NOT WIN32 )
set ( Lua_FIND_VERSION_MAJOR 5 )
set ( Lua_FIND_VERSION_MINOR 4 )
option ( ENABLE_SYSTEM_LUA "Enable use of system Lua ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR} (compiled as C++)" OFF )
endif ( )
if ( ENABLE_SYSTEM_LUA )
set ( Lua_FIND_VERSION_EXACT ON )
set ( Lua_FIND_VERSION_COUNT 2 )
include ( FindLua )
if ( NOT LUA_FOUND )
message ( FATAL_ERROR "Lua ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR} C++ not found. Try setting 'LUA_DIR'." )
endif ( )
else ( )
if ( NOT EXISTS "${CMAKE_SOURCE_DIR}/src/modules/lua/.git" )
message ( FATAL_ERROR "Lua submodule does not exist. You must run 'git submodule update --init --recursive' to initialize it." )
else ( )
message ( "-- Lua submodule found." )
endif ( )
endif ( )
2018-03-18 18:56:56 +00:00
# set what std version to use
if ( NOT CXX_STD )
2021-01-16 22:18:30 +00:00
set ( CXX_STD "17" )
2018-03-18 18:56:56 +00:00
endif ( )
2020-04-30 15:16:45 +00:00
set ( CMAKE_CXX_STANDARD ${ CXX_STD } )
# make sure to force using it
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
# forbid defaulting to gnu++NN instead of c++NN
set ( CMAKE_CXX_EXTENSIONS OFF )
2018-03-18 18:56:56 +00:00
2024-01-28 12:08:20 +00:00
find_package ( OpenSSL 1.0 REQUIRED )
2021-05-22 19:58:40 +00:00
if ( APPLE )
2022-06-08 20:18:06 +00:00
find_library ( APPKIT_LIBRARY AppKit REQUIRED )
find_library ( FOUNDATION_LIBRARY Foundation REQUIRED )
2021-05-22 19:58:40 +00:00
find_library ( IOKIT_LIBRARY IOKit REQUIRED )
find_library ( SECURITY_LIBRARY Security REQUIRED )
2017-05-31 04:37:29 +00:00
endif ( )
2023-12-20 02:20:09 +00:00
find_package ( Boost ${ BOOST_VERSION } REQUIRED COMPONENTS iostreams program_options regex system thread random coroutine locale filesystem graph )
2021-05-14 00:43:06 +00:00
find_package ( ICU REQUIRED COMPONENTS data i18n uc )
2011-01-08 20:40:56 +00:00
# no, gettext executables are not required when NLS is deactivated
find_package ( Gettext )
2023-05-13 02:51:24 +00:00
find_package ( Python )
2009-08-01 18:28:18 +00:00
2010-07-30 21:49:36 +00:00
find_package ( X11 )
2008-05-05 22:22:28 +00:00
Add CMake and SCons options to use system Lua 5.4 C++
scons/lua.py makes use of the vestigial luadir option from commit
e94dcecf171.
Like FindLua.cmake, scons/lua.py searches for the Lua headers and
library, instead of using pkg-config like the old scons/lua.py (removed
in commit 9929d3ca1cf) did, because even though distributions typically
provide .pc files for Lua, upstream Lua doesn't. It's likely that all
distributions that compile Lua as a C++ library will also provide .pc
files, but this check doesn't rely on that (just as the CMake module
doesn't).
Unfortunately, SCons.Conftest.CheckLib() prints up to eight messages
like "Checking for C++ library lua54-c++... no" until a working library
name is found.
Also conditionally include system Lua headers in src/lua/*.h and update
documentation in src/modules/lua_README.md, src/wesnoth_lua_config.h,
and src/wesnoth_lua_config.md. The two lines about "The primary commit,
after replacing the sources," in src/wesnoth_lua_config.md don't make
sense since the instructions were updated for submodule Lua in commit
d32cfb88c4f and make even less sense now with preceding commits for
updating CMake modules.
2024-01-06 23:54:56 +00:00
if ( NOT WIN32 AND NOT ENABLE_SYSTEM_LUA )
2021-12-12 13:58:11 +00:00
# Use the safer `mkstemp' instead of `tmpnam' on POSIX systems.
add_definitions ( -DLUA_USE_POSIX )
2021-05-22 20:38:41 +00:00
endif ( )
2009-04-13 14:41:32 +00:00
2009-03-24 14:28:52 +00:00
#check for some compiler/arch specific things and export defines accordingly...
2010-07-30 21:49:36 +00:00
include ( SearchForStuff )
2009-03-24 14:28:52 +00:00
2015-04-12 09:52:00 +00:00
# if no build type is specified, it can happen that the game is built without
# optimization (c.f. bug #23445), work around this by enforcing "release" type
# if nothing was selected
if ( NOT CMAKE_BUILD_TYPE )
2021-06-08 21:12:03 +00:00
set ( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE )
2021-04-29 04:20:05 +00:00
message ( "No build type specified, defaulting to Release" )
2021-05-22 20:38:41 +00:00
endif ( )
2015-04-12 09:52:00 +00:00
2013-03-30 16:29:34 +00:00
if ( NOT DEFINED ENABLE_DISPLAY_REVISION )
2021-05-13 04:44:14 +00:00
# can't run the shell script on windows
if ( NOT WIN32 )
# Test whether the code is used in a repository if not autorevision will
# fail and should be disabled by default. If inside a repository enable
# the display of revision numbers by default.
execute_process (
C O M M A N D $ { C M A K E _ S O U R C E _ D I R } / u t i l s / a u t o r e v i s i o n . s h - t h > $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / r e v i s i o n . d u m m y
W O R K I N G _ D I R E C T O R Y
$ { C M A K E _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E
E N A B L E _ D I S P L A Y _ R E V I S I O N _ T E S T _ O U T P U T
E R R O R _ V A R I A B L E
E N A B L E _ D I S P L A Y _ R E V I S I O N _ T E S T _ E R R N O
)
if ( "${ENABLE_DISPLAY_REVISION_TEST_ERRNO}" STREQUAL "" )
set ( DEFAULT_ENABLE_DISPLAY_REVISION true )
else ( )
set ( DEFAULT_ENABLE_DISPLAY_REVISION false )
endif ( )
unset ( ENABLE_DISPLAY_REVISION_TEST_OUTPUT )
unset ( ENABLE_DISPLAY_REVISION_TEST_ERRNO )
2013-03-30 16:29:34 +00:00
else ( )
set ( DEFAULT_ENABLE_DISPLAY_REVISION false )
endif ( )
2013-03-15 20:28:52 +00:00
endif ( )
2013-03-30 16:29:34 +00:00
2013-03-15 20:28:52 +00:00
option (
E N A B L E _ D I S P L A Y _ R E V I S I O N
2013-03-21 21:39:36 +00:00
" E n a b l e t h e d i s p l a y o f t h e r e v i s i o n n u m b e r i n t h e g a m e , o n l y e n a b l e i t w h e n i n a c h e c k o u t "
2013-03-15 20:28:52 +00:00
$ { D E F A U L T _ E N A B L E _ D I S P L A Y _ R E V I S I O N }
)
2010-07-30 21:49:36 +00:00
if ( UNIX AND NOT APPLE AND NOT CYGWIN )
2010-07-30 21:49:42 +00:00
option ( ENABLE_DESKTOP_ENTRY "enable installation of desktop entry files" ON )
2021-05-22 20:38:41 +00:00
endif ( )
2010-07-30 21:49:36 +00:00
2017-11-03 13:10:55 +00:00
if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
option ( ENABLE_APPDATA_FILE "enable installation of an appdata file for appstream" ON )
2021-05-22 20:38:41 +00:00
endif ( )
2017-11-03 13:10:55 +00:00
2018-06-15 06:31:31 +00:00
option ( HARDEN "Whether to enable options to harden the executables" ON )
2015-06-27 02:09:18 +00:00
option ( ENABLE_STRICT_COMPILATION "Sets the strict compilation mode" OFF )
2012-07-12 18:08:17 +00:00
option ( ENABLE_PEDANTIC_COMPILATION "Sets the pedantic compilation mode" OFF )
2009-05-27 19:08:57 +00:00
option ( ENABLE_DEBUG_WINDOW_LAYOUT "Add the debug option to allow the generation of debug layout files in dot format" OFF )
2011-02-08 19:37:36 +00:00
option ( ENABLE_DESIGN_DOCUMENTS "Enables the generation of design documents, and has additional dependencies" OFF )
2018-02-12 06:11:50 +00:00
option ( ENABLE_LTO "Sets Link Time Optimization for Release builds" OFF )
2023-02-25 10:44:06 +00:00
option ( GLIBCXX_ASSERTIONS "Whether to define _GLIBCXX_ASSERTIONS" OFF )
option ( GLIBCXX_DEBUG "Whether to define _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC. Requires a version of Boost's program_options that's compiled with __GLIBCXX_DEBUG too." OFF )
2017-11-24 21:11:45 +00:00
option ( ENABLE_POT_UPDATE_TARGET "Enables the tools to update the pot files and manuals. This target has extra dependencies." OFF )
2022-06-08 10:44:33 +00:00
option ( FORCE_COLOR_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE )
2008-05-15 14:56:38 +00:00
2009-08-10 17:50:37 +00:00
if ( UNIX AND NOT APPLE AND NOT CYGWIN )
2010-03-03 10:21:55 +00:00
option ( ENABLE_NOTIFICATIONS "Enable Window manager notification messages" ON )
2021-05-22 20:38:41 +00:00
endif ( )
2009-08-10 17:50:37 +00:00
2008-05-15 14:56:38 +00:00
set ( BINARY_SUFFIX "" CACHE STRING "Suffix behind all binaries" )
set ( BINARY_PREFIX "" CACHE STRING "Prefix in front of all binaries" )
2008-05-05 21:06:14 +00:00
2008-05-13 09:11:18 +00:00
#
# Handle options (set paths/definitions/etc...)
#
2008-05-05 21:06:14 +00:00
2012-07-10 19:07:04 +00:00
### Set the environment compiler flags.
2021-12-04 14:49:43 +00:00
if ( NOT MSVC )
2021-05-07 16:25:10 +00:00
if ( NOT DEFINED CXX_FLAGS_USER )
2012-07-10 19:07:04 +00:00
2021-05-07 16:25:10 +00:00
MESSAGE ( STATUS "Environment compiler flags set to »${CXX_FLAGS_USER}«" )
set ( CXX_FLAGS_USER
" $ E N V { C X X F L A G S } "
C A C H E
S T R I N G
" T h e C X X F L A G S e n v i r o n m e n t v a r i a b l e u s e d f o r t h e i n i t i a l g e n e r a t i o n . "
F O R C E
)
2012-07-10 19:07:04 +00:00
2021-05-22 20:38:41 +00:00
endif ( )
2017-12-02 20:54:40 +00:00
2021-05-07 16:25:10 +00:00
set ( COMPILER_FLAGS "-Wall -Wextra -Werror=non-virtual-dtor -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wold-style-cast -Wtrampolines" )
2021-04-29 04:20:05 +00:00
2021-05-07 16:25:10 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -Qunused-arguments -Wno-unknown-warning-option -Wmismatched-tags -Wno-conditional-uninitialized -Wno-unused-lambda-capture" )
endif ( )
2014-01-18 21:30:11 +00:00
Use -Wno-dangling-reference when building with GCC-13
Version 13 of GCC added the -Wdangling-reference option, however
due to false positives it had to be moved from -Wall to -Wextra.
Discussion about its status in GCC-14 is in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110075
The warning is for C++ only and the flag will generate a warning
when compiling C files if the flag is set in Scon's CCFLAGS.
The docs don't explain exactly what triggers the warning, but here's the
explanation from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106393#c1
> The warning works by checking if a reference is initialized with a function
> that returns a reference, and at least one parameter of the function is a
> reference that is bound to a temporary. It assumes that such a function
> actually returns one of its arguments! ... suppress the warning when we've
> seen the definition of the function and we can say that it can return a
> variable with static storage duration.
Consistent with that, we're getting warnings on functions of the form
find(container, const std::string&). All of the things triggering it
seem to be false positives:
* Calls to find_widget<...>.
* Calls to theme::get_theme_config.
* Calls to race::gender_value.
* In src/actions/attack.cpp, any `attacker->attacks()[i]`.
Although there's an iterator in there, the eventual reference
is to a member of the array, not the iterator.
* In src/gui/dialogs/unit_advance.cpp, `cfg.child_range("...").back()`
That returns an object indirectly owned by cfg.
We'd like the other warnings of -Wextra, so turn off -Wdangling-reference.
2024-02-04 13:20:53 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU"
A N D C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ G R E A T E R _ E Q U A L 1 3
A N D C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 1 4 )
# GCC-13 added this new warning, and included it in -Wextra,
# however in GCC-13 it has a lot of false positives.
#
# It's likely to generate false postives with GCC-14 too, but
# I'm using a narrow version check as GCC-14 is still in dev.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110075
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -Wno-dangling-reference" )
endif ( )
2017-11-22 19:39:35 +00:00
### Set strict compiler flags.
2014-02-14 20:42:48 +00:00
2021-05-07 16:25:10 +00:00
if ( ENABLE_STRICT_COMPILATION )
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -Werror" )
2021-05-22 20:38:41 +00:00
endif ( )
2012-07-10 19:07:04 +00:00
2012-07-12 18:08:17 +00:00
### Set pedantic compiler flags.
2021-05-07 16:25:10 +00:00
if ( ENABLE_PEDANTIC_COMPILATION )
2013-01-23 19:59:27 +00:00
2021-05-07 16:25:10 +00:00
set ( CXX_FLAGS_PEDANTIC_COMPILATION "-Wlogical-op -Wmissing-declarations -Wredundant-decls -Wctor-dtor-privacy -Wdouble-promotion -Wuseless-cast -Wnoexcept" )
2014-01-05 14:37:32 +00:00
2021-05-07 16:25:10 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set ( CXX_FLAGS_PEDANTIC_COMPILATION "${CXX_FLAGS_PEDANTIC_COMPILATION} -Wdocumentation -Wno-documentation-deprecated-sync" )
endif ( )
2018-03-09 00:35:31 +00:00
2021-05-07 16:25:10 +00:00
set ( COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_PEDANTIC_COMPILATION}" )
2014-01-26 13:24:12 +00:00
2021-05-22 20:38:41 +00:00
endif ( )
2012-07-12 18:08:17 +00:00
2018-04-22 00:09:13 +00:00
# check for sanitizer options
2021-05-07 16:25:10 +00:00
if ( SANITIZE )
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=${SANITIZE}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${SANITIZE}" )
# manually disable some optimizations to get better stacktraces if sanitizers are used
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls" )
2021-05-22 20:38:41 +00:00
endif ( )
2018-04-22 00:09:13 +00:00
2022-06-08 10:44:33 +00:00
### Force colour output (for example for Ninja, or piped CI)
if ( FORCE_COLOR_OUTPUT )
if ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -fdiagnostics-color=always" )
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set ( COMPILER_FLAGS "${COMPILER_FLAGS} -fcolor-diagnostics" )
endif ( )
endif ( )
2012-07-10 19:07:04 +00:00
### Set the final compiler flags.
2021-05-07 16:25:10 +00:00
set ( COMPILER_FLAGS "${COMPILER_FLAGS} ${CXX_FLAGS_USER}" )
2012-07-10 19:07:04 +00:00
2021-05-07 16:25:10 +00:00
if ( NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${COMPILER_FLAGS}" )
MESSAGE ( STATUS "CMake compiler flags set to »${COMPILER_FLAGS}«" )
set ( CMAKE_CXX_FLAGS
" $ { C O M P I L E R _ F L A G S } "
C A C H E
S T R I N G
" G l o b a l f l a g s u s e d b y t h e C X X c o m p i l e r d u r i n g a l l b u i l d s . "
F O R C E
)
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-15 13:02:11 +00:00
2018-09-07 17:36:11 +00:00
# #
# Determine optimization level
# #
2021-05-07 16:25:10 +00:00
if ( NOT OPT )
if ( PROFILER STREQUAL "perf" )
2021-06-08 21:12:03 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "-Og" )
set ( CMAKE_C_FLAGS_RELEASE "-Og" )
2021-05-22 20:38:41 +00:00
else ( )
2021-06-08 21:12:03 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "-O3" )
set ( CMAKE_C_FLAGS_RELEASE "-O3" )
2021-05-22 20:38:41 +00:00
endif ( )
else ( )
2021-05-07 16:25:10 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "${OPT}" )
set ( CMAKE_C_FLAGS_RELEASE "${OPT}" )
2018-09-07 17:36:11 +00:00
2021-05-07 16:25:10 +00:00
set ( CMAKE_CXX_FLAGS_DEBUG "${OPT}" )
set ( CMAKE_C_FLAGS_DEBUG "${OPT}" )
2021-05-22 20:38:41 +00:00
endif ( )
2018-09-07 17:36:11 +00:00
2018-05-04 00:07:57 +00:00
# check for hardening options
2021-05-07 16:25:10 +00:00
if ( HARDEN )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -fstack-protector-strong" )
if ( APPLE )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -Wl,-pie" )
2021-12-04 14:49:43 +00:00
elseif ( WIN32 AND MINGW )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie" )
2021-05-07 16:25:10 +00:00
else ( )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie -Wl,-z,relro,-z,now" )
endif ( )
2018-06-16 18:29:15 +00:00
2021-05-07 16:25:10 +00:00
if ( NOT CMAKE_CXX_FLAGS_DEBUG STREQUAL "-O0" )
add_definitions ( -D_FORTIFY_SOURCE=2 )
endif ( )
2021-05-22 20:38:41 +00:00
endif ( )
2018-05-04 00:07:57 +00:00
2021-05-07 16:25:10 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set ( CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm ${CMAKE_EXE_LINKER_FLAGS}" )
2021-05-22 20:38:41 +00:00
endif ( )
2011-04-25 07:19:25 +00:00
2017-11-17 16:28:52 +00:00
add_definitions ( -DWESNOTH_PATH= "${CMAKE_INSTALL_FULL_DATADIR}/${DATADIRNAME}" )
2008-05-04 17:27:28 +00:00
2021-05-07 16:25:10 +00:00
if ( X11_FOUND )
add_definitions ( -D_X11 )
2021-05-22 20:38:41 +00:00
endif ( )
2008-06-18 20:02:26 +00:00
2021-05-07 16:25:10 +00:00
add_definitions ( -DLOCALEDIR= "${LOCALEDIR}" )
2017-11-20 08:22:19 +00:00
# -rdynamic is automatically added, but we don't need it, and it increases the executable size
2021-05-07 16:25:10 +00:00
RemoveFlag ( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS SCRIPT "-rdynamic" "" )
RemoveFlag ( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS SCRIPT "-rdynamic" "" )
2021-04-29 04:20:05 +00:00
# -DNDEBUG is automatically added to all release build types, so manually remove this define from the related variables
2021-05-07 16:25:10 +00:00
RemoveFlag ( CMAKE_CXX_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C++ flags for RelWithDebInfo" )
RemoveFlag ( CMAKE_C_FLAGS_RELWITHDEBINFO CACHE "-DNDEBUG" "Default C flags for RelWithDebInfo" )
RemoveFlag ( CMAKE_CXX_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C++ flags for MinSizeRel" )
RemoveFlag ( CMAKE_C_FLAGS_MINSIZEREL CACHE "-DNDEBUG" "Default C flags for MinSizeRel" )
2014-02-16 09:45:08 +00:00
2017-09-30 18:32:41 +00:00
# #
# Start determining options for Release build
# #
# reset the base Release build option
2021-05-07 16:25:10 +00:00
MESSAGE ( "Replacing default flags used for Release build with ${OPT} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_RELEASE}" CACHE STRING "Release build flags" FORCE )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "" FORCE )
2017-09-30 18:32:41 +00:00
# set the arch to use for Release build if provided
2021-05-07 16:25:10 +00:00
if ( ARCH )
MESSAGE ( "adding -march=${ARCH} to Release build" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=${ARCH}" CACHE STRING "Release build flags" FORCE )
2021-05-22 20:38:41 +00:00
endif ( )
2017-09-30 18:32:41 +00:00
2017-10-25 13:02:30 +00:00
# PGO and LTO for GCC
2021-05-07 16:25:10 +00:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
if ( PGO_DATA STREQUAL "generate" )
MESSAGE ( "Generating PGO data" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags generating PGO data" FORCE )
endif ( )
if ( PGO_DATA STREQUAL "use" )
MESSAGE ( "Using PGO data from previous runs" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-correction -fprofile-use=${CMAKE_SOURCE_DIR}/pgo_data/" CACHE STRING "Release build flags for using PGO data" FORCE )
endif ( )
if ( ENABLE_LTO )
if ( NOT LTO_JOBS )
MESSAGE ( "LTO_JOBS not set, defaulting to 1" )
set ( LTO_JOBS "1" CACHE STRING "Number of threads to use for LTO with gcc" FORCE )
2021-05-22 20:38:41 +00:00
endif ( )
2021-05-07 16:25:10 +00:00
MESSAGE ( "added -flto=${LTO_JOBS} to Release build" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=${LTO_JOBS}" CACHE STRING "Release build flags with LTO" FORCE )
MESSAGE ( "Using GCC gold linker" )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=gold -Wno-stringop-overflow" CACHE STRING "" FORCE )
2021-05-22 20:38:41 +00:00
endif ( )
endif ( )
2017-10-25 13:02:30 +00:00
# PGO and LTO for Clang
2021-05-07 16:25:10 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
if ( PGO_DATA STREQUAL "generate" )
MESSAGE ( "Generating PGO data" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth-%p.profraw" CACHE STRING "Release build flags generating PGO data" FORCE )
endif ( )
if ( PGO_DATA STREQUAL "use" )
MESSAGE ( "Using PGO data from previous runs" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo_data/wesnoth.profdata" CACHE STRING "Release build flags for using PGO data" FORCE )
endif ( )
if ( ENABLE_LTO )
MESSAGE ( "added -flto=thin to Release build" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=thin" CACHE STRING "Release build flags with LTO" FORCE )
MESSAGE ( "Using Clang LLD linker" )
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=lld" CACHE STRING "Linker flag for building with LTO and clang" FORCE )
2021-05-22 20:38:41 +00:00
endif ( )
endif ( )
2017-10-25 13:02:30 +00:00
2017-09-30 18:32:41 +00:00
# set CMAKE_AR and CMAKE_RANLIB to use LTO-enabled variants if LTO is enabled
2021-05-07 16:25:10 +00:00
if ( ENABLE_LTO )
MESSAGE ( "Using gcc-ar and gcc-ranlib" )
find_program ( LTO_AR NAMES gcc-ar )
find_program ( LTO_RANLIB NAMES gcc-ranlib )
set ( CMAKE_AR "${LTO_AR}" CACHE STRING "Supports LTO" FORCE )
set ( CMAKE_RANLIB "${LTO_RANLIB}" CACHE STRING "Supports LTO" FORCE )
endif ( )
MARK_AS_ADVANCED ( LTO_AR LTO_RANLIB NON_LTO_AR NON_LTO_RANLIB )
2017-09-30 18:32:41 +00:00
2017-11-12 09:24:30 +00:00
# add in extra flags
2021-05-07 16:25:10 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_RELEASE}" )
2017-11-12 09:24:30 +00:00
2017-10-25 13:02:30 +00:00
# clean the pgo data
2021-05-07 16:25:10 +00:00
set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_SOURCE_DIR}/pgo_data/" )
2017-10-25 13:02:30 +00:00
2017-09-30 18:32:41 +00:00
# #
# End determining options for Release build
# Start setting options for Debug build
# #
2016-11-12 04:20:04 +00:00
2021-05-07 16:25:10 +00:00
# replace the default Debug flag of -g with -O0 -DDEBUG -ggdb3
# this matches the flags of scons' debug build
MESSAGE ( "Replacing flags used for Debug build ${OPT} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE )
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -ggdb3 ${EXTRA_FLAGS_CONFIG} ${EXTRA_FLAGS_DEBUG}" CACHE STRING "change cmake's Debug flags to match scons' flags" FORCE )
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "${LINK_EXTRA_FLAGS_CONFIG} ${LINK_EXTRA_FLAGS_DEBUG}" CACHE STRING "" FORCE )
2014-02-16 09:45:08 +00:00
2023-02-25 10:44:06 +00:00
# Enabling GLIBCXX_ASSERTIONS puts bounds-checks on std::vector::operator[], etc
if ( GLIBCXX_ASSERTIONS )
MESSAGE ( "Defining _GLIBCXX_ASSERTIONS" )
add_definitions ( -D_GLIBCXX_ASSERTIONS )
endif ( )
# GLIBCXX_DEBUG enables more checks that GLIBCXX_ASSERTIONS, but changes the ABI of Boost's program_options library.
# When _GLIBCXX_DEBUG is defined, _GLIBCXX_ASSERTIONS is automatically implied (Gnu's c++config.h will define it).
2021-05-07 16:25:10 +00:00
if ( GLIBCXX_DEBUG )
MESSAGE ( "Defining _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC" )
add_definitions ( -D_GLIBCXX_DEBUG )
add_definitions ( -D_GLIBCXX_DEBUG_PEDANTIC )
2021-05-22 20:38:41 +00:00
endif ( )
2017-10-08 18:03:49 +00:00
2017-09-30 18:32:41 +00:00
# #
2021-06-08 21:12:03 +00:00
# Setup profiler build options
2017-10-13 04:35:36 +00:00
# #
2021-06-09 09:39:09 +00:00
set ( PROFILER "" CACHE STRING "Enable performance-measuring tools (and choose which tool to use)" )
2017-10-13 04:35:36 +00:00
2021-06-08 21:12:03 +00:00
if ( PROFILER STREQUAL "gprof" )
2021-05-07 16:25:10 +00:00
MESSAGE ( "Profiler is gprof" )
2021-06-08 21:12:03 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with gprof" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -pg ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with gprof" FORCE )
2021-05-07 16:25:10 +00:00
endif ( )
if ( PROFILER STREQUAL "gcov" )
MESSAGE ( "Profiler is gcov" )
2021-06-08 21:12:03 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with gcov" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with gcov" FORCE )
2021-05-07 16:25:10 +00:00
endif ( )
if ( PROFILER STREQUAL "gperftools" )
MESSAGE ( "Profiler is gperftools" )
2021-06-08 21:12:03 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--no-as-needed,-lprofiler ${LINK_EXTRA_FLAGS_CONFIG}" CACHE STRING "" FORCE )
2021-05-07 16:25:10 +00:00
endif ( )
if ( PROFILER STREQUAL "perf" )
MESSAGE ( "Profiler is perf" )
2021-06-09 03:37:57 +00:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ggdb -fno-omit-frame-pointer ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with perf" FORCE )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ggdb -fno-omit-frame-pointer ${EXTRA_FLAGS_CONFIG}" CACHE STRING "Flags for profiling with perf" FORCE )
2021-05-07 16:25:10 +00:00
endif ( )
2017-10-13 04:35:36 +00:00
# #
2021-06-08 21:12:03 +00:00
# End setting profiler build options
2017-09-30 18:32:41 +00:00
# #
2021-04-29 04:20:05 +00:00
else ( )
2022-03-17 14:02:52 +00:00
set ( CMAKE_CXX_FLAGS "/W3 /WX /wd4503 /wd4351 /wd4250 /wd4244 /wd4267 /we4239 /wd4275 /EHsc /utf-8 /Zc:__cplusplus" CACHE STRING "Global flags used by the CXX compiler during all builds." FORCE )
2022-03-12 19:57:27 +00:00
set ( CMAKE_C_FLAGS "/WX" CACHE STRING "Global flags used by the C compiler during all builds." FORCE )
2023-08-21 00:45:47 +00:00
add_definitions ( -D_WIN32_WINNT=0x0601 -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -DNOMINMAX )
2021-04-29 04:20:05 +00:00
2021-05-07 16:25:10 +00:00
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG_LUA" )
2021-06-28 03:51:47 +00:00
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO" )
2021-05-07 16:25:10 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT" )
2022-01-14 18:32:37 +00:00
2021-04-29 04:20:05 +00:00
# -DNDEBUG is automatically added to all release build types, so manually remove this define from the related variables
2021-05-07 16:25:10 +00:00
RemoveFlag ( CMAKE_CXX_FLAGS_RELEASE CACHE "/DNDEBUG" "Default C++ flags for RELEASE" )
RemoveFlag ( CMAKE_C_FLAGS_RELEASE CACHE "/DNDEBUG" "Default C flags for RELEASE" )
RemoveFlag ( CMAKE_CXX_FLAGS_RELWITHDEBINFO CACHE "/DNDEBUG" "Default C++ flags for RelWithDebInfo" )
RemoveFlag ( CMAKE_C_FLAGS_RELWITHDEBINFO CACHE "/DNDEBUG" "Default C flags for RelWithDebInfo" )
RemoveFlag ( CMAKE_CXX_FLAGS_MINSIZEREL CACHE "/DNDEBUG" "Default C++ flags for MinSizeRel" )
RemoveFlag ( CMAKE_C_FLAGS_MINSIZEREL CACHE "/DNDEBUG" "Default C flags for MinSizeRel" )
2021-05-22 20:38:41 +00:00
endif ( )
2017-09-30 18:32:41 +00:00
2017-11-18 15:10:56 +00:00
# When the path starts with a / on a Unix system it's an absolute path.
# This means that on Windows the path used is always relative.
if ( IS_ABSOLUTE "${LOCALEDIR}" )
2017-11-17 16:28:52 +00:00
add_definitions ( -DHAS_RELATIVE_LOCALEDIR=0 )
2017-11-18 15:10:56 +00:00
set ( LOCALE_INSTALL ${ LOCALEDIR } )
else ( )
add_definitions ( -DHAS_RELATIVE_LOCALEDIR=1 )
set ( LOCALE_INSTALL ${ CMAKE_INSTALL_DATADIR } / ${ DATADIRNAME } / ${ LOCALEDIR } )
endif ( )
2008-05-04 17:27:28 +00:00
2017-11-03 20:30:47 +00:00
add_definitions ( -DFIFODIR= "${FIFO_DIR}" )
2008-05-13 09:11:18 +00:00
2008-05-04 17:27:28 +00:00
if ( PREFERENCES_DIR )
2017-11-23 22:32:04 +00:00
add_definitions ( -DPREFERENCES_DIR= "${PREFERENCES_DIR}" )
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-04 17:27:28 +00:00
2012-03-05 22:36:26 +00:00
if ( DEFAULT_PREFS_FILE )
2017-11-23 22:32:04 +00:00
add_definitions ( -DDEFAULT_PREFS_PATH= "${DEFAULT_PREFS_FILE}" )
2013-05-29 18:27:49 +00:00
2012-03-05 22:36:26 +00:00
if ( NOT DEFAULT_PREFS_FILE MATCHES "^/" )
add_definitions ( -DHAS_RELATIVE_DEFPREF )
2021-05-22 20:38:41 +00:00
endif ( )
endif ( )
2012-03-05 22:36:26 +00:00
2009-05-27 19:08:57 +00:00
if ( ENABLE_DEBUG_WINDOW_LAYOUT )
add_definitions ( -DDEBUG_WINDOW_LAYOUT_GRAPHS )
2021-05-22 20:38:41 +00:00
endif ( )
2009-05-27 19:08:57 +00:00
2008-05-15 13:02:11 +00:00
#
# Libraries that are only required by some targets
#
2017-11-25 17:58:41 +00:00
if ( ENABLE_GAME OR ENABLE_TESTS )
2023-03-08 03:48:58 +00:00
find_package ( CURL REQUIRED )
2017-11-24 21:11:45 +00:00
find_package ( VorbisFile REQUIRED )
2020-12-04 23:21:59 +00:00
find_package ( PkgConfig REQUIRED )
2021-12-15 07:49:52 +00:00
find_package ( Fontconfig REQUIRED )
2024-04-11 17:58:56 +00:00
find_package ( SDL2 2.0.18 REQUIRED )
2021-12-15 08:22:41 +00:00
if ( NOT MSVC )
# for everything else, use pkgconfig
2022-05-05 18:56:27 +00:00
# SDL2_image and SDL2_mixer don't seem to have any cmake configuration available at all
2021-12-15 08:22:41 +00:00
pkg_check_modules ( SDL2IMAGE REQUIRED SDL2_image>=2.0.2 )
pkg_check_modules ( SDL2MIXER REQUIRED SDL2_mixer>=2.0.0 )
else ( )
2022-05-05 18:56:27 +00:00
# for MSVC, vcpkg builds and provides custom SDL2-related modules for cmake to use, so use those
2021-12-15 08:22:41 +00:00
# this also fixes the issue with our previous FindSDL2* scripts incorrectly using the Release version of these libs instead of the Debug version
2022-11-28 05:33:43 +00:00
find_package ( SDL2_image CONFIG REQUIRED )
2022-08-12 23:02:02 +00:00
find_package ( SDL2_mixer CONFIG REQUIRED )
2021-12-15 08:22:41 +00:00
endif ( )
2020-12-04 23:21:59 +00:00
pkg_check_modules ( CAIRO REQUIRED cairo>=1.10 )
2022-09-09 15:28:15 +00:00
pkg_check_modules ( PANGOCAIRO REQUIRED pangocairo>=1.44.0 )
pkg_check_modules ( PANGO REQUIRED pango>=1.44.0 )
2022-01-14 18:32:37 +00:00
pkg_check_modules ( LIBREADLINE readline )
2021-05-22 20:38:41 +00:00
endif ( )
2017-11-25 17:58:41 +00:00
2008-09-12 12:32:47 +00:00
if ( ENABLE_TESTS )
2020-09-28 05:18:55 +00:00
find_package ( Boost ${ BOOST_VERSION } REQUIRED COMPONENTS unit_test_framework )
2021-05-22 20:38:41 +00:00
endif ( )
2015-04-13 06:40:47 +00:00
2009-03-19 23:18:29 +00:00
if ( ENABLE_GAME )
2009-08-10 17:50:37 +00:00
if ( ENABLE_NOTIFICATIONS )
2010-03-03 23:08:31 +00:00
pkg_check_modules ( LIBDBUS dbus-1 )
if ( LIBDBUS_FOUND )
2010-07-30 21:49:42 +00:00
add_definitions ( -DHAVE_LIBDBUS )
2021-05-22 20:38:41 +00:00
else ( )
2010-03-03 23:08:31 +00:00
message ( "Could not find dbus-1, Disabling notification support." )
2021-05-22 20:38:41 +00:00
endif ( )
2014-11-23 13:22:37 +00:00
else ( )
unset ( LIBDBUS_FOUND CACHE )
endif ( )
2009-08-10 17:50:37 +00:00
2021-05-22 21:11:42 +00:00
find_package ( History )
if ( HISTORY_FOUND )
2015-04-13 07:30:57 +00:00
add_definitions ( -DHAVE_HISTORY )
2021-05-22 20:38:41 +00:00
endif ( )
endif ( )
2008-05-15 13:02:11 +00:00
2011-01-02 18:50:00 +00:00
if ( ENABLE_POT_UPDATE_TARGET )
find_package ( TranslationTools REQUIRED )
2021-05-22 20:38:41 +00:00
endif ( )
2011-01-02 18:50:00 +00:00
2008-05-15 14:56:38 +00:00
# get languages
2018-04-29 09:26:01 +00:00
if ( ENABLE_NLS )
2018-04-27 13:49:16 +00:00
file ( READ po/LINGUAS LINGUAS )
string ( REPLACE "\n" "" LINGUAS ${ LINGUAS } )
separate_arguments ( LINGUAS )
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-15 14:56:38 +00:00
#
# Include subdirectories
#
add_subdirectory ( doc )
2009-01-23 12:37:29 +00:00
2023-05-13 02:51:24 +00:00
if ( GETTEXT_FOUND AND Python_FOUND AND ENABLE_NLS )
2010-07-30 21:49:42 +00:00
add_subdirectory ( po )
2021-05-22 20:38:41 +00:00
endif ( )
2010-07-30 21:49:36 +00:00
2008-05-15 14:56:38 +00:00
add_subdirectory ( src )
2008-05-15 13:02:11 +00:00
2008-05-14 13:00:50 +00:00
#
2011-02-12 16:24:56 +00:00
# Install files
2008-05-14 13:00:50 +00:00
#
2018-01-21 23:08:05 +00:00
if ( ENABLE_GAME )
install ( DIRECTORY data fonts images sounds DESTINATION ${ CMAKE_INSTALL_DATADIR } / ${ DATADIRNAME } USE_SOURCE_PERMISSIONS PATTERN ".git" EXCLUDE )
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-14 13:00:50 +00:00
2018-01-21 23:08:05 +00:00
# install file for add-ons server
if ( ENABLE_CAMPAIGN_SERVER AND NOT ENABLE_GAME )
install ( FILES data/COPYING.txt DESTINATION ${ CMAKE_INSTALL_DATADIR } / ${ DATADIRNAME } /data )
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-15 14:56:38 +00:00
2009-04-07 10:24:37 +00:00
#
2009-04-07 11:58:48 +00:00
# Install desktop file so wesnoth appears in the application start menu with an icon
2009-04-07 10:24:37 +00:00
#
2009-04-07 11:58:48 +00:00
if ( ENABLE_DESKTOP_ENTRY AND ENABLE_GAME )
2019-03-27 19:08:17 +00:00
install ( FILES packaging/org.wesnoth.Wesnoth.desktop DESTINATION ${ CMAKE_INSTALL_DATAROOTDIR } /applications )
2021-04-07 22:10:45 +00:00
install ( DIRECTORY packaging/icons/hicolor packaging/icons/HighContrast DESTINATION ${ CMAKE_INSTALL_DATAROOTDIR } /icons )
2021-05-22 20:38:41 +00:00
endif ( )
2009-04-07 10:24:37 +00:00
2017-11-03 13:10:55 +00:00
if ( ENABLE_APPDATA_FILE AND ENABLE_GAME )
2019-03-27 19:08:17 +00:00
install ( FILES packaging/org.wesnoth.Wesnoth.appdata.xml DESTINATION ${ CMAKE_INSTALL_DATAROOTDIR } /metainfo )
2021-05-22 20:38:41 +00:00
endif ( )
2008-05-09 01:49:21 +00:00
2008-05-13 09:11:18 +00:00
if ( ENABLE_SERVER AND FIFO_DIR )
2010-07-30 21:49:42 +00:00
install ( CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory \$ENV{DESTDIR}/${FIFO_DIR})" )
if ( SERVER_UID AND SERVER_GID )
install ( CODE "execute_process(COMMAND chown ${SERVER_UID}:${SERVER_GID} \$ENV{DESTDIR}/${FIFO_DIR})" )
endif ( )
2008-05-15 14:56:38 +00:00
endif ( )
2008-05-14 13:00:50 +00:00
2008-05-09 01:49:21 +00:00
#
2008-05-14 13:00:50 +00:00
# uninstall
2008-05-09 01:49:21 +00:00
#
2008-05-01 20:12:38 +00:00
2008-05-14 13:00:50 +00:00
configure_file (
2015-11-07 08:53:36 +00:00
" $ { C M A K E _ S O U R C E _ D I R } / c m a k e / u n i n s t a l l . c m a k e . i n "
2010-07-30 21:49:42 +00:00
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / u n i n s t a l l . c m a k e "
I M M E D I A T E @ O N L Y
)
2008-05-14 13:00:50 +00:00
add_custom_target ( uninstall
2010-07-30 21:49:42 +00:00
" $ { C M A K E _ C O M M A N D } " - P " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / u n i n s t a l l . c m a k e "
)
2008-05-14 13:00:50 +00:00
#
# Packaging stuff
#
2008-05-09 01:49:21 +00:00
2008-05-15 14:56:38 +00:00
include ( CPack )
set ( CPACK_GENERATOR "TGZ" )
set ( CPACK_SOURCE_GENERATOR "TGZ" )