~widelands-dev/widelands/trunk

10797 by The Widelands Bunnybot
Fix revision detection, bump cmake version (CB #4550 / GH #6207)
1
cmake_minimum_required (VERSION 3.12)
2
cmake_policy(VERSION 3.12)
8866.1.8 by Toni Förster
properly set CMP0054 and set message for GLVND linker flags
3
10608 by The Widelands Bunnybot
Fix Compilation with GCC 13.1 and AppleClang (#5903)
4
project (widelands)
5
9478 by The Widelands Bunnybot
Update CMakeLists.txt (#4161)
6
message(STATUS "Using CMake version ${CMAKE_VERSION}")
7
10650 by The Widelands Bunnybot
Remove superfluous `SDL_GetModState()` calls (#5945)
8
# Detailed help is in README.md
9
# Please update it if you change anything here
7688.1.2 by Tino
unix line endings
10
option(OPTION_USE_GLBINDING "Use glbinding instead of GLEW" OFF)
11
option(OPTION_GLEW_STATIC "Use static GLEW Library" OFF)
7851.1.29 by GunChleoc
Added CMake option to omit building website-related stuff and rescued the English language.
12
option(OPTION_BUILD_WEBSITE_TOOLS "Build website-related tools" ON)
8075.1.3 by GunChleoc
Added commandline switch for translations.
13
option(OPTION_BUILD_TRANSLATIONS "Build translations" ON)
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
14
option(OPTION_BUILD_TESTS "Build tests" ON)
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
15
option(OPTION_BUILD_CODECHECK "Build codecheck" ON)
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
16
option(OPTION_BUILD_WINSTATIC "Build a static linked .exe on windows" OFF)
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
17
option(OPTION_TSAN "Build with ThreadSanitizer" OFF)
10253 by The Widelands Bunnybot
Only use embedded minizip if not installed (#5360)
18
option(OPTION_FORCE_EMBEDDED_MINIZIP "Use embedded minizip sources" OFF)
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
19
option(USE_XDG "Follow XDG-Basedir specification" ON) # Enabled by default
20
10411 by The Widelands Bunnybot
Delete selected text on text input (#5633)
21
set(CMAKE_FIND_FRAMEWORK LAST)
22
9900 by The Widelands Bunnybot
Fix codecheck path magic (#4895)
23
# Absolute path reference for submodules
24
set(WL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
10125 by The Widelands Bunnybot
Dependencies: Asio include handling & Solus support (#5182)
25
26
# Add custom includes to override system libs
27
FILE(GLOB custom_include_directories auto_dependencies/*)
28
foreach(custom_include_dir ${custom_include_directories})
29
  if(IS_DIRECTORY "${custom_include_dir}")
30
    message(STATUS "Using custom include directory '${custom_include_dir}'.")
31
    list(INSERT CMAKE_INCLUDE_PATH 0 "${custom_include_dir}")
32
    include_directories(BEFORE SYSTEM "${custom_include_dir}")
33
  else()
34
    message(WARNING "Not a directory: '${custom_include_dir}' - Ignored.")
35
  endif()
36
endforeach()
37
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
38
include("${CMAKE_SOURCE_DIR}/cmake/UseSystemInfo.cmake")
39
include("${CMAKE_SOURCE_DIR}/cmake/WlFunctions.cmake")
40
10797 by The Widelands Bunnybot
Fix revision detection, bump cmake version (CB #4550 / GH #6207)
41
# This policy is not known to versions prior 3.27 and would result in errors,
42
# if set on such systems. This can be removed when cmake_minimum_required is set
43
# to 3.27 or newer  by using:
44
# cmake_policy(VERSION 3.27)
45
if(POLICY CMP0148)
46
  cmake_policy(SET CMP0148 NEW)
47
endif(POLICY CMP0148)
9464 by The Widelands Bunnybot
CMake Cleanups (#4100)
48
8729.1.1 by Lucki
Add basic XDG support.
49
IF(USE_XDG AND NOT APPLE AND NOT WIN32)
50
  ADD_DEFINITIONS(-DUSE_XDG)
8729.1.16 by GunChleoc
Code review
51
  message(STATUS "Building with XDG support")
8729.1.1 by Lucki
Add basic XDG support.
52
ENDIF(USE_XDG AND NOT APPLE AND NOT WIN32)
53
7688.1.2 by Tino
unix line endings
54
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
55
  message(FATAL_ERROR "Build directory and source directory must not be the same.")
56
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
57
58
# Define the directory structure for installation - will be hardcoded in WL bin
59
# (through config.h). If not specified, we are going to use the directory where
60
# the executable is in. Also on Linux.
61
# Packagers (or people using make install) have to set this variable to an absolute path.
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
62
wl_set_if_unset(WL_INSTALL_BASEDIR ".")
63
64
# Define the directory structure for installation of the data files - will be hardcoded
65
# in WL bin (through config.h). If not specified, we are going to use the "data" directory
66
# below the directory where the executable is in. Also on Linux.
67
# Packagers (or people using make install) have to set this variable to an absolute path.
7293.1.72 by Tino
- define datadir relative to widelands executable
68
wl_set_if_unset(WL_INSTALL_DATADIR "./data")
7688.1.2 by Tino
unix line endings
69
10259 by The Widelands Bunnybot
Move definition of `WL_INSTALL_BINDIR` (#5383)
70
# To override this, use '-DWL_INSTALL_BINDIR=<absolute path>' when configuring or change
71
# 'CMAKE_INSTALL_PREFIX'.
72
# Example: to have the bin installed to "/usr/games", just use '-DCMAKE_INSTALL_PREFIX=/usr'
73
# and don't specify '-DWL_INSTALL_BINDIR' when configuring.
74
# Note: 'CMAKE_INSTALL_PREFIX' defaults to /usr/local on UNIX and c:/Program Files/${PROJECT_NAME} on Windows
10306 by The Widelands Bunnybot
Integrate AppImage building into CI (#5377)
75
wl_set_if_unset(WL_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}/games")
10259 by The Widelands Bunnybot
Move definition of `WL_INSTALL_BINDIR` (#5383)
76
7688.1.2 by Tino
unix line endings
77
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
8270.4.7 by Hans Joachim Desserud
Increase minimum required GCC version to 4.8. Additionally remove some workarounds required by 4.7
78
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
79
    message(FATAL_ERROR "Widelands needs GCC >= 4.8 to compile.")
7688.1.2 by Tino
unix line endings
80
  endif()
10797 by The Widelands Bunnybot
Fix revision detection, bump cmake version (CB #4550 / GH #6207)
81
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
8270.4.9 by Hans Joachim Desserud
Increase minimum required Clang version to 3.4. This is the oldest version we build with on travis
82
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
83
    message(FATAL_ERROR "Clang version must be at least 3.4!")
7688.1.2 by Tino
unix line endings
84
  endif()
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
85
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
10120 by The Widelands Bunnybot
Resolve MSVC warnings (#5157)
86
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
87
    message(FATAL_ERROR "MSVC version must be at least 19!")
88
  endif()
7688.1.2 by Tino
unix line endings
89
else()
90
  message(WARNING "You are using an unsupported compiler! Supported are Clang and GCC.")
91
endif()
10120 by The Widelands Bunnybot
Resolve MSVC warnings (#5157)
92
message(STATUS "Picking up default CXX flags:
93
    - CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'
94
    - CMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}'
95
    - CMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}'")
7688.1.2 by Tino
unix line endings
96
97
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
98
99
if (WIN32)
8919.1.1 by tino79
adapt to changes in appveyor 11/09/18 platform updates
100
  link_libraries(wsock32 ws2_32 bcrypt)
7688.1.2 by Tino
unix line endings
101
endif()
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
102
if (OPTION_BUILD_WINSTATIC)
9975 by The Widelands Bunnybot
Add-Ons Webserver (#4934)
103
  add_definitions(-DGLBINDING_STATIC_DEFINE -DNGHTTP2_STATICLIB)
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
104
  set (OPTION_GLEW_STATIC ON)
10628 by The Widelands Bunnybot
Remove hard-coded library paths for MinGW builds (#5921)
105
  if(MSVC)
106
    set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
107
  else()
108
    set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
109
    set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
110
  endif()
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
111
endif()
7688.1.2 by Tino
unix line endings
112
10797 by The Widelands Bunnybot
Fix revision detection, bump cmake version (CB #4550 / GH #6207)
113
find_package (Python3 REQUIRED)
7688.1.2 by Tino
unix line endings
114
115
find_package(Gettext REQUIRED)
116
find_package(OpenGL REQUIRED)
10411 by The Widelands Bunnybot
Delete selected text on text input (#5633)
117
find_package(PNG 1.6 REQUIRED)
9278 by The Widelands Bunnybot
Improve SDL2 detection on modern systems (#3872)
118
9464 by The Widelands Bunnybot
CMake Cleanups (#4100)
119
find_package(SDL2 REQUIRED)
7688.1.2 by Tino
unix line endings
120
find_package(SDL2_image REQUIRED)
121
find_package(SDL2_mixer REQUIRED)
122
find_package(SDL2_ttf REQUIRED)
123
find_package(ZLIB REQUIRED)
9491 by The Widelands Bunnybot
Fix CMake packages on Xenial (#4181)
124
if(${CMAKE_VERSION} VERSION_LESS 3.9.0)
9478 by The Widelands Bunnybot
Update CMakeLists.txt (#4161)
125
    find_package(ICU_old REQUIRED)
126
else()
127
    find_package(ICU REQUIRED COMPONENTS uc dt)
128
endif()
7688.1.2 by Tino
unix line endings
129
if(OPTION_USE_GLBINDING)
130
  find_package(glbinding REQUIRED)
131
else()
132
  find_package(GLEW REQUIRED)
133
endif()
134
10125 by The Widelands Bunnybot
Dependencies: Asio include handling & Solus support (#5182)
135
# Check that Asio is installed. Asio does not have (or need) a Find… CMake Module, so we "only" need to check if the header exists.
136
if(NOT asio_location OR asio_location STREQUAL "")
137
  unset(asio_location CACHE)
138
  find_path(asio_location "asio.hpp")
139
  if(asio_location)
140
    message(STATUS "Found Asio in '${asio_location}'.")
141
  else()
142
    message(FATAL_ERROR "Could NOT find Asio (missing: asio.hpp). Please run:\n./install-dependencies.sh\nwhich will attempt to install all missing dependencies automatically, or provide further instructions if this not supported on your system.")
143
  endif()
144
endif()
145
add_definitions(-DASIO_STANDALONE)
146
8075.1.3 by GunChleoc
Added commandline switch for translations.
147
if (APPLE OR WIN32 OR
148
    CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR
8024 by Holger Rapp
OpenBSD build patch by David Carlier.
149
    CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
7688.1.2 by Tino
unix line endings
150
  if (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
9464 by The Widelands Bunnybot
CMake Cleanups (#4100)
151
    find_package(Intl REQUIRED)
7688.1.2 by Tino
unix line endings
152
  endif()
153
endif()
154
8790.1.1 by Holger Rapp
Attempt to fix the Mac OS X nightlies.
155
# Disable no symbols warning on macOS, but only on versions where this is
156
# supported. It is not supported on OS X 10.7 (DARWIN_MAJOR_VERSION == 11).
8790.1.2 by GunChleoc
Fix CMake for Linux.
157
if (APPLE)
158
    if (${DARWIN_MAJOR_VERSION} GREATER 11)
159
        SET(CMAKE_C_ARCHIVE_CREATE   "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
160
        SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
161
        SET(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
162
        SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
163
    endif()
8778.2.8 by Toni Förster
Disable no symbols warning on macOS
164
endif()
165
7688.1.2 by Tino
unix line endings
166
# TODO(sirver): One day, this should be enabled. Then we have no more cycles in our dependencies....
167
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_NO_CYCLES ON)
168
169
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
170
  find_path(FILE_WL_RELEASE "WL_RELEASE" ${CMAKE_CURRENT_SOURCE_DIR})
171
  if(${FILE_WL_RELEASE} STREQUAL "FILE_WL_RELEASE-NOTFOUND")
172
    set(CMAKE_BUILD_TYPE Debug)
173
  else()
174
    set(CMAKE_BUILD_TYPE Release)
175
  endif()
176
endif (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
177
178
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
10120 by The Widelands Bunnybot
Resolve MSVC warnings (#5157)
179
  set(WL_DEBUG_FLAGS "-DDEBUG")
180
  if(NOT MSVC)
181
    wl_add_flag(WL_DEBUG_FLAGS "-g")
182
    if(NOT OPTION_TSAN)
183
      option(OPTION_ASAN "Build with AddressSanitizer" ON)
184
    endif()
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
185
  endif()
10650 by The Widelands Bunnybot
Remove superfluous `SDL_GetModState()` calls (#5945)
186
elseif((CMAKE_BUILD_TYPE STREQUAL "Release") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
10402 by The Widelands Bunnybot
Drop support for g++-5 and g++-6 (#5541)
187
  if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.5))
188
    message(STATUS "GCC >7.5.0 breaks -O3, setting -O2")
8307.1.1 by Tino
when using GCC 6.3 only do -O2
189
    set(WL_OPTIMIZE_FLAGS "-O2")
10120 by The Widelands Bunnybot
Resolve MSVC warnings (#5157)
190
  elseif(MSVC)
191
    set(WL_OPTIMIZE_FLAGS "/O2")
8307.1.1 by Tino
when using GCC 6.3 only do -O2
192
  else()
193
    set(WL_OPTIMIZE_FLAGS "-O3")
10650 by The Widelands Bunnybot
Remove superfluous `SDL_GetModState()` calls (#5945)
194
  endif()
10402 by The Widelands Bunnybot
Drop support for g++-5 and g++-6 (#5541)
195
  if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.6))
196
    message(WARNING "GCC <7.6.0 is known to cause segfaults in release builds. Please consider upgrading to GCC version 7.6 or newer or using Clang. Adding selected overrides to suppress reporting of known bugs.")
10124 by The Widelands Bunnybot
Fix older g++ optimization segfaults (#5176)
197
    wl_add_flag(WL_OPTIMIZE_FLAGS "--param asan-stack=0")
198
  endif()
7688.1.2 by Tino
unix line endings
199
  set(WL_DEBUG_FLAGS "-DNDEBUG -DNOPARACHUTE")
8508.1.1 by Holger Rapp
Only include ASAN in debug builds by default.
200
  option(OPTION_ASAN "Build with AddressSanitizer" OFF)
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
201
elseif(CMAKE_BUILD_TYPE STREQUAL "None")
202
  message(STATUS "Not setting any default flags.")
7688.1.2 by Tino
unix line endings
203
else()
204
  message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
205
endif()
206
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
207
if(OPTION_TSAN)
208
  message(STATUS "Using ThreadSanitizer https://clang.llvm.org/docs/ThreadSanitizer.html")
209
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-fsanitize=thread")
210
  set (CMAKE_EXE_LINKER_FLAGS "-fsanitize=thread" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
211
  option(OPTION_ASAN "Build with AddressSanitizer" OFF)
212
else()
213
  message(STATUS "Not using ThreadSanitizer.")
214
endif(OPTION_TSAN)
7688.1.2 by Tino
unix line endings
215
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
216
if(OPTION_ASAN)
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
217
  message(STATUS "Using AddressSanitizer https://clang.llvm.org/docs/AddressSanitizer.html")
218
  # See https://clang.llvm.org/docs/AddressSanitizer.html
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
219
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-fsanitize=address")
220
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-fno-omit-frame-pointer")
221
  set (CMAKE_EXE_LINKER_FLAGS "-fsanitize=address" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
10738 by The Widelands Bunnybot
Self-diagnose crashes (#6100)
222
  add_definitions(-DUSE_ASAN)
8508.1.1 by Holger Rapp
Only include ASAN in debug builds by default.
223
else()
224
  message(STATUS "Not using AddressSanitizer.")
8496.1.1 by GunChleoc
Added compile options for AddressSanitizer and for choosing the compiler. 2 new warning flags for the clang compiler.
225
endif(OPTION_ASAN)
226
10070 by The Widelands Bunnybot
Resolve thread sanitizer issues (#5114)
227
if(OPTION_ASAN AND OPTION_TSAN)
228
  message(FATAL_ERROR "OPTION_ASAN and OPTION_TSAN cannot be used together")
229
endif()
230
8866.1.6 by Toni Förster
add description remove unneeded line
231
# This is set to avoid linker errors when using GLVND-libs on Linux
8866.1.4 by Toni Förster
set additional linker flags
232
if("${OpenGL_GL_PREFERENCE}" STREQUAL "GLVND")
10205 by The Widelands Bunnybot
Fetched translations and updated catalogs.
233
   link_libraries(OpenGL::GL)
8866.1.14 by Toni Förster
add compile definition for GLVND
234
   add_compile_definitions(WL_USE_GLVND)
8866.1.8 by Toni Förster
properly set CMP0054 and set message for GLVND linker flags
235
   message(STATUS "Adding linker flags for GLVND.")
8866.1.4 by Toni Förster
set additional linker flags
236
endif()
237
7688.1.2 by Tino
unix line endings
238
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
10221 by The Widelands Bunnybot
CMakeLists.txt: Use a list for many build flags (#5328)
239
  set(warn_disable_flags
240
    "-Weverything"
241
242
    # Disabled warnings that are overly verbose right now or just do not make sense.
243
    "-Wno-c++98-compat"
244
    "-Wno-c++98-compat-pedantic"
245
    "-Wno-conversion"
246
    "-Wno-exit-time-destructors"
247
    "-Wno-global-constructors"
248
    "-Wno-padded"
249
    "-Wno-sign-conversion"
250
    "-Wno-missing-noreturn"
251
252
    # It is impossible to write code that both GCC and Clang will like,
253
    # so we have to switch off the warning for one of them.
254
    # http://clang-developers.42468.n3.nabble.com/Question-on-Wswitch-enum-td4025927.html
255
    "-Wno-switch-enum"
256
257
    # TODO(sirver: weak-vtables should be enabled, but leads to lot of errors right now.
258
    "-Wno-weak-vtables"
259
    "-Wno-unreachable-code"
260
    "-Wno-documentation"
261
    "-Qunused-arguments"
262
    "-Wint-to-void-pointer-cast"
263
  )
264
  foreach(flag IN LISTS warn_disable_flags)
265
    wl_add_flag(WL_COMPILE_DIAGNOSTICS ${flag})
266
  endforeach()
267
8496.1.2 by GunChleoc
Older Clang versions to not recognize Winconsistent-missing-override.
268
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8)
10221 by The Widelands Bunnybot
CMakeLists.txt: Use a list for many build flags (#5328)
269
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Winconsistent-missing-override")
8496.1.2 by GunChleoc
Older Clang versions to not recognize Winconsistent-missing-override.
270
  endif()
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
271
elseif(MSVC)
10448 by The Widelands Bunnybot
Fix clang-tidy C++17 checks (#5679)
272
  wl_add_flag(WL_GENERIC_CXX_FLAGS "/std:c++17")
10120 by The Widelands Bunnybot
Resolve MSVC warnings (#5157)
273
  # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/
274
  # Disabled warnings that are overly verbose right now or just do not make sense.
275
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "/wd4244")
276
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "/wd4267")
277
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "/wd4018")
278
  # Use correct code page
279
  wl_add_flag(WL_GENERIC_CXX_FLAGS "/utf-8")
7688.1.2 by Tino
unix line endings
280
else()
8270.4.7 by Hans Joachim Desserud
Increase minimum required GCC version to 4.8. Additionally remove some workarounds required by 4.7
281
  # Assuming GCC 4.8 or higher.
7688.1.2 by Tino
unix line endings
282
  if(WIN32)
283
    # This is needed for getenv().
10444 by The Widelands Bunnybot
Switch to C++17 (#5672)
284
    wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=gnu++17")
9468 by The Widelands Bunnybot
Build a static linked executable with msys2 (Appveyor&Github Workflow) (#3982)
285
    if (OPTION_BUILD_WINSTATIC)
286
      set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ ${CMAKE_CXX_STANDARD_LIBRARIES}")
287
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic")
288
    endif()
8349.4.20 by GunChleoc
Fixed the reduntant decls flag for windows.
289
  else()
290
    # SDL and MinGW both declare 'unsigned int __builtin_ia32_crc32qi(unsigned int, unsigned char)', resulting in lots of warnings. So, we can't have this flag in Windows.
291
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wredundant-decls")
7688.1.2 by Tino
unix line endings
292
  endif()
293
10221 by The Widelands Bunnybot
CMakeLists.txt: Use a list for many build flags (#5328)
294
  set(warn_flags
295
    "-Wall"
296
    "-Wpedantic"
297
    "-Wdeprecated-declarations"
298
    "-Wextra"
299
    "-Wformat"
300
    "-Wformat-nonliteral"
301
    "-Wformat-security"
302
    "-Wformat-y2k"
303
    "-Winit-self"
304
    "-Winvalid-pch"
305
    "-Wmissing-include-dirs"
306
    "-Wno-undef"
307
    "-Wold-style-cast"
308
    "-Woverlength-strings"
309
    "-Wpacked"
310
    "-Wpointer-arith"
311
    "-Wsign-promo"
312
    "-Wundef"
313
    "-Wunused"
314
    "-Wunused-macros"
315
    "-fno-elide-constructors" # Detect invalid constexpr initialization
316
  )
317
  foreach(flag IN LISTS warn_flags)
318
    wl_add_flag(WL_COMPILE_DIAGNOSTICS ${flag})
319
  endforeach()
10608 by The Widelands Bunnybot
Fix Compilation with GCC 13.1 and AppleClang (#5903)
320
  if (NOT APPLE)
321
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wlogical-op")
322
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wsync-nand")
323
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wtrampolines")
324
  endif()
7688.1.2 by Tino
unix line endings
325
endif()
326
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
327
if(NOT MSVC)
10363 by The Widelands Bunnybot
Fix Spelling Errors in Comments (#5512)
328
  if(CMAKE_BUILD_TYPE STREQUAL "Release")
329
    message(STATUS "Compiler warnings will be ignored.")
10608 by The Widelands Bunnybot
Fix Compilation with GCC 13.1 and AppleClang (#5903)
330
  elseif(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (
331
         ((NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0)) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.2))
10688 by The Widelands Bunnybot
Resolve compiler warnings (#6021)
332
         OR (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0)) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.1)))
333
    # Skip this on g++ versions 12.0, 12.1, and 13.0 because of false-positives from system headers.
10281 by The Widelands Bunnybot
Update testsuite compilers and OSs for Jammy (#5415)
334
    message(WARNING "This compiler is known to cause false-positive warnings.")
335
  else()
10363 by The Widelands Bunnybot
Fix Spelling Errors in Comments (#5512)
336
    # Turn some warnings into errors.
337
    message(STATUS "Warnings will be treated as errors.")
10281 by The Widelands Bunnybot
Update testsuite compilers and OSs for Jammy (#5415)
338
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror")
10363 by The Widelands Bunnybot
Fix Spelling Errors in Comments (#5512)
339
    if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0))
340
      # Silence some false positives on older g++
341
      message(STATUS "Disabling known false-positive warnings for this compiler.")
342
      wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-error=unused-variable")
343
      wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-error=unused-but-set-parameter")
344
    endif()
345
    if (APPLE)  # Our Mac CI needs these
346
      message(STATUS "Disabling known false-positive warnings for this environment.")
347
      wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-error=poison-system-directories")
348
      wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-error=disabled-macro-expansion")
349
    endif()
10036 by The Widelands Bunnybot
Build System Update (#5085)
350
  endif()
8182.2.23 by GunChleoc
All those #ifdef _WIN32 blocks are annoying, let's just try to get rid of -Wswitch-default in Windows.
351
10444 by The Widelands Bunnybot
Switch to C++17 (#5672)
352
  wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=c++17")
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
353
endif()
7688.1.2 by Tino
unix line endings
354
9392 by The Widelands Bunnybot
Add cross-compile-unit optimization with Linux GCC. (#3879)
355
# Cross-compile-unit optimization slows linking significantly.
356
# Therefore, impatient user may want to prevent that.
357
if(USE_FLTO_IF_AVAILABLE STREQUAL "yes")
358
# Cross-compile-unit optimization not supported by gcc with debug on!
359
# Therefore, this may only be done with Release builds.
360
if(CMAKE_BUILD_TYPE STREQUAL "Release")
361
  # Only tested on Linux. Might work also on other platforms.
362
  # If tested and found good, remove this check
363
  if (CMAKE_SYSTEM MATCHES "Linux")
364
    # Usage of -flto tested only with gcc 8.3 and 9.3 (2020-04); when in doubt, leaving it out..
365
    if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0))
366
      #
367
      # The execution jumps between compile units rather often. -flot allows optimization across
368
      # comple units. Binary size reduced by >15% on tested environments. This does not directly
369
      # translate to execution speed, but might still be noticeable.
370
      #
371
      # This is not related to -O2 or -O3 discussion, and not enable by either.
372
      #
373
      # If using lto, it needs to happen both during compile and link, else no benefits.
374
      wl_add_flag(WL_GENERIC_CXX_FLAGS "-flto")
375
      SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -flto")
376
      message(STATUS "Enabling link-time optimizations")
377
    endif()
378
  endif(CMAKE_SYSTEM MATCHES "Linux")
379
endif(CMAKE_BUILD_TYPE STREQUAL "Release")
380
endif(USE_FLTO_IF_AVAILABLE STREQUAL  "yes")
381
7688.1.2 by Tino
unix line endings
382
IF (WIN32)
10115 by The Widelands Bunnybot
Replace Boost::Asio → Asio (#5164)
383
  add_definitions(-D_WIN32_WINNT=0x0601)
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
384
  if(MSVC)
10115 by The Widelands Bunnybot
Replace Boost::Asio → Asio (#5164)
385
    add_definitions(-DWIN32_LEAN_AND_MEAN -D__STDC_FORMAT_MACROS -DNOMINMAX)
9660 by The Widelands Bunnybot
Fix formatting action for branches on origin (#4500)
386
    # Needed for minizip
387
    add_definitions(-Dor=|| -Dand=&& -Dnot=!)
388
  else()
389
    add_definitions(-DMINGW_HAS_SECURE_API -DWIN32_LEAN_AND_MEAN -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO)
390
    if (CMAKE_SIZEOF_VOID_P EQUAL 4)
391
      set (CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
392
      message (STATUS "Enabled large address awareness on mingw32")
393
    else (CMAKE_SIZEOF_VOID_P EQUAL 4)
394
      message (STATUS "Detected mingw32-w64")
395
    endif (CMAKE_SIZEOF_VOID_P EQUAL 4)
396
  endif()
10688 by The Widelands Bunnybot
Resolve compiler warnings (#6021)
397
else()
398
  add_definitions(-DLUA_USE_POSIX)
10628 by The Widelands Bunnybot
Remove hard-coded library paths for MinGW builds (#5921)
399
endif()
400
401
if(OPTION_BUILD_WINSTATIC)
402
  # Add required libraries for statical linking
10740 by The Widelands Bunnybot
Fix MinGW library linking order (#6111)
403
  wl_add_static_libs(SDL_IMG_STATIC_LIBS tiff jpeg lzma)
10618 by The Widelands Bunnybot
Resolve static libraries during configuration (#5914)
404
  wl_add_static_libs(SDL_MIXER_STATIC_LIBS opusfile opus FLAC vorbisfile vorbis ogg mpg123 shlwapi)
10628 by The Widelands Bunnybot
Remove hard-coded library paths for MinGW builds (#5921)
405
  wl_add_static_libs(SDL_TTF_STATIC_LIBS freetype bz2 graphite2 usp10 dwrite harfbuzz freetype rpcrt4)
406
  wl_add_static_libs(SDL_STATIC_LIBS intl iconv dinput8 shell32 setupapi advapi32 uuid version oleaut32 ole32 imm32 winmm gdi32 user32)
10783 by The Widelands Bunnybot
Rename brotli static dependency (GH #6177 / CB #4519)
407
  set(BROTLI brotlidec brotlicommon brotlienc)
10628 by The Widelands Bunnybot
Remove hard-coded library paths for MinGW builds (#5921)
408
  if(MSVC)
409
    wl_add_static_libs(SDL_IMG_STATIC_LIBS libwebp)
410
    wl_add_static_libs(SDL_STATIC_LIBS charset ${BROTLI})
411
    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
412
      string(REPLACE "/MDd" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
413
      wl_add_flag(TARGET_COMPILE_FLAGS "/MTd /EHsc")
414
    else()
415
      string(REPLACE "/MD" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
416
      wl_add_flag(TARGET_COMPILE_FLAGS "/MT /EHsc")
417
    endif()
418
  else()
10828 by The Widelands Bunnybot
Fix msys2 win builds (GH #6265 / CB #4604)
419
    wl_add_static_libs(SDL_IMG_STATIC_LIBS webp webpdemux webpdecoder jbig deflate Lerc jxl hwy sharpyuv)
10628 by The Widelands Bunnybot
Remove hard-coded library paths for MinGW builds (#5921)
420
    wl_add_static_libs(SDL_MIXER_STATIC_LIBS ssp)
421
    wl_add_static_libs(SDL_STATIC_LIBS mingw32 dxerr8 zstd ${BROTLI})
422
  endif(MSVC)
423
endif(OPTION_BUILD_WINSTATIC)
7688.1.2 by Tino
unix line endings
424
10738 by The Widelands Bunnybot
Self-diagnose crashes (#6100)
425
if(NOT OPTION_ASAN)
426
  # Allow self-diagnosis for crashes if the system supports it (uses a GNU extension)
427
  find_path(has_execinfo "execinfo.h")
428
  if(has_execinfo)
429
    message(STATUS "Adding crash self-diagnosis handler.")
430
    add_definitions(-DPRINT_SEGFAULT_BACKTRACE)
431
    if(NOT WIN32)
432
      # Needed for human-readable-ish symbolizing; doesn't hurt performance, see https://stackoverflow.com/q/12634114
433
      SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
434
    endif()
435
  endif()
436
endif()
437
7688.1.2 by Tino
unix line endings
438
# on BSD this must be explicitly linked
439
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
440
  # Not needed on Debian GNU/kFreeBSD..
441
  if (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
442
    find_library(EXECINFO_LIBRARY NAMES execinfo)
443
  endif (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
8035.1.1 by Hans Joachim Desserud
When building on OpenBSD, compilation fails to find and include GL/glu.h unless the X11 include dir is added
444
8035.1.2 by Hans Joachim Desserud
Comment style
445
  # OpenBSD needs the X11 include directory in order to find GL/glu.h
8035.1.1 by Hans Joachim Desserud
When building on OpenBSD, compilation fails to find and include GL/glu.h unless the X11 include dir is added
446
  if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
447
    find_package(X11 REQUIRED)
448
    include_directories(${X11_INCLUDE_DIR})
449
  endif ()
7688.1.2 by Tino
unix line endings
450
endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
451
452
if (NOT DEFINED WL_VERSION)
8853 by tino79
quick fix revision detection
453
  include (${CMAKE_SOURCE_DIR}/cmake/BzrRevision.cmake)
7688.1.2 by Tino
unix line endings
454
else (NOT DEFINED WL_VERSION)
455
  add_custom_target (
456
    InputRevision ALL
9098 by Dmitry Marakasov
Fix typo in CMakeLists.txt
457
    COMMAND ${CMAKE_COMMAND} -DWL_INSTALL_BASEDIR=${WL_INSTALL_BASEDIR} -DWL_VERSION=${WL_VERSION} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/InputRevision.cmake
7688.1.2 by Tino
unix line endings
458
  )
459
endif (NOT DEFINED WL_VERSION)
460
461
# Enable testing.
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
462
if (OPTION_BUILD_TESTS)
463
  include(CTest)
464
  enable_testing()
7688.1.2 by Tino
unix line endings
465
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
466
  # Run a test after a normal compile. This magic is needed as 'make test' will
467
  # not rebuild tests:
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
468
  # https://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests
9148.2.1 by Notabilis
Adding compile.sh switch -s to skip building the tests.
469
  add_custom_target(_run_all_tests ALL
470
    COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
471
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
472
    DEPENDS wl_tests
473
  )
474
endif (OPTION_BUILD_TESTS)
7688.1.2 by Tino
unix line endings
475
476
install (
477
  FILES ${CMAKE_CURRENT_BINARY_DIR}/VERSION
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
478
  DESTINATION ${WL_INSTALL_BASEDIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
479
  CONFIGURATIONS Debug;Release;None
7688.1.2 by Tino
unix line endings
480
  COMPONENT CoreVersionFile
481
)
482
483
# Installation.
484
add_subdirectory(doc)
8075.1.3 by GunChleoc
Added commandline switch for translations.
485
if(OPTION_BUILD_TRANSLATIONS)
486
  add_subdirectory(po)
487
endif(OPTION_BUILD_TRANSLATIONS)
7688.1.2 by Tino
unix line endings
488
add_subdirectory(src)
489
490
# install files to the correct locations here
491
install(
9942 by The Widelands Bunnybot
Autogenerate and compare datadir version file (#4853)
492
  FILES
493
    data/datadirversion
494
  DESTINATION ${WL_INSTALL_DATADIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
495
  CONFIGURATIONS Debug;Release;None
9942 by The Widelands Bunnybot
Autogenerate and compare datadir version file (#4853)
496
  COMPONENT VersionFile
497
)
498
499
install(
7688.1.2 by Tino
unix line endings
500
  DIRECTORY
8412.1.1 by tiborb95 at gmail
inserted missing ai entry in CMakeList.txt
501
    data/ai
7293.1.6 by fios at foramnagaidhlig
Moved scripting to data/scripting.
502
    data/campaigns
7293.1.11 by fios at foramnagaidhlig
Some cleanup.
503
    data/i18n
7293.1.43 by fios at foramnagaidhlig
Merged trunk.
504
    data/images
505
    data/scripting
7802 by Holger Rapp
Unbreak installations: install shaders directory.
506
    data/shaders
8711 by GunChleoc
Added templates dir to CMake install.
507
    data/templates
7293.1.8 by fios at foramnagaidhlig
Moved tribes to data/tribes.
508
    data/tribes
7293.1.9 by fios at foramnagaidhlig
Moved txts to data/txts and txts/languages to data/i18n/languages.
509
    data/txts
7293.1.10 by fios at foramnagaidhlig
Moved world to data/world.
510
    data/world
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
511
  DESTINATION ${WL_INSTALL_DATADIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
512
  CONFIGURATIONS Debug;Release;None
7688.1.2 by Tino
unix line endings
513
  COMPONENT CoreDataFiles
514
)
515
516
install(
517
  DIRECTORY
7293.1.4 by fios at foramnagaidhlig
Moved maps to data/maps.
518
    data/maps
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
519
  DESTINATION ${WL_INSTALL_DATADIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
520
  CONFIGURATIONS Debug;Release;None
7688.1.2 by Tino
unix line endings
521
  COMPONENT MapFiles
522
)
523
524
install(
525
  DIRECTORY
7293.1.5 by fios at foramnagaidhlig
Moved music to data/music and sound to data/sound. All paths are now relative to these 2 directories. Moved the duck's sounds to data/sound/animals.
526
    data/music
527
    data/sound
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
528
  DESTINATION ${WL_INSTALL_DATADIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
529
  CONFIGURATIONS Debug;Release;None
7688.1.2 by Tino
unix line endings
530
  COMPONENT MusicFiles
531
)
532
533
install(
534
  FILES
535
    COPYING
536
    CREDITS
537
    ChangeLog
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
538
  DESTINATION ${WL_INSTALL_BASEDIR}
9974 by The Widelands Bunnybot
cmake: add support for None build type (#5010)
539
  CONFIGURATIONS Debug;Release;None
7688.1.2 by Tino
unix line endings
540
  COMPONENT CoreLicenseFiles
541
)
542
543
install(
544
  DIRECTORY
545
    doc
7293.1.44 by fios at foramnagaidhlig
Scrapped the ImageCatalog. The datadir is now "./data" on a global level (CMake, g_fs).
546
  DESTINATION ${WL_INSTALL_BASEDIR}
7688.1.2 by Tino
unix line endings
547
  CONFIGURATIONS Debug
548
  COMPONENT DocFiles
549
  PATTERN "CMakeLists.txt" EXCLUDE
550
)
551
10204 by The Widelands Bunnybot
Skip installing locales when translations are disabled (#5302)
552
if(OPTION_BUILD_TRANSLATIONS)
553
  set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${WL_INSTALL_DATADIR}/locale)
554
  install(
555
    DIRECTORY
556
      ${CMAKE_CURRENT_BINARY_DIR}/locale/
557
    DESTINATION ${WL_INSTALL_DATADIR}/locale
558
    CONFIGURATIONS Debug;Release;None
559
    COMPONENT CoreLanguageFiles
560
  )
561
endif(OPTION_BUILD_TRANSLATIONS)
9204 by The Widelands Bunnybot
Noordfrees: Launchpad mirror (#3766)\n\nMirrors all changes at widelands:master to lp:widelands (1d6b62c7619a182081e1c942ae533a95d6112044)
562
563
if (UNIX AND NOT APPLE)
564
  add_subdirectory(xdg)
565
endif (UNIX AND NOT APPLE)
10268 by The Widelands Bunnybot
CMakeLists.txt: add custom uninstall target (#5358)
566
567
# uninstall target
568
# see https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
569
if(NOT TARGET uninstall)
570
  configure_file(
571
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
572
    "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
573
    IMMEDIATE @ONLY)
574
575
  add_custom_target(uninstall
576
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
577
endif()
578