File: CMakeLists.txt

package info (click to toggle)
widelands 1:19+repack-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 371,172 kB
  • sloc: cpp: 108,458; ansic: 18,695; python: 5,155; sh: 487; xml: 460; makefile: 229
file content (323 lines) | stat: -rw-r--r-- 11,548 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
project (widelands)

cmake_minimum_required (VERSION 2.8.7)

include("${CMAKE_SOURCE_DIR}/cmake/WlFunctions.cmake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/Modules)

option(OPTION_USE_GLBINDING "Use glbinding instead of GLEW" OFF)
option(OPTION_GLEW_STATIC "Use static GLEW Library" OFF)
option(OPTION_BUILD_WEBSITE_TOOLS "Build website-related tools" ON)
option(OPTION_BUILD_TRANSLATIONS "Build translations" ON)

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
  message(FATAL_ERROR "Build directory and source directory must not be the same.")
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)

# Define the directory structure for installation - will be hardcoded in WL bin
# (through config.h). If not specified, we are going to use the directory where
# the executable is in. Also on Linux.
# Packagers (or people using make install) have to set this variable to an absolute path.
wl_set_if_unset(WL_INSTALL_BASEDIR ".")

# Define the directory structure for installation of the data files - will be hardcoded
# in WL bin (through config.h). If not specified, we are going to use the "data" directory
# below the directory where the executable is in. Also on Linux.
# Packagers (or people using make install) have to set this variable to an absolute path.
wl_set_if_unset(WL_INSTALL_DATADIR "./data")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
    message(FATAL_ERROR "Widelands needs GCC >= 4.7 to compile.")
  endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
    message(FATAL_ERROR "Clang version must be at least 3.2!")
  endif()
else()
  message(WARNING "You are using an unsupported compiler! Supported are Clang and GCC.")
endif()

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)

if (WIN32)
  set (Boost_USE_STATIC_LIBS  ON)
else()
  set (Boost_USE_STATIC_LIBS  OFF)
endif()
set (Boost_USE_MULTITHREADED ON)
set (Boost_DETAILED_FAILURE_MSG ON)
find_package(Boost 1.48
  COMPONENTS
    unit_test_framework
    regex
  REQUIRED)

find_package (PythonInterp REQUIRED)

find_package(Gettext REQUIRED)
find_package(OpenGL REQUIRED)
find_package(PNG REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_net REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(ZLIB REQUIRED)
find_package(ICU REQUIRED)
find_package(Minizip)

if(OPTION_USE_GLBINDING)
  find_package(glbinding REQUIRED)
else()
  find_package(GLEW REQUIRED)
endif()

if (APPLE OR WIN32 OR
    CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR
    CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  if (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
    find_package(intl REQUIRED)
  endif()
endif()

# TODO(sirver): One day, this should be enabled. Then we have no more cycles in our dependencies....
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_NO_CYCLES ON)

if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
  find_path(FILE_WL_RELEASE "WL_RELEASE" ${CMAKE_CURRENT_SOURCE_DIR})
  if(${FILE_WL_RELEASE} STREQUAL "FILE_WL_RELEASE-NOTFOUND")
    set(CMAKE_BUILD_TYPE Debug)
  else()
    set(CMAKE_BUILD_TYPE Release)
  endif()
endif (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(WL_DEBUG_FLAGS "-g -DDEBUG")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
  set(WL_OPTIMIZE_FLAGS "-g -O3")
  set(WL_DEBUG_FLAGS "-DNDEBUG -DNOPARACHUTE")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  set(WL_OPTIMIZE_FLAGS "-O3")
  set(WL_DEBUG_FLAGS "-g -DNDEBUG -DNOPARACHUTE")
else()
  message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()

wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=c++11")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Weverything")

  # Disabled warnings that are overly verbose right now or just do not make sense.
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-c++98-compat")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-c++98-compat-pedantic")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-conversion")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-exit-time-destructors")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-global-constructors")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-padded")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-sign-conversion")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-missing-noreturn")

  # TODO(sirver): weak-vtables should be enabled, but leads to lot of errors right now.
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-weak-vtables")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-unreachable-code")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-documentation")

  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=deprecated")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=non-pod-varargs")

  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Qunused-arguments")
else()
  # Assuming GCC 4.7 or higher.
  if(WIN32)
    # This is needed for getenv().
    wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=gnu++11")
  else()
    # 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.
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wredundant-decls")
  endif()

  if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8))
     # Because of: https://svn.boost.org/trac/boost/ticket/9240.
     wl_add_flag(WL_GENERIC_CXX_FLAGS "-fext-numeric-literals")
  endif()

  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
    # g++-4.7 complains otherwise about <:: not being a valid token in
    # unique_ptr<::Something>. Since this is common style in c++ though, we'd
    # rather have it swallow this frog for us.
    wl_add_flag(WL_GENERIC_CXX_FLAGS "-fpermissive")
  endif()

  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wall")
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-pedantic")
  else()
    wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wpedantic")
  endif()
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wdeprecated-declarations")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wextra")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wformat")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wformat-nonliteral")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wformat-security")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wformat-y2k")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Winit-self")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Winvalid-pch")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wlogical-op")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wmissing-include-dirs")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wno-undef")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wold-style-cast")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Woverlength-strings")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wpacked")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wpointer-arith")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wsign-promo")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wsync-nand")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wtrampolines")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wundef")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wunused")
  wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Wunused-macros")
endif()

# Turn some warnings into errors.
wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=format-security")
wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=return-type")
wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=shadow")
wl_add_flag(WL_COMPILE_DIAGNOSTICS "-Werror=uninitialized")

IF (WIN32)
  add_definitions(-DMINGW_HAS_SECURE_API)
  if (CMAKE_SIZEOF_VOID_P EQUAL 4)
    set (CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
    message (STATUS "Enabled large address awareness on mingw32")
  else (CMAKE_SIZEOF_VOID_P EQUAL 4)
    message (STATUS "Detected mingw32-w64")
  endif (CMAKE_SIZEOF_VOID_P EQUAL 4)
endif (WIN32)

# on BSD this must be explicitly linked
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  # Not needed on Debian GNU/kFreeBSD..
  if (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")
    find_library(EXECINFO_LIBRARY NAMES execinfo)
  endif (NOT CMAKE_SYSTEM_NAME MATCHES "kFreeBSD")

  # OpenBSD needs the X11 include directory in order to find GL/glu.h
  if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
    find_package(X11 REQUIRED)
    include_directories(${X11_INCLUDE_DIR})
  endif ()
endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")

if (NOT DEFINED WL_VERSION)
  add_custom_target (
    BzrRevision ALL
    COMMAND ${CMAKE_COMMAND} -DWL_INSTALL_BASEDIR=${WL_INSTALL_BASEDIR} -DWL_INSTALL_DATADIR=${WL_INSTALL_DATADIR} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/BzrRevision.cmake
  )

  # Detect version now
  execute_process (
    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/detect_revision.py
    OUTPUT_VARIABLE WL_VERSION
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/VERSION "${WL_VERSION}")
  configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/build_info.cc.cmake ${CMAKE_CURRENT_BINARY_DIR}/src/build_info.cc)
  message (STATUS "Version of Widelands Build is ${WL_VERSION}(${CMAKE_BUILD_TYPE})")
else (NOT DEFINED WL_VERSION)
  add_custom_target (
    InputRevision ALL
    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
  )
endif (NOT DEFINED WL_VERSION)

# Enable testing.
include(CTest)
enable_testing()

# Run a test after a normal compile. This magic is needed as 'make test' will
# not rebuild tests:
# http://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests
add_custom_target(_run_all_tests ALL
  COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  DEPENDS wl_tests
)

install (
  FILES ${CMAKE_CURRENT_BINARY_DIR}/VERSION
  DESTINATION ${WL_INSTALL_BASEDIR}
  CONFIGURATIONS Debug;Release
  COMPONENT CoreVersionFile
)

# Installation.
add_subdirectory(doc)
if(OPTION_BUILD_TRANSLATIONS)
  add_subdirectory(po)
endif(OPTION_BUILD_TRANSLATIONS)
add_subdirectory(src)

# install files to the correct locations here
install(
  DIRECTORY
    data/campaigns
    data/i18n
    data/images
    data/scripting
    data/shaders
    data/tribes
    data/txts
    data/world
  DESTINATION ${WL_INSTALL_DATADIR}
  CONFIGURATIONS Debug;Release
  COMPONENT CoreDataFiles
)

install(
  DIRECTORY
    data/maps
  DESTINATION ${WL_INSTALL_DATADIR}
  CONFIGURATIONS Debug;Release
  COMPONENT MapFiles
)

install(
  DIRECTORY
    data/music
    data/sound
  DESTINATION ${WL_INSTALL_DATADIR}
  CONFIGURATIONS Debug;Release
  COMPONENT MusicFiles
)

install(
  FILES
    COPYING
    CREDITS
    ChangeLog
  DESTINATION ${WL_INSTALL_BASEDIR}
  CONFIGURATIONS Debug;Release
  COMPONENT CoreLicenseFiles
)

install(
  DIRECTORY
    doc
  DESTINATION ${WL_INSTALL_BASEDIR}
  CONFIGURATIONS Debug
  COMPONENT DocFiles
  PATTERN "CMakeLists.txt" EXCLUDE
)

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${WL_INSTALL_DATADIR}/locale)

install(
  DIRECTORY
    ${CMAKE_CURRENT_BINARY_DIR}/locale/
  DESTINATION ${WL_INSTALL_DATADIR}/locale
  CONFIGURATIONS Debug;Release
  COMPONENT CoreLanguageFiles
)