forked from spring/spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
606 lines (492 loc) · 21.8 KB
/
CMakeLists.txt
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# CMake 2.8.10
# + adds support for CMAKE_CXX_COMPILER_ID (which is ignored with older cmake)
cmake_minimum_required(VERSION 2.8.11)
SET(CMAKE_MODULES_SPRING "${CMAKE_CURRENT_SOURCE_DIR}/rts/build/cmake")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_MODULES_SPRING}")
# enable flag overrides for compilers
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_MODULES_SPRING}/OverrideFlags.cmake")
project(Spring)
# dummy so that qtcreator shows all files (even those of windows)
if(CMAKE_VERSION VERSION_GREATER 3.1.2)
add_library(platform_sources EXCLUDE_FROM_ALL "")
endif()
# includes rts/build/cmake/Util.cmake & rts/build/cmake/PreferStaticLibs.cmake
INCLUDE(Util)
INCLUDE(PreferStaticLibs)
CheckMinCMakeVersion(CUSTOM_TARGET_SOURCES_SUPPORT 2 6 3)
# check for minimal gcc version
set(MIN_GCC_VER "4.8")
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${MIN_GCC_VER}")
message(FATAL_ERROR "gcc >=${MIN_GCC_VER} required")
else()
message(STATUS "gcc ${CMAKE_CXX_COMPILER_VERSION} detected")
endif()
endif()
# set some internal vars
if(NOT "${CMAKE_C_FLAGS}" STREQUAL "")
Message(WARNING "Using custom C_FLAGS: ${CMAKE_C_FLAGS} this build will very likely not sync in online mode!")
endif()
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
Message(WARNING "Using custom CXX_FLAGS: ${CMAKE_CXX_FLAGS} this build will very likely not sync in online mode!")
endif()
set (CUSTOM_COMPILER_DEFINITIONS "" CACHE STRING "Custom flags can be defined here")
if (CUSTOM_COMPILER_DEFINITIONS)
add_definitions(${CUSTOM_COMPILER_DEFINITIONS})
endif (CUSTOM_COMPILER_DEFINITIONS)
### set the default build type
if (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RELWITHDEBINFO CACHE STRING
"Choose the type of build, options are: RELWITHDEBINFO DEBUG RELEASE PROFILE"
FORCE)
endif (NOT CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
if(${CMAKE_BUILD_TYPE_UPPER} MATCHES "^DEBUG")
set(DEBUG_BUILD TRUE)
else()
set(DEBUG_BUILD FALSE)
endif()
if(DEBUG_BUILD)
set(JAVA_COMPILE_FLAG_CONDITIONAL "-g:lines,source,vars")
else()
set(JAVA_COMPILE_FLAG_CONDITIONAL "-g:lines,source")
endif()
# Tell windows to pass arguments around in @response files
# (32k arg limit workaround)
if (WIN32)
SET(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
endif (WIN32)
# XCode
if (APPLE)
option(MACOSX_BUNDLE "Compile spring to work as a Bundle.app" TRUE)
add_definitions(${PIC_FLAG})
if (MACOSX_BUNDLE)
add_definitions(-DMACOSX_BUNDLE)
endif (MACOSX_BUNDLE)
else (APPLE)
set(MACOSX_BUNDLE FALSE)
endif (APPLE)
### Compiler flags and defines based on build type
INCLUDE(TestCXXFlags)
## 32bit or 64bit?
set(MARCH_FLAG ${MARCH} CACHE STRING "CPU optimization (use i686 for generic optimization)")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MARCH_BITS 64 CACHE INTERNAL "" FORCE)
else (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(MARCH_BITS 32 CACHE INTERNAL "" FORCE)
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)
Message(STATUS "Building Spring on ${MARCH_BITS}bit environment")
set(BUILD_BITS "${MARCH_BITS}" CACHE STRING "Target arch machine type")
Message(STATUS "Targetting ${BUILD_BITS}bit")
### Install paths (relative to CMAKE_INSTALL_PREFIX)
if (UNIX AND NOT MINGW)
set(BINDIR "bin" CACHE STRING "Where to install binaries")
set(LIBDIR "lib" CACHE STRING "Where to install libraries")
set(MANDIR "share/man" CACHE STRING "Where to install man pages")
set(DOCDIR "share/doc/spring-VERSION" CACHE STRING "Where to install basic project documentation (README, LICENSE, etc.)") # TODO set correct version here, and re-enable userdocs in doc/CMakeLists.txt
set(DATADIR "share/games/spring" CACHE STRING "Where to install game content")
set(APPLICATIONS_DIR "share/applications" CACHE STRING "Where to install desktop files")
set(PIXMAPS_DIR "share/pixmaps" CACHE STRING "Where to install icons")
set(MIME_DIR "share/mime" CACHE STRING "Where MIME definitions are located")
else (UNIX AND NOT MINGW)
set(BINDIR "." CACHE STRING "Where to install binaries")
set(LIBDIR "." CACHE STRING "Where to install libraries")
set(DOCDIR "doc" CACHE STRING "Where to install basic project documentation (README, LICENSE, etc.)")
set(DATADIR "." CACHE STRING "Where to install game content")
if (NOT MINGWLIBS)
if(MSVC)
set(MINGWLIBS ${CMAKE_SOURCE_DIR}/vclibs CACHE PATH "Location of the vclibs package")
else(MSVC)
if(BUILD_BITS EQUAL 32)
set(MINGWLIBS ${CMAKE_SOURCE_DIR}/mingwlibs CACHE PATH "Location of the mingwlibs package")
else(BUILD_BITS EQUAL 32)
set(MINGWLIBS ${CMAKE_SOURCE_DIR}/mingwlibs64 CACHE PATH "Location of the mingwlibs package")
endif(BUILD_BITS EQUAL 32)
endif(MSVC)
endif ()
if (EXISTS "${MINGWLIBS}" AND IS_DIRECTORY "${MINGWLIBS}")
# MinGW needs an additional library, mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
# (Actually on second look, I think it only needs one of the m* libraries.)
if(NOT MSVC)
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
endif(NOT MSVC)
set(SDL2_INCLUDE_DIR "${MINGWLIBS}/include/SDL2")
set(CMAKE_PREFIX_PATH ${MINGWLIBS})
include_directories(${MINGWLIBS}/include)
set(CMAKE_LIBRARY_PATH ${MINGWLIBS}/dll ${MINGWLIBS}/lib)
# some cross-compile fixes
set(CMAKE_FIND_ROOT_PATH ${MINGWLIBS} ${CMAKE_FIND_ROOT_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
else()
MESSAGE(WARNING "Compiling for windows. MINGWLIBS '${MINGWLIBS}' is not a valid directory, trying system libs")
endif ()
add_definitions(-D_WIN32_WINNT=0x502) ## vista is minimum due to InterlockedIncrement64
add_definitions(-D__USE_MINGW_ANSI_STDIO=1) ## use __mingw_sprintf instead of __builtin_sprintf (it's used by lua in a synced way, and builtin doesn't sync)
if(MSVC)
add_definitions(-DBOOST_ALL_NO_LIB -DNOMINMAX -DWIN32_LEAN_AND_MEAN)
set(Boost_USE_STATIC_LIBS ON)
set(GLEW_STATIC ON)
set(EXE_FLAGS WIN32)
else()
INCLUDE_DIRECTORIES(rts/lib/mingw-std-threads)
endif()
endif (UNIX AND NOT MINGW)
## Artificial Intelligence
# In theory, it should be possible to set this to LIBDIR instead
# (next two are relative to CMAKE_INSTALL_PREFIX)
set(AI_LIBS_DIR "${DATADIR}" CACHE STRING "Where to install Skirmish AI libraries")
set(AI_DATA_DIR "${AI_LIBS_DIR}" CACHE STRING "Where to install Skirmish AI additional files (eg. configuration)")
set(AI_TYPES "ALL" CACHE STRING "Which AI Interfaces (and Skirmish AIs using them) to build [ALL|NATIVE|JAVA|NONE]")
## DataDirs
set(BUILTIN_DATADIRS "")
if (NOT WIN32 AND NOT MACOSX_BUNDLE)
set(SPRING_DATADIR CACHE STRING "Path to game content (in addition to /etc/spring/datadir)")
set(SPRING_DATADIR_INTERNAL "")
if (SPRING_DATADIR)
set(SPRING_DATADIR_INTERNAL "${SPRING_DATADIR}${PATH_DELIM_T}")
endif (SPRING_DATADIR)
if (CMAKE_INSTALL_PREFIX)
set(SPRING_DATADIR_INTERNAL "${SPRING_DATADIR_INTERNAL}${CMAKE_INSTALL_PREFIX}${PATH_SEP_T}${DATADIR}")
endif (CMAKE_INSTALL_PREFIX)
set(BUILTIN_DATADIRS "${SPRING_DATADIR_INTERNAL}")
endif (NOT WIN32 AND NOT MACOSX_BUNDLE)
if (NOT "${AI_LIBS_DIR}" STREQUAL "${DATADIR}")
# If the AI library dir is not the same as the normal data dir,
# add it to the internal list of data dirs
set(BUILTIN_DATADIRS "${BUILTIN_DATADIRS}${PATH_DELIM_T}${CMAKE_INSTALL_PREFIX}${PATH_SEP_T}${AI_LIBS_DIR}")
endif (NOT "${AI_LIBS_DIR}" STREQUAL "${DATADIR}")
if (NOT "${AI_DATA_DIR}" STREQUAL "${DATADIR}" AND NOT "${AI_DATA_DIR}" STREQUAL "${AI_LIBS_DIR}")
# If the AI data dir is not the same as the normal data dir
# nor the AI library dir, add it to the internal list of data dirs
set(BUILTIN_DATADIRS "${BUILTIN_DATADIRS}${PATH_DELIM_T}${CMAKE_INSTALL_PREFIX}${PATH_SEP_T}${AI_DATA_DIR}")
endif (NOT "${AI_DATA_DIR}" STREQUAL "${DATADIR}" AND NOT "${AI_DATA_DIR}" STREQUAL "${AI_LIBS_DIR}")
add_definitions(-DSPRING_DATADIR="${BUILTIN_DATADIRS}")
# Spring Related USE-Flags
set(LOG_LEVEL "DEFAULT" CACHE STRING
"The minimum log level.
Log messages below this level
will not be compiled into the binary.
Available levels:
* DEFAULT (DEBUG on debug builds, INFO on release builds)
* DEBUG (log everything)
* INFO
* WARNING (only use this if you know what you are doing!)")
if (NOT "${LOG_LEVEL}" STREQUAL "DEFAULT")
add_definitions(-D_LOG_LEVEL_MIN=LOG_LEVEL_${LOG_LEVEL})
endif (NOT "${LOG_LEVEL}" STREQUAL "DEFAULT")
option(SYNCCHECK "Check sync during gameplay (Required for online play!)" TRUE)
if (SYNCCHECK)
add_definitions(-DSYNCCHECK)
endif (SYNCCHECK)
option(NO_CREG "Disable creg support" FALSE)
if (NO_CREG)
add_definitions(-DNOT_USING_CREG)
endif (NO_CREG)
option(NO_SOUND "No sound output support" FALSE)
if (WIN32)
## internal AVI recorder (w/o sound atm)
option(NO_AVI "Disable in-game video recording" FALSE)
if (NOT NO_AVI)
add_definitions(-DAVI_CAPTURING)
endif (NOT NO_AVI)
if (NOT MSVC)
## stdout console
option(WINDOWS_CONSOLE "Show a visible cmd.exe with stdout when spring runs" FALSE)
if (NOT WINDOWS_CONSOLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
endif (NOT WINDOWS_CONSOLE)
endif(NOT MSVC)
endif (WIN32)
option(USE_LIBSQUISH "Enable libsquish for DXT decompressing. (needed for ETC1 support)" TRUE)
if (USE_LIBSQUISH)
add_definitions(-DUSE_LIBSQUISH)
endif (USE_LIBSQUISH)
FIND_PACKAGE(Boost 1.51.0 COMPONENTS thread chrono regex system REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
# boost::chrono depends on clock_gettime which we need to link ourself when boost is static linked
Set(Boost_CHRONO_LIBRARY_WITH_RT ${Boost_CHRONO_LIBRARY})
IF (UNIX AND NOT MINGW)
FIND_LIBRARY(REALTIME_LIBRARY rt)
IF (PREFER_STATIC_LIBS AND NOT EXISTS "${REALTIME_LIBRARY}")
MESSAGE(FATAL_ERROR "librt.[so|a] not found! Needed by std/boost chrono when static linked!")
ENDIF (PREFER_STATIC_LIBS AND NOT EXISTS "${REALTIME_LIBRARY}")
# zydox buildslave seems to have problems to autolink it from dynlinked boost libs
# so always link it (won't hurt cause std/boost chrono need it never the less)
if (EXISTS "${REALTIME_LIBRARY}")
LIST(APPEND Boost_CHRONO_LIBRARY_WITH_RT ${REALTIME_LIBRARY})
ENDIF (EXISTS "${REALTIME_LIBRARY}")
ENDIF (UNIX AND NOT MINGW)
# Note the missing REQUIRED, as headless & dedi may not depend on those.
# So req. checks are done in the build target's CMakeLists.txt.
FIND_PACKAGE(SDL2)
FIND_PACKAGE_STATIC(DevIL)
IF (PREFER_STATIC_LIBS)
# dependencies of DevIL
FIND_PACKAGE_STATIC(JPEG REQUIRED)
FIND_PACKAGE_STATIC(PNG REQUIRED)
FIND_PACKAGE_STATIC(TIFF REQUIRED)
FIND_PACKAGE_STATIC(GIF REQUIRED)
ENDIF (PREFER_STATIC_LIBS)
if (WIN32)
FIND_PACKAGE(Windres)
SET(CMAKE_RC_COMPILER ${WINDRES_BIN})
FIND_PACKAGE(Win32Libs REQUIRED)
endif (WIN32)
if (WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
elseif (UNIX)
# unix specifics
else (UNIX)
# mac
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
INCLUDE_DIRECTORIES("${COREFOUNDATION_LIBRARY}/Headers")
endif (WIN32)
FIND_PACKAGE(Valgrind)
if (VALGRIND_FOUND)
add_definitions(-DUSE_VALGRIND)
endif (VALGRIND_FOUND)
INCLUDE (CheckSymbolExists)
CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
if (NOT HAVE_STRNLEN)
Message(FATAL_ERROR "this compiler/environment isn't supported, the function strnlen is missing!")
endif()
### Add Link-Time-Optimization flags, if supported (GCC >= 4.5) and enabled
option(LTO "Link Time Optimizations (LTO)" FALSE)
if (LTO)
if (NOT LTO_FLAGS)
Message(WARNING "Tried to enable LTO, but compiler doesn't support it!")
endif (NOT LTO_FLAGS)
Set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LTO_FLAGS}")
Set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LTO_FLAGS}")
Set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LTO_FLAGS}")
endif (LTO)
### Memory Access Protection (BoundsChecking)
option(DEBUG_BOUNDSCHECK "Array/Pointer BoundsChecking a.k.a. buffer overflow protection (debug)" FALSE)
if (DEBUG_BOUNDSCHECK)
if (NOT MPX_FLAGS)
Message(WARNING "Tried to enable BoundsCheck, but compiler doesn't support it!")
endif (NOT MPX_FLAGS)
Set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPX_FLAGS}")
Set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPX_FLAGS}")
Set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${MPX_FLAGS}")
endif (DEBUG_BOUNDSCHECK)
### ld.gold
option(COMPRESS_DEBUG_SYMBOLS "Compresses the DebugSymbols (needs ld.gold, beware: slow)" FALSE)
if (LDGOLD_FOUND)
Message(STATUS "Found ld.gold")
if (COMPRESS_DEBUG_SYMBOLS)
Message(STATUS "Compressing debug symbols")
set(LDGOLD_LINKER_FLAGS " -Wl,--compress-debug-sections=zlib ${LDGOLD_LINKER_FLAGS}")
endif (COMPRESS_DEBUG_SYMBOLS)
set(CMAKE_LINKER LD_GOLD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LDGOLD_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDGOLD_LINKER_FLAGS}")
else (LDGOLD_FOUND)
Message(WARNING "You are using ld.bfd, it's much slower than ld.gold.")
endif (LDGOLD_FOUND)
### C++11
Message(STATUS "Compiling with C++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS}")
add_definitions(-D_GLIBCXX_USE_NANOSLEEP) # issue in std::chrono with gentoo and few other distros
add_definitions(-D_RANDOM_TCC) # don't include <bits/random.tcc>, it fails to compile with single precision constants
### our custom OpenMP replacement
option(THREADPOOL "Enable ThreadPools" TRUE)
if (THREADPOOL)
add_definitions(-DTHREADPOOL)
endif(THREADPOOL)
### warnings
if(NOT MSVC)
### SigNan
option(DEBUG_SIGNAL_NANS "Enable NaN-Signaling" ${DEBUG_BUILD})
if (DEBUG_SIGNAL_NANS AND CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsignaling-nans")
endif()
### CompileTime Warnings
set(COMMON_WARNINGS "${COMMON_WARNINGS} -Wformat -Wformat-security")
option(DEBUG_MAX_WARNINGS "Enable verbose compile" ${DEBUG_BUILD})
if (DEBUG_MAX_WARNINGS)
# This would produce the maximum on warnings
set(DEBUG_WARNINGS "-Wall -Wconversion ${COMMON_WARNINGS}")
else (DEBUG_MAX_WARNINGS)
# This should produce a sane amount of warnings
set(DEBUG_WARNINGS "-Wall -Wno-sign-compare ${COMMON_WARNINGS}")
endif (DEBUG_MAX_WARNINGS)
endif(NOT MSVC)
if(DEBUG_BUILD)
set(DEBUG_LUANAN_DEFAULT TRUE)
else()
set(DEBUG_LUANAN_DEFAULT FALSE)
endif()
option(DEBUG_LUANAN "check for nans in lua" ${DEBUG_LUANAN_DEFAULT})
if(DEBUG_LUANAN)
add_definitions(-DDEBUG_LUANAN)
endif()
### streflop
option(ENABLE_STREFLOP "build Spring with streflop support (REQUIRED FOR MULTIPLAYER)" TRUE)
if (ENABLE_STREFLOP)
## note: is removed in ./AI/CMakeLists.txt since it would break AI compilation
add_definitions(-DSTREFLOP_SSE)
else ()
add_definitions(-DNOT_USING_STREFLOP)
endif ()
### Asio
add_definitions(-DASIO_STANDALONE)
### compiler specific flags
set(CXX_FLAGS_DEBUG_ADDITIONAL "")
if ($ENV{CXX} MATCHES "icpc")
# intel C/C++ compiler fix; it does not support these flags:
# "-march -mfpmath -msse -ggdb"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -axK") # SSE1
set(CXX_FLAGS_DEBUG_ADDITIONAL "-g -debug full")
elseif (CMAKE_COMPILER_IS_GNUCXX)
if (UNIX)
CHECK_AND_ADD_FLAGS(CMAKE_CXX_FLAGS "-fdiagnostics-color=auto")
endif (UNIX)
if (MARCH_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${MARCH_FLAG}")
Message(STATUS "using march=${MARCH_FLAG}")
else (MARCH_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=generic")
Message(STATUS "using mtune=generic")
endif (MARCH_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}") # SSE1
elseif (MSVC)
# silence warnings
add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS)
else (MSVC)
Message(WARNING "unknown compiler")
endif ($ENV{CXX} MATCHES "icpc")
set(CXX_DEBUG_DEFINES "-DDEBUG -D_DEBUG -DNO_CATCH_EXCEPTIONS")
set(CXX_RELWITHDEBINFO_DEFINES "-DNDEBUG")
set(CXX_RELEASE_DEFINES "-DNDEBUG")
set(CXX_PROFILE_DEFINES "-DNDEBUG -DPROFILE")
#### build types
if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(MSVC_CXX_FLAGS "/wd4146 /wd4711")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP ${MSVC_CXX_FLAGS} ${CXX_DEBUG_DEFINES}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /Ob2 /GL /MP ${MSVC_CXX_FLAGS} ${CXX_RELWITHDEBINFO_DEFINES}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2 /GL /MP ${MSVC_CXX_FLAGS} ${CXX_RELEASE_DEFINES}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} /O2 /Ob2 /GL /MP ${MSVC_CXX_FLAGS} ${CXX_PROFILE_DEFINES}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE} /LTCG")
else (MSVC)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsingle-precision-constant -frounding-math")
endif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IEEE_FP_FLAG} -pipe -fno-strict-aliasing ${VISIBILITY_HIDDEN} ${VISIBILITY_INLINES_HIDDEN}")
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif (UNIX)
if (MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads")
endif (MINGW)
add_definitions(-DBOOST_NO_FENV_H) # streflop overrides fenv.h
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_FLAGS_DEBUG_ADDITIONAL} -O0 ${DEBUG_WARNINGS} ${CXX_DEBUG_DEFINES}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CXX_FLAGS_DEBUG_ADDITIONAL} -O2 ${COMMON_WARNINGS} ${CXX_RELWITHDEBINFO_DEFINES}")
set(CMAKE_CXX_FLAGS_RELEASE " -O2 ${COMMON_WARNINGS} ${CXX_RELEASE_DEFINES}")
set(CMAKE_CXX_FLAGS_PROFILE " -O2 -pg ${DEBUG_WARNINGS} ${CXX_PROFILE_DEFINES}")
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "-pg")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "-pg")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g")
if (MARCH_BITS EQUAL 64 AND BUILD_BITS EQUAL 32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif (MARCH_BITS EQUAL 64 AND BUILD_BITS EQUAL 32)
if (MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++ -Wl,--enable-auto-import")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++ -Wl,--enable-auto-import")
if (BUILD_BITS EQUAL 32)
# Increase memory limit from 2GB to 3GB on 32bit Windows and 2GB->4GB on 64bit Windows (assuming spring.exe is 32bit)
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx
Message(STATUS "Enable IMAGE_FILE_LARGE_ADDRESS_AWARE (>2GB memory limit)")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--large-address-aware")
else (BUILD_BITS EQUAL 32)
Message(WARNING "The 64bit version of spring on windows is experimental and may not sync with regular builds")
endif (BUILD_BITS EQUAL 32)
endif (MINGW)
endif (MSVC)
#######################################
# Source Files
#
# Sub-parts of the build system may add dependencies to this target
add_custom_target(generateSources)
# Make sure git is found if git is used
If (EXISTS "${CMAKE_SOURCE_DIR}/.git")
find_package(Git REQUIRED)
Endif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Generate the version files
Set(VERSION_GENERATE_DIR "${CMAKE_BINARY_DIR}")
Set(VERSION_GENERATE_SOURCES
"${VERSION_GENERATE_DIR}/src-generated/engine/System/VersionGenerated.h"
"${VERSION_GENERATE_DIR}/VERSION"
)
Set_Source_Files_Properties(
${VERSION_GENERATE_SOURCES}
PROPERTIES GENERATED TRUE
)
# This is always executed (on every run of "make"),
# but the actual version files are only written in case of a change
# in the version info they use, or in the template file content.
IF (MSVC)
Add_Custom_Command(
OUTPUT ${VERSION_GENERATE_SOURCES}
COMMAND "${CMAKE_COMMAND}"
"-DSOURCE_ROOT=${CMAKE_SOURCE_DIR}"
"-DCMAKE_MODULES_SPRING=${CMAKE_MODULES_SPRING}"
"-DGENERATE_DIR=${VERSION_GENERATE_DIR}"
"-DVERSION_ADDITIONAL=${VERSION_ADDITIONAL}"
-P "${CMAKE_MODULES_SPRING}/ConfigureVersion.cmake"
"${VERSION_GENERATE_DIR}"
COMMENT
" Configuring Version files ..." VERBATIM
)
Add_Custom_Target(generateVersionFiles DEPENDS ${VERSION_GENERATE_SOURCES})
ELSE (MSVC)
# This is always executed (on every run of "make"),
# but the actual version files are only written in case of a change
# in the version info they use, or in the template file content.
Add_Custom_Target(generateVersionFiles)
Add_Custom_Command(TARGET generateVersionFiles
COMMAND "${CMAKE_COMMAND}"
"-DSOURCE_ROOT=${CMAKE_SOURCE_DIR}"
"-DCMAKE_MODULES_SPRING=${CMAKE_MODULES_SPRING}"
"-DGENERATE_DIR=${VERSION_GENERATE_DIR}"
"-DVERSION_ADDITIONAL=${VERSION_ADDITIONAL}"
-P "${CMAKE_MODULES_SPRING}/ConfigureVersion.cmake"
"${VERSION_GENERATE_DIR}"
COMMENT
" Configuring Version files ..." VERBATIM
)
ENDIF (MSVC)
Add_Dependencies(generateSources generateVersionFiles)
### Where the other CMakeLists.txt are
# As the libs are required by all the other sub-projects, we add them first
Add_Subdirectory(rts/lib)
if (NOT "${AI_TYPES}" STREQUAL "NONE")
Add_Subdirectory(AI)
endif (NOT "${AI_TYPES}" STREQUAL "NONE")
# As tools/unitsync/ depends on sources from here, we add this one first
Add_Subdirectory(rts/System)
# additional tools
Add_Subdirectory(tools)
# man pages & user-docs
Add_Subdirectory(doc)
### Handle game content
### - Pack base-files
### - Install base-files
### - Install freedesktop stuff
### - Install mingw DLLs
Add_Subdirectory(cont)
# As rts/builds/* depends on most other stuff, we add this one as last
Add_Subdirectory(rts)
# Unit tests
# this has to be in root CMakeLists.txt; it requires CMake 2.6.3 or later
ENABLE_TESTING()
Add_Subdirectory(test)