-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
CMakeLists.txt
354 lines (296 loc) · 9.39 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
# Copyright 2014-2019 the openage authors. See copying.md for legal info.
# main C++ library definitions.
# dependency and source file setup for the resulting library.
declare_binary(libopenage openage library allow_no_undefined)
#################################################################
# source files and folders are added at the bottom of this file #
#################################################################
# set basic library settings
set_target_properties(libopenage PROPERTIES
VERSION 0
AUTOMOC ON
AUTOGEN_TARGET_DEPENDS "codegen"
)
##################################################
# library dependency specification
# freetype includedir hint for ubuntu...
find_path(FREETYPE_INCLUDE_DIRS freetype/freetype.h HINTS /usr/include/freetype2)
# provide apple qt location
if(APPLE)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_PREFIX}/opt/qt)
endif()
# windows does not have libm
if(NOT WIN32)
find_library(MATH_LIB m)
find_library(UTIL_LIB util)
endif()
if(WIN32)
find_library(OGG_LIB ogg)
target_link_libraries(libopenage PRIVATE DbgHelp)
endif()
if(NOT APPLE AND NOT WIN32)
find_library(RT_LIB rt)
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
find_library(EXECINFO_LIB execinfo)
endif()
endif()
find_library(FONTCONFIG_LIB fontconfig)
find_package(toml11 REQUIRED)
find_package(Freetype REQUIRED)
find_package(PNG REQUIRED)
find_package(Opusfile REQUIRED)
find_package(Epoxy REQUIRED)
find_package(HarfBuzz 1.0.0 REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
set(QT_VERSION_REQ "6.2")
find_package(Qt6 ${QT_VERSION_REQ} REQUIRED COMPONENTS Core Quick Multimedia)
if(WANT_BACKTRACE)
find_package(GCCBacktrace)
endif()
if(WANT_IWYU)
# include-what-you-use warnings during C++ compilation
find_program(IWYU_PATH NAMES include-what-you-use iwyu REQUIRED)
set_property(TARGET libopenage PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${IWYU_PATH}")
endif()
##################################################
# nyan integration
# first, try to locate nyan directly
# this discovers the system package or the user-registry package
find_package(nyan CONFIG)
# if this didn't work, we can download nyan like a git submodule.
# this is the treeish to be checked out.
if(NOT DEFINED NYAN_CLONE_VERSION)
set(NYAN_CLONE_VERSION origin/master)
endif()
option(
DOWNLOAD_NYAN
"whether to clone the nyan project in case it is not found"
OFF
)
option(
FORCE_DOWNLOAD_NYAN
"Force the download and usage of the nyan project"
OFF
)
option(
DISABLE_SUBPROJECT_UPDATES
"Disable the automatic update of subprojects over the internet"
OFF
)
# if nyan was not found, consider downloading it as subproject
# only use the subproject mode if it was requested
# or if it was used before.
if((NOT nyan_FOUND AND DOWNLOAD_NYAN) OR FORCE_DOWNLOAD_NYAN)
message(STATUS "Downloading nyan as submodule project...")
if(DISABLE_SUBPROJECT_UPDATES)
set(DISABLE_NYAN_UPDATES "DISABLE_UPDATES")
endif()
fetch_project(
NAME nyan
${DISABLE_NYAN_UPDATES}
GIT_REPOSITORY https://github.com/SFTtech/nyan
GIT_TAG ${NYAN_CLONE_VERSION}
)
# don't register nyan to the userpackage-repo!
set(REGISTER_USERPACKAGE OFF)
# don't generate the `doc` target again (name conflict!)
set(DOXYGEN_ENABLE OFF)
# register the targets
add_subdirectory(${nyan_SOURCE_DIR} ${nyan_BINARY_DIR})
message(STATUS "nyan processed successfully!")
elseif(NOT nyan_FOUND)
message(FATAL_ERROR "
Could not find the cmake package configuration file \"nyanConfig.cmake\".
To find it, you have several options:
* If your distribution provides it, install \"nyan\" through the package manager.
* If you want openage to automatically download \"nyan\", append `-DDOWNLOAD_NYAN=YES` to the cmake invocation or use `./configure --download-nyan`.
* If you want to build nyan manually, follow the build instructions:
[[ doc/building.md#nyan-installation ]]
* If you already built nyan but it still can't be found (cmake package repo fails):
* Try to set \"nyan_DIR\" to the nyan build directory (it contains nyanConfig.cmake)
either through: \"./configure $youroptions -- -Dnyan_DIR=/home/dev/nyan/build\"
or: \"cmake $yourotheroptions -Dnyan_DIR=/home/dev/nyan/build ..\"
In case of other problems, please try to figure them out (and tell us what you did).
Contact information is in README.md.
")
endif()
##################################################
# optional dependencies
# advanced stacktraces with libbacktrace from gcc
if(GCCBacktrace_FOUND)
target_include_directories(libopenage PRIVATE ${GCCBacktrace_INCLUDE_DIRS})
target_link_libraries(libopenage PRIVATE "${GCCBacktrace_LIBRARIES}")
have_config_option(backtrace BACKTRACE true)
else()
have_config_option(backtrace BACKTRACE false)
endif()
# google performance tools
if(WANT_GPERFTOOLS_PROFILER OR WANT_GPERFTOOLS_TCMALLOC)
find_package(GPerfTools)
endif()
if(WANT_GPERFTOOLS_PROFILER AND GPERFTOOLS_FOUND)
have_config_option(gperftools-profiler GPERFTOOLS_PROFILER true)
target_include_directories(libopenage PRIVATE ${GPERFTOOLS_INCLUDE_DIR})
target_link_libraries(libopenage PRIVATE ${GPERFTOOLS_PROFILER})
else()
have_config_option(gperftools-profiler GPERFTOOLS_PROFILER false)
endif()
if(WITH_GPERFTOOLS_TCMALLOC AND GPERFTOOLS_FOUND)
have_config_option(gperftools-tcmalloc GPERFTOOLS_TCMALLOC true)
target_include_directories(libopenage PRIVATE ${GPERFTOOLS_INCLUDE_DIR})
target_link_libraries(libopenage PRIVATE ${GPERFTOOLS_TCMALLOC})
else()
have_config_option(gperftools-tcmalloc GPERFTOOLS_TCMALLOC false)
endif()
# inotify support
if(WANT_INOTIFY)
find_package(Inotify)
endif()
if(WANT_INOTIFY AND INOTIFY_FOUND)
have_config_option(inotify INOTIFY true)
target_include_directories(libopenage PRIVATE ${INOTIFY_INCLUDE_DIRS})
else()
have_config_option(inotify INOTIFY false)
endif()
# ncurses support
if(WANT_NCURSES)
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses)
endif()
if(WANT_NCURSES AND CURSES_FOUND)
have_config_option(ncurses NCURSES true)
target_include_directories(libopenage PRIVATE ${CURSES_INCLUDE_DIRS})
target_link_libraries(libopenage PRIVATE ${CURSES_LIBRARIES})
else()
have_config_option(ncurses NCURSES false)
endif()
# opengl support
if(WANT_OPENGL)
find_package(OpenGL)
endif()
# vulkan support
if(WANT_VULKAN)
find_package(Vulkan)
endif()
if(WANT_OPENGL AND OPENGL_FOUND)
have_config_option(opengl OPENGL true)
target_link_libraries(libopenage PRIVATE OpenGL::GL)
else()
have_config_option(opengl OPENGL false)
endif()
if(WANT_VULKAN AND VULKAN_FOUND)
have_config_option(vulkan VULKAN true)
target_link_libraries(libopenage PRIVATE Vulkan::Vulkan)
else()
have_config_option(vulkan VULKAN false)
endif()
if(NOT (OPENGL_FOUND OR VULKAN_FOUND))
message(FATAL_ERROR "One of OpenGL or Vulkan is required!")
endif()
##################################################
# build configuration generation
get_config_option_string()
configure_file(config.h.in config.h)
configure_file(config.cpp.in config.cpp)
configure_file(version.h.in version.h)
configure_file(version.cpp.in version.cpp)
configure_file(
"${CMAKE_SOURCE_DIR}/openage/config.py.in"
"${CMAKE_BINARY_DIR}/openage/config.py"
)
##################################################
# directories for header inclusion
target_include_directories(libopenage
PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${FREETYPE_INCLUDE_DIRS}
${EPOXY_INCLUDE_DIRS}
${OPUS_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${HarfBuzz_INCLUDE_DIRS}
${QTPLATFORM_INCLUDE_DIRS}
)
##################################################
# dependency linking
# all the libraries are not exposed
# to the public api of libopenage
target_link_libraries(libopenage
PRIVATE
Threads::Threads
nyan::nyan
Eigen3::Eigen
${PNG_LIBRARIES}
${OPUS_LIBRARIES}
${OGG_LIB}
${CMAKE_DL_LIBS}
${FONTCONFIG_LIB}
${FREETYPE_LIBRARIES}
${EPOXY_LIBRARIES}
${MATH_LIB}
${UTIL_LIB}
${HarfBuzz_LIBRARIES}
${RT_LIB}
${EXECINFO_LIB}
Qt6::Core
Qt6::Quick
Qt6::Multimedia
)
##################################################
# installation of the library
install(TARGETS libopenage
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(WIN32)
install(FILES $<TARGET_FILE:nyan::nyan>
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
##################################################
# source file definitions
get_codegen_scu_file()
# add new sources here, dependencies for linking and including
# are specified above the source file list.
add_sources(libopenage
main.cpp
options.cpp
${CMAKE_CURRENT_BINARY_DIR}/config.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${CODEGEN_SCU_FILE}
)
pxdgen(
main.h
)
# add subsystem folders
add_subdirectory("assets")
add_subdirectory("audio")
add_subdirectory("console")
add_subdirectory("coord")
add_subdirectory("curve")
add_subdirectory("cvar")
add_subdirectory("datastructure")
add_subdirectory("engine")
add_subdirectory("error")
add_subdirectory("event")
add_subdirectory("gamestate")
add_subdirectory("input")
add_subdirectory("job")
add_subdirectory("log")
add_subdirectory("main")
add_subdirectory("pathfinding")
add_subdirectory("presenter")
add_subdirectory("pyinterface")
add_subdirectory("renderer")
add_subdirectory("rng")
add_subdirectory("testing")
add_subdirectory("time")
add_subdirectory("util")
add_subdirectory("versions")