File: CMakeLists.txt

package info (click to toggle)
caveexpress 2.4+git20160609-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 48,824 kB
  • sloc: cpp: 66,239; ansic: 1,135; sh: 471; xml: 186; python: 74; makefile: 20
file content (200 lines) | stat: -rw-r--r-- 6,683 bytes parent folder | download | duplicates (2)
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
cmake_minimum_required(VERSION 2.8.7)
project(caveproductions)
INCLUDE(FindPkgConfig)

PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(LUA5.2 REQUIRED lua5.2)
PKG_SEARCH_MODULE(Box2D REQUIRED box2d)

INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS})

#-------------------------------------------------------------------------------
# options
#-------------------------------------------------------------------------------

option(NETWORKING "Enable networking" ON)
option(UNITTESTS "Builds with unittests" ON)
option(TOOLS "Builds with tools" ON)
option(VERBOSE "Print debug information" OFF)
option(COVERAGE "Compile with test coverage" OFF)
option(USE_CCACHE "Use ccache" ON)
option(CAVEEXPRESS "Build caveexpress" ON)
option(CAVEPACKER "Build cavepacker" ON)
option(MINIRACER "Build miniracer" OFF)
option(SANITIZER "Build with sanitizer support if available" ON)

#-------------------------------------------------------------------------------
# end options
#-------------------------------------------------------------------------------

if (NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
	set(RELEASE False)
else()
	set(RELEASE True)
endif()

set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Root dir")
message(STATUS "Place binaries in ${ROOT_DIR}")
# First for the generic no-config case (e.g. with mingw)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)

# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
	string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
	set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${ROOT_DIR})
	set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
	set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
endforeach()
set(DEFAULT_LUAC_EXECUTABLE luac)
set(CP_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CP_CMAKE_DIR})
set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (${CMAKE_EXTRA_GENERATOR} MATCHES "Eclipse CDT4")
	message(STATUS "Generate eclipse projects")
	set(CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES OFF)
	set(CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT ON)
	set(CMAKE_ECLIPSE_VERSION "4.3" CACHE STRING "Eclipse version")
	set(CMAKE_CXX_COMPILER_ARG1 "-std=c++11" CACHE STRING "C++ version for Eclipse")
endif()

include(${CP_CMAKE_DIR}/macros.cmake)

if (COVERAGE)
	if ((CP_GCC OR CP_CLANG) AND NOT RELEASE)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
	elseif (RELEASE)
		message(WARNING "Skip coverage, you attempt to compile in release mode")
	else()
		message(WARNING "Skip coverage, you don't compile with gcc or clang")
	endif()
endif()

cp_message("ROOT_DIR: ${ROOT_DIR}")
cp_message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
cp_message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")

#-------------------------------------------------------------------------------
# variables
#-------------------------------------------------------------------------------

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
	set(WINDOWS 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
	set(LINUX 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
	set(DARWIN 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
	set(LINUX 1)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
	set(EMSCRIPTEN 1)
else()
	message(WARNING "Unknown host system: ${CMAKE_SYSTEM_NAME}. Default to linux")
	set(LINUX 1)
endif()

include(${CP_CMAKE_DIR}/pack.cmake)
include(CPack)

# on mac it e.g. finds the gui launcher - this is not what we want - find a proper way to handle this
if (NOT ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
	find_host_program(TEXTUREPACKER_BIN NAMES TexturePacker)
	if (${TEXTUREPACKER_BIN})
		message(STATUS "Found TexturePacker: ${TEXTUREPACKER_BIN}")
	else()
		message(STATUS "Could not find TexturePacker")
	endif()
endif()
if (NOT CMAKE_TOOLCHAIN_FILE)
	if (WINDOWS)
		include(${CP_CMAKE_DIR}/toolchains/windows-toolchain.cmake)
	elseif (DARWIN)
		include(${CP_CMAKE_DIR}/toolchains/darwin-toolchain.cmake)
	else()
		include(${CP_CMAKE_DIR}/toolchains/linux-toolchain.cmake)
	endif()
endif()

if (ANDROID)
	include(${CP_CMAKE_DIR}/android.cmake)
elseif (IOS)
	include(${CP_CMAKE_DIR}/ios.cmake)
elseif (DARWIN)
	include(${CP_CMAKE_DIR}/darwin.cmake)
elseif (WINDOWS)
#	include(${CP_CMAKE_DIR}/windows.cmake)
elseif (NACL)
	include(${CP_CMAKE_DIR}/nacl.cmake)
elseif (EMSCRIPTEN)
	include(${CP_CMAKE_DIR}/emscripten.cmake)
endif()

if (PKGDATADIR)
	add_definitions(-DPKGDATADIR="${PKGDATADIR}")
	message(STATUS "You specified a package data dir - but this means, you have to rebuild for each game.")
	message(STATUS "If you don't do this, you get all the data of all the games in the same directory.")
	message(STATUS "See the available options and disable all but one game for each build.")
endif()

if (NOT NETWORKING)
	add_definitions(-DNONETWORK=1)
endif()

if (NOT CMAKE_BUILD_TYPE)
	if (RELEASE)
		set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Compile Type" FORCE)
	else()
		set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
	endif()
	set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release)
endif()

find_host_program(CCACHE "ccache")
if (CCACHE)
	if (USE_CCACHE)
		message(STATUS "Using ccache")
		set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
		set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
	endif()
else()
	message(STATUS "ccache not found")
endif()

configure_file(${ROOT_DIR}/src/config.h.in ${CMAKE_BINARY_DIR}/cp-config.h)
include_directories(${CMAKE_BINARY_DIR})

include_directories(src)
include_directories(src/modules)

# TODO move into lib cmakefiles
if (LUA5.2_FOUND)
	add_definitions(-DHAVE_LUA_H)
endif()
if (UNITTESTS)
	enable_testing()
endif()
add_subdirectory(src/modules)
if (CAVEPACKER)
	add_subdirectory(src/cavepacker)
endif()
if (CAVEEXPRESS)
	add_subdirectory(src/caveexpress)
endif()
if (MINIRACER)
	add_subdirectory(src/miniracer)
endif()
if (UNITTESTS)
	add_subdirectory(src/tests)
endif()