summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 5873776327d4a179dc0661608835445e0cdc6900 (plain)
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
##
# Main CMake project file
# Contains global options and definitions
##

cmake_minimum_required(VERSION 2.8)

project(colobot C CXX)

# Include cmake directory with some additional scripts
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")


##
# Build options
##

# Global build type
set(CMAKE_BUILD_TYPE debug)

# Global compile flags
# These are specific to GCC/MinGW; for other compilers, change as necessary
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")

# Asserts can be enabled/disabled regardless of build type
option(ASSERTS "Enable assert()s" ON)

# Building tests can be enabled/disabled
option(TESTS "Enable tests" ON)

# CBot can also be a static library
option(CBOT_STATIC "Build CBot as static libary" OFF)


##
# Required 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(LTDL 2.4.2 REQUIRED)

set(Boost_USE_STATIC_LIBS        ON)
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)

# GLEW requirement depends on platform
# By default it is auto detected
# This setting may be used to override
# Possible values:
# - auto -> determine automatically
# - 1 -> always enable
# - 0 -> always disable
set(USE_GLEW auto)
# This is useful on Windows, if linking against standard GLEW dll fails
option(GLEW_STATIC "Link statically with GLEW" OFF)


##
# Additional settings to use when cross-compiling with MXE (http://mxe.cc/)
##

include("${colobot_SOURCE_DIR}/cmake/mxe.cmake")


##
# Platform detection and some related checks
##

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    message(STATUS "Windows system detected")
    set(PLATFORM_WINDOWS 1)
    set(PLATFORM_LINUX   0)
    set(PLATFORM_OTHER   0)

    # On Windows, GLEW is required
    if (${USE_GLEW} MATCHES "auto")
        set(USE_GLEW 1)
    endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    message(STATUS "Linux system detected")
    set(PLATFORM_WINDOWS 0)
    set(PLATFORM_LINUX   1)
    set(PLATFORM_OTHER   0)

    # On Linux, we should be fine without GLEW
    if (${USE_GLEW} MATCHES "auto")
        set(USE_GLEW 0)
    endif()
else()
    message(STATUS "Other system detected")
    set(PLATFORM_WINDOWS 0)
    set(PLATFORM_LINUX   0)
    set(PLATFORM_OTHER   1)

    # Use GLEW to be safe
    if (${USE_GLEW} MATCHES "auto")
        set(USE_GLEW 1)
    endif()
endif()


if(${USE_GLEW})
    find_package(GLEW REQUIRED)
endif()

if(NOT ${ASSERTS})
    add_definitions(-DNDEBUG)
endif()

if(${TESTS})
    add_definitions(-DTEST_VIRTUAL=virtual)
    enable_testing()
else()
    add_definitions(-DTEST_VIRTUAL)
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)
    if(GTEST_SRC_DIR)
        add_subdirectory(${GTEST_SRC_DIR} bin/test)
    else()
        add_subdirectory(lib/gtest bin/test)
    endif()
endif()

# Subdirectory with sources
add_subdirectory(src bin)

INSTALL_FILES(/share/games/colobot ../data)