forked from colobot/colobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
363 lines (286 loc) · 11.9 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
##
# Main CMake project file
# Contains global options and definitions
##
cmake_minimum_required(VERSION 2.8)
project(colobot C CXX)
##
# Project version
##
set(COLOBOT_VERSION_CODENAME "Gold")
set(COLOBOT_VERSION_MAJOR 0)
set(COLOBOT_VERSION_MINOR 1)
set(COLOBOT_VERSION_REVISION 2)
# Used on official releases
set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha")
# Used on unreleased, development builds
#set(COLOBOT_VERSION_UNRELEASED "+alpha")
# Append git characteristics to version
if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}")
endif()
set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}${COLOBOT_VERSION_RELEASE_CODENAME}")
message(STATUS "Building Colobot \"${COLOBOT_VERSION_CODENAME}\" (${COLOBOT_VERSION_FULL})")
##
# Platform detection and some related checks
##
if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
message(STATUS "Build for Windows system")
set(PLATFORM_WINDOWS 1)
set(PLATFORM_LINUX 0)
set(PLATFORM_MACOSX 0)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
set(SYSTEM_CPP_MODULE "system_windows.cpp")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
message(STATUS "Build for Linux system")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 1)
set(PLATFORM_MACOSX 0)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
set(SYSTEM_CPP_MODULE "system_linux.cpp")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
message(STATUS "Build for Mac OSX system")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_MACOSX 1)
set(PLATFORM_OTHER 0)
# Platform-dependent implementation of system.h
set(SYSTEM_CPP_MODULE "system_macosx.cpp")
set(USE_SDL_MAIN 1) # fixes SDL_main
else()
message(STATUS "Build for other system")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_MACOSX 0)
set(PLATFORM_OTHER 1)
# Platform-dependent implementation of system.h
set(SYSTEM_CPP_MODULE "system_other.cpp")
endif()
##
# Build options
##
# Build targets should be placed in the root build directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Include cmake directory with some additional scripts
set(CMAKE_MODULE_PATH "${colobot_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Compiler detection
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "Detected GCC version 4.7+")
set(CXX11_FLAGS "-std=gnu++11")
elseif (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6)
message(STATUS "Detected GCC version 4.6+")
set(CXX11_FLAGS "-std=c++0x -Doverride=")
else()
message(FATAL_ERROR "${PROJECT_NAME} requires GCC 4.6 or greater.")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
message(STATUS "Detected Clang compiler")
set(CXX11_FLAGS "-std=c++11")
else()
message(FATAL_ERROR "Your C++ compiler doesn't seem to support C++11.\n"
"Supported compilers at this time are GCC 4.6+ and clang.")
endif()
# Global compile flags
# These are specific to GCC/MinGW/clang; for other compilers, change as necessary
# The flags are used throughout src/ and test/ subdirs
# Special flags for boost
set(Boost_FLAGS "-DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS")
set(COLOBOT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast ${CXX11_FLAGS} ${Boost_FLAGS}")
set(COLOBOT_CXX_FLAGS_RELEASE "-O2")
set(COLOBOT_CXX_FLAGS_DEBUG "-g -O0")
# Asserts can be enabled/disabled regardless of build type
option(ASSERTS "Enable assert()s" ON)
# Development build can be enabled/disabled regardless of build type
option(DEV_BUILD "Enable development build (enables some debugging tools, local setting paths, etc.)" OFF)
# Building tests can be enabled/disabled
option(TESTS "Build tests" OFF)
# Building tool programs can be enabled/disabled
option(TOOLS "Build tool programs" OFF)
# CBot can also be a static library
option(CBOT_STATIC "Build CBot as static libary" OFF)
# Generate desktop files, manpage, etc.
option(DESKTOP "Generate desktop files, manpages, etc" ON)
# Doxygen docs are optional for installation
option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF)
# Build OpenAL sound support
option(OPENAL_SOUND "Build OpenAL sound support" ON)
# Change to false in case static boost libraries are not available
option(BOOST_STATIC "Link with static boost libraries" OFF)
# This is useful on Windows, if linking against standard GLEW dll fails
option(GLEW_STATIC "Link statically with GLEW" OFF)
# Sometimes helpful if there are different versions of gmock/gtest installed on system vs bundled
option(FORCE_BUNDLED_GTEST "Force the use of bundled gtest" OFF)
option(FORCE_BUNDLED_GMOCK "Force the use of bundled gmock" OFF)
# Default build type if not given is debug
if(NOT DEFINED CMAKE_BUILD_TYPE)
message(STATUS "Build type not specified - assuming debug")
set(CMAKE_BUILD_TYPE debug)
endif()
# Warn about development build
if(DEV_BUILD)
message("Building with development extensions")
endif()
##
# Searching for packages
##
find_package(OpenGL 1.4 REQUIRED)
find_package(SDL 1.2.10 REQUIRED)
find_package(SDL_image 1.2 REQUIRED)
find_package(SDL_ttf 2.0 REQUIRED)
find_package(PNG 1.2 REQUIRED)
find_package(Gettext REQUIRED)
set(Boost_USE_STATIC_LIBS ${BOOST_STATIC})
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_ADDITIONALVERSION "1.51" "1.51.0")
find_package(Boost COMPONENTS system filesystem regex REQUIRED)
find_package(GLEW REQUIRED)
if (OPENAL_SOUND)
find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})
find_package(LibSndFile REQUIRED)
endif()
if(NOT ASSERTS)
add_definitions(-DNDEBUG)
endif()
if(TESTS)
add_definitions(-DTESTS -DTEST_VIRTUAL=virtual)
else()
add_definitions(-DTEST_VIRTUAL=)
endif()
if(DEV_BUILD)
add_definitions(-DDEV_BUILD)
endif()
##
# Additional settings to use when cross-compiling with MXE (http://mxe.cc/)
##
include("${colobot_SOURCE_DIR}/cmake/mxe.cmake")
##
# Additional settings for MSYS
##
include("${colobot_SOURCE_DIR}/cmake/msys.cmake")
##
# Clipboard support needs X11 libraries
##
if(PLATFORM_LINUX OR PLATFORM_MACOSX)
find_package(X11 REQUIRED)
if(PLATFORM_MACOSX)
# Add the includes for X11
include_directories("/opt/X11/include")
endif()
endif()
##
# Clipboard support
##
set(CLIPBOARD_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/clipboard/include)
add_subdirectory(lib/clipboard)
##
# Localename
##
set(LOCALENAME_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/localename)
add_subdirectory(lib/localename)
##
# Doxygen docs
##
find_package(Doxygen)
if(DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
endif()
##
# Targets
##
if(TESTS)
# Google Test library
find_path(GTEST_SRC_DIR NAMES src/gtest.cc src/gtest-all.cc PATHS /usr/src PATH_SUFFIXES gtest)
find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS /usr/include)
if(NOT(FORCE_BUNDLED_GTEST) AND GTEST_SRC_DIR AND GTEST_INCLUDE_DIR)
message(STATUS "Using system gtest library in ${GTEST_SRC_DIR}")
else()
message(STATUS "Using bundled gtest library")
set(GTEST_SRC_DIR ${colobot_SOURCE_DIR}/lib/gtest)
set(GTEST_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gtest/include)
endif()
add_subdirectory(${GTEST_SRC_DIR} lib/gtest)
# Google Mock library
find_path(GMOCK_SRC_DIR NAMES src/gmock.cc src/gmock-all.cc PATHS /usr/src PATH_SUFFIXES gmock)
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h PATHS /usr/include)
if(NOT(FORCE_BUNDLED_GMOCK) AND GMOCK_SRC_DIR AND GMOCK_INCLUDE_DIR)
message(STATUS "Using system gmock library in ${GMOCK_SRC_DIR}")
include_directories(${GMOCK_SRC_DIR})
# gmock-all.cc includes all other sources
add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc)
else()
message(STATUS "Using bundled gmock library")
set(GMOCK_SRC_DIR ${colobot_SOURCE_DIR}/lib/gmock)
set(GMOCK_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gmock/include)
add_subdirectory(${GMOCK_SRC_DIR} lib/gmock)
endif()
# Tests targets
enable_testing()
add_subdirectory(test)
endif()
# Installation paths defined before compiling sources
if(PLATFORM_WINDOWS)
if(MXE)
# We need to use STRING because PATH doesn't accept relative paths
set(COLOBOT_INSTALL_BIN_DIR ./ CACHE STRING "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ./ CACHE STRING "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ./data CACHE STRING "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ./lang CACHE STRING "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ./doc CACHE STRING "Colobot documentation directory")
else()
set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/ CACHE PATH "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/data CACHE PATH "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/lang CACHE PATH "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/doc CACHE PATH "Colobot documentation directory")
endif()
elseif(PLATFORM_MACOSX)
set(COLOBOT_INSTALL_BIN_DIR ../MacOS CACHE STRING "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ../MacOS CACHE STRING "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR . CACHE STRING "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR i18n CACHE SRING "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR doc CACHE STRING "Colobot documentation directory")
else()
set(COLOBOT_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/games CACHE PATH "Colobot binary directory")
set(COLOBOT_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/colobot CACHE PATH "Colobot libraries directory")
set(COLOBOT_INSTALL_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/games/colobot CACHE PATH "Colobot shared data directory")
set(COLOBOT_INSTALL_I18N_DIR ${CMAKE_INSTALL_PREFIX}/share/locale CACHE PATH "Colobot translations directory")
set(COLOBOT_INSTALL_DOC_DIR ${CMAKE_INSTALL_PREFIX}/share/doc/colobot CACHE PATH "Colobot documentation directory")
endif()
# Subdirectory with sources
add_subdirectory(src)
add_subdirectory(po)
if(DESKTOP)
add_subdirectory(desktop)
endif()
##
# Installation
##
# Data: check if the submodule handles its own installation
if(EXISTS "${CMAKE_SOURCE_DIR}/data/CMakeLists.txt")
message(STATUS "Data directory will install itself.")
add_subdirectory(data)
else()
message(WARNING "Data directory is not available; make sure colobot-data is installed in ${COLOBOT_INSTALL_DATA_DIR}.")
endif()
# Documentation
if(INSTALL_DOCS AND DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/ DESTINATION ${COLOBOT_INSTALL_DOC_DIR} OPTIONAL)
endif()