forked from CytopiaTeam/Cytopia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
433 lines (351 loc) · 13.7 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
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
include(CMakeDependentOption)
option(BUILD_TILEDATA_EDITOR "Build Cytopia TileData Editor" OFF)
option(BUILD_TEST "Build Cytopia Tests" ON)
option(USE_PACKAGE_MANAGER "Use conan for managing packages" ON)
cmake_dependent_option(USE_PMM "Use PMM for managing conan" OFF WIN32 ON)
option(ENABLE_SDL2_MIXER "Enable SDL2 Mixer" ON)
option(ENABLE_MICROPROFILE "Enable microprofile" OFF)
option(ENABLE_ANGELSCRIPT "Enable AngelScript" ON)
if (NOT BUILD_TILEDATA_EDITOR)
set(_CC_QT "# ")
endif ()
if (NOT ENABLE_SDL2_MIXER)
set(_CC_SDL2_MIXER "# ")
endif ()
if (NOT BUILD_TEST)
set(_CC_CATCH2 "# ")
endif ()
if (NOT ENABLE_ANGELSCRIPT)
set(_CC_ANGELSCRIPT "# ")
endif ()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/conanfile.txt.in" "${CMAKE_CURRENT_SOURCE_DIR}/conanfile.txt")
set(_include_directories "")
set(_compile_definitions "")
set(_link_libraries "")
# create the cmake project
project(
# this will be the ${PROJECT_NAME}
Cytopia
# this will provide ${PROJECT_VERSION}
VERSION 0.2
# Description
DESCRIPTION "A city-building game"
# we are using C++
LANGUAGES CXX
)
# on macOS, usr/local/lib is not in the default search path for libraries. Homebrew install it's libraries there though.
if (APPLE AND NOT USE_PACKAGE_MANAGER)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/local/lib)
endif ()
if (USE_PACKAGE_MANAGER)
if (USE_PMM)
include(cmake/pmm.cmake)
pmm(CONAN
REMOTES
AFG https://api.bintray.com/conan/anotherfoxguy/conan-packages
catchorg https://api.bintray.com/conan/catchorg/Catch2
ror-dependencies https://api.bintray.com/conan/anotherfoxguy/ror-dependencies
BINCRAFTERS
)
if (DEFINED ENV{CI})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif ()
else ()
include(cmake/conan.cmake)
conan_check()
conan_add_remote(NAME AFG URL https://api.bintray.com/conan/anotherfoxguy/conan-packages)
conan_add_remote(NAME bincrafters URL https://api.bintray.com/conan/bincrafters/public-conan)
conan_add_remote(NAME catchorg URL https://api.bintray.com/conan/catchorg/Catch2)
conan_add_remote(NAME ror-dependencies URL https://api.bintray.com/conan/anotherfoxguy/ror-dependencies)
set(CONAN_ARGS
BASIC_SETUP
CMAKE_TARGETS
)
if (NOT DEFINED ENV{CI})
list(APPEND CONAN_ARGS NO_OUTPUT_DIRS)
endif ()
conan_cmake_run(CONANFILE conanfile.txt
BUILD missing
${CONAN_ARGS}
)
endif ()
else (USE_PACKAGE_MANAGER)
# add the path to our custom find modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_image REQUIRED SDL2_image)
pkg_check_modules(SDL2_ttf REQUIRED SDL2_ttf)
pkg_check_modules(ZLIB REQUIRED zlib)
if (ENABLE_SDL2_MIXER)
pkg_check_modules(SDL2_mixer REQUIRED SDL2_mixer)
endif ()
find_package(LIBNOISE REQUIRED)
if (ENABLE_ANGELSCRIPT)
find_package(AngelScript REQUIRED)
endif ()
if (BUILD_TEST)
find_package(Catch2 REQUIRED)
endif (BUILD_TEST)
endif (USE_PACKAGE_MANAGER)
if (ENABLE_MICROPROFILE)
set(FETCHCONTENT_QUIET OFF)
include(FetchContent)
FetchContent_Declare(
microprofile
GIT_REPOSITORY https://github.com/jonasmr/microprofile.git
)
FetchContent_GetProperties(microprofile)
if (NOT microprofile_POPULATED)
FetchContent_Populate(microprofile)
endif ()
set(TREAT_WARNINGS_AS_ERRORS OFF CACHE INTERNAL "" FORCE)
endif (ENABLE_MICROPROFILE)
# get linux distribution
if (UNIX AND NOT APPLE)
execute_process(COMMAND head -1 /etc/os-release OUTPUT_VARIABLE linux_distribution)
endif ()
# Configuration for packaging
include(cmake/CpackConfiguration.cmake)
# Compile options
include(cmake/CompileOptions.cmake)
# set install dir here for convenience
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/redist")
# make sure, every binary lands in the root directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
message(STATUS "Building Project: ${PROJECT_NAME}")
message(STATUS "Build configuration: " ${CMAKE_BUILD_TYPE})
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()
set(SOURCES
src/engine/basics/Camera.cxx
src/engine/basics/isoMath.cxx
src/engine/basics/mapEdit.cxx
src/engine/basics/Settings.cxx
src/engine/basics/Timer.cxx
src/engine/basics/utils.cxx
src/engine/GameObjects/MapNode.cxx
src/engine/map/MapLayers.cxx
src/engine/map/TerrainGenerator.cxx
src/engine/ui/basics/UIElement.cxx
src/engine/ui/basics/ButtonGroup.cxx
src/engine/ui/basics/Layout.cxx
src/engine/ui/widgets/Bar.cxx
src/engine/ui/widgets/Button.cxx
src/engine/ui/widgets/Combobox.cxx
src/engine/ui/widgets/Checkbox.cxx
src/engine/ui/widgets/Frame.cxx
src/engine/ui/widgets/Image.cxx
src/engine/ui/widgets/Text.cxx
src/engine/ui/widgets/TextField.cxx
src/engine/ui/widgets/Tooltip.cxx
src/engine/ui/menuGroups/MenuGroupBuild.cxx
src/engine/Engine.cxx
src/engine/EventManager.cxx
src/engine/Map.cxx
src/engine/Sprite.cxx
src/engine/ResourcesManager.cxx
src/engine/TileManager.cxx
src/engine/UIManager.cxx
src/engine/WindowManager.cxx
src/Game.cxx
src/main.cxx
)
if (ENABLE_SDL2_MIXER)
list(APPEND SOURCES
src/engine/audio/SoundEffect.cxx
src/engine/audio/SoundEffect.cxx
src/engine/audio/Music.cxx
src/engine/AudioMixer.cxx
)
endif ()
if (ENABLE_ANGELSCRIPT)
list(APPEND SOURCES
external/as_add_on/scriptbuilder/scriptbuilder.cpp
external/as_add_on/scriptbuilder/scriptbuilder.h
external/as_add_on/scriptstdstring/scriptstdstring.h
external/as_add_on/scriptstdstring/scriptstdstring.cpp
src/Scripting/ScriptEngine.cxx
src/Scripting/ScriptEngine.hxx
)
endif ()
if (ENABLE_MICROPROFILE)
list(APPEND SOURCES
${microprofile_SOURCE_DIR}/microprofile.h
${microprofile_SOURCE_DIR}/microprofile_html.h
${microprofile_SOURCE_DIR}/microprofile.cpp
)
endif (ENABLE_MICROPROFILE)
if (MSVC)
set(SOURCES ${SOURCES} ${PROJECT_SOURCE_DIR}/build/msvc/icon_cytopia.rc)
endif ()
if (APPLE)
file(GLOB_RECURSE MAC_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources/*)
file(GLOB_RECURSE MAC_EXTERN_RESOURCES ${PROJECT_SOURCE_DIR}/Cytopia_Resources/*)
# not working now, we need a special icon file for apple
set(ICON_PATH ${PROJECT_SOURCE_DIR}/resources/images/app_icons/cytopia_icon_iso.icns)
set(MACOSX_BUNDLE_ICON_FILE cytopia_icon_iso.icns)
# set each file as resources file for the app image.
foreach (resource_file ${MAC_RESOURCES})
get_filename_component(buildDirRelFilePath ${resource_file} DIRECTORY)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" buildDirRelFilePath ${buildDirRelFilePath})
set_source_files_properties(${resource_file} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/${buildDirRelFilePath})
endforeach ()
foreach (resource_file ${MAC_EXTERN_RESOURCES})
get_filename_component(buildDirRelFilePath ${resource_file} DIRECTORY)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/Cytopia_Resources/" "" buildDirRelFilePath ${buildDirRelFilePath})
set_source_files_properties("${resource_file}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources/resources/audio/${buildDirRelFilePath})
endforeach ()
# set_source_files_properties(${PROJECT_SOURCE_DIR}/Cytopia_Resources/music PROPERTIES MACOSX_PACKAGE_LOCATION Resources/resources/audio/music)
set_source_files_properties(${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${myApp_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} ${ICON_PATH} ${MAC_RESOURCES} ${MAC_EXTERN_RESOURCES})
else ()
# create a new executable with the same name as the project
add_executable(${PROJECT_NAME} ${SOURCES})
endif ()
if (ENABLE_MICROPROFILE)
list(APPEND _include_directories ${microprofile_SOURCE_DIR})
list(APPEND _compile_definitions
MICROPROFILE_ENABLED
MICROPROFILE_GPU_TIMERS=0
)
if (WIN32)
list(APPEND _link_libraries ws2_32.lib)
endif (WIN32)
endif (ENABLE_MICROPROFILE)
if (MINGW)
# need to link with mingw32 before SDL2
list(APPEND _link_libraries mingw32)
endif ()
# link the libraries that we've found
if (USE_PACKAGE_MANAGER)
list(APPEND _link_libraries
CONAN_PKG::sdl2
CONAN_PKG::sdl2_image
CONAN_PKG::sdl2_ttf
CONAN_PKG::libnoise
CONAN_PKG::zlib
)
if (ENABLE_SDL2_MIXER)
list(APPEND _link_libraries CONAN_PKG::sdl2_mixer)
endif ()
if (ENABLE_ANGELSCRIPT)
list(APPEND _link_libraries CONAN_PKG::AngelScript)
endif ()
if (BUILD_TEST)
list(APPEND _link_libraries CONAN_PKG::Catch2)
endif ()
else (USE_PACKAGE_MANAGER)
list(APPEND _include_directories
${SDL2_INCLUDE_DIRS}
${SDL2_image_INCLUDE_DIRS}
${SDL2_ttf_INCLUDE_DIRS}
${ZLIB_INCLUDEDIR}
)
list(APPEND _link_libraries
${SDL2_LIBRARIES}
${SDL2_image_LIBRARIES}
${SDL2_ttf_LIBRARIES}
LIBNOISE::LIBNOISE_LIBRARIES
${ZLIB_LIBRARIES}
)
if (ENABLE_SDL2_MIXER)
list(APPEND _link_libraries ${SDL2_mixer_LIBRARIES})
endif ()
if (ENABLE_ANGELSCRIPT)
list(APPEND _link_libraries ${AngelScript_LIBRARY})
endif ()
if (BUILD_TEST)
list(APPEND _link_libraries ${CATCH2_LIBRARIES})
endif ()
endif (USE_PACKAGE_MANAGER)
# enable C++14
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
list(APPEND _compile_definitions VERSION="${PROJECT_NAME} ${PROJECT_VERSION} - tech preview")
if (ENABLE_SDL2_MIXER)
list(APPEND _compile_definitions USE_SDL2_MIXER)
endif ()
if (ENABLE_ANGELSCRIPT)
list(APPEND _compile_definitions USE_ANGELSCRIPT)
list(APPEND _include_directories external/as_add_on)
endif ()
target_include_directories(${PROJECT_NAME} PRIVATE ${_include_directories})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${_compile_definitions})
target_link_libraries(${PROJECT_NAME} PRIVATE ${_link_libraries})
# copy the resources to the compiled directory
add_custom_command(
TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:${PROJECT_NAME}>/resources
)
if (EXISTS ${PROJECT_SOURCE_DIR}/Cytopia_Resources)
add_custom_command(
TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/Cytopia_Resources/music $<TARGET_FILE_DIR:${PROJECT_NAME}>/resources/audio/music
)
else ()
message(WARNING "No Resources directory found. Please init git submodules with following command:")
message("git submodule update --init --recursive")
endif ()
if (BUILD_TILEDATA_EDITOR)
add_subdirectory(src/TileDataUi)
# QT5 is used for the TileData Editing tool
if (USE_PACKAGE_MANAGER)
find_package(Qt5 CONFIG COMPONENTS Core Widgets REQUIRED)
else ()
find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
endif ()# USE_PACKAGE_MANAGER
endif ()# BUILD_TILEDATA_EDITOR
# use Doxygen to generate the documentation
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DoxyFile_src ${PROJECT_SOURCE_DIR}/Doxyfile)
set(DoxyFile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DoxyFile_src} ${DoxyFile} @ONLY)
message("Use target doc to build the documentation")
add_custom_target(
doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DoxyFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
endif ()
if (MSVC)
# set startup project for Visual Studio Builds
set_property(
DIRECTORY ${PROJECT_SOURCE_DIR}
PROPERTY
VS_STARTUP_PROJECT ${PROJECT_NAME}
)
# set Visual Studio working directory to the Configuration directory
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$(Configuration)"
)
endif ()
install(TARGETS ${PROJECT_NAME} DESTINATION .)
if (NOT APPLE)
install(DIRECTORY resources DESTINATION .)
if (EXISTS ${PROJECT_SOURCE_DIR}/Cytopia_Resources)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/Cytopia_Resources/music DESTINATION ./resources/audio)
endif ()
endif ()
install(FILES ReleaseNotes.txt credits.txt DESTINATION .)
if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE RESOURCE TRUE)
endif ()
if (BUILD_TEST)
include(tests/CMakeLists.txt)
endif (BUILD_TEST)
include(FeatureSummary)
feature_summary(WHAT ALL)