-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
447 lines (398 loc) · 11.4 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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
cmake_minimum_required (VERSION 3.6.0)
SET(CMAKE_COLOR_MAKEFILE ON)
project(breakhack C)
set(breakhack_GAME_TITLE "BreakHack")
set(breakhack_MAJOR_VERSION 4)
set(breakhack_MINOR_VERSION 0)
set(breakhack_PATCH_VERSION 3)
set(breakhack_RELEASE_TYPE "")
# Checksums
set(breakhack_STEAMAPI_DLL_CHECKSUM 0x1a20dd5)
set(breakhack_STEAMAPI_SO_CHECKSUM 0x19f8c71)
include(build_deps/cmake/FindCCache.cmake)
include(build_deps/cmake/FindCMocka.cmake)
include(build_deps/cmake/Findcppcheck.cmake)
configure_file(
"${PROJECT_SOURCE_DIR}/src/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
set(DISABLE_STEAM_BUILD OFF CACHE BOOL "Disable Steam build")
if (NOT DISABLE_STEAM_BUILD)
if (EXISTS "${PROJECT_SOURCE_DIR}/lib/steamworks_c_wrapper/sdk")
MESSAGE ( STATUS "Steam SDK located, Steam build enabled")
set(STEAM ON)
else ()
MESSAGE ( STATUS "Steam SDK not found, Steam build disabled")
endif()
else ()
MESSAGE ( STATUS "Steam build disabled by DISABLE_STEAM_BUILD flag")
endif ()
if (STEAM)
add_subdirectory(lib/steamworks_c_wrapper)
endif()
add_subdirectory(lib/bh_random)
add_subdirectory(lib/checksum)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CLANG 1)
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(GCC 1)
endif()
if ("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(NINJA 1)
endif()
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(OSX 1)
endif()
set (default_build_type "Release")
if (NOT CMAKE_BUILD_TYPE AND default_build_type)
message( STATUS "Setting default buildtype to '${default_build_type}' as none was specified")
set(CMAKE_BUILD_TYPE "${default_build_type}")
endif ()
# Deal with travis compile issue
if (CCACHE_FOUND AND CLANG)
add_definitions(-Qunused-arguments -fcolor-diagnostics)
endif()
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_BUILD TRUE)
endif()
IF ( MSVC )
MESSAGE ( STATUS "Setting MSVC MT switches")
string (REPLACE
"/MDd"
"/MTd"
CMAKE_C_FLAGS_DEBUG
${CMAKE_C_FLAGS_DEBUG}
)
string (REPLACE
"/MDd"
"/MTd"
CMAKE_C_FLAGS_RELEASE
${CMAKE_C_FLAGS_RELEASE}
)
ELSEIF ( WIN32 )
SET (
CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -mconsole"
)
SET (
CMAKE_C_FLAGS_RELEASE
"${CMAKE_C_FLAGS_RELEASE} -mwindows"
)
ENDIF ()
#IF ( GCC )
#SET (
#CMAKE_C_FLAGS_DEBUG
#"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
#)
#ENDIF ( GCC )
if (STEAM)
include_directories(
lib/steamworks_c_wrapper/src
)
endif ()
# Include SDL2
set(SDL_STATIC ON)
set(SDL_SHARED OFF)
set(SDL_TEST OFF)
add_subdirectory(lib/SDL)
set(SDL2_INCLUDE_DIR lib/SDL/include)
set(SDL2_LIBRARY SDL2-static)
set(SDL2_MAIN_LIBRARY SDL2main)
# Include SDL2_image/mixer/ttf
set(BUILD_SHARED_LIBS OFF)
set(SDL2IMAGE_PNG ON)
set(SDL2IMAGE_JPG ON)
set(SDL2IMAGE_AVIF OFF)
set(SDL2IMAGE_BMP OFF)
set(SDL2IMAGE_GIF OFF)
set(SDL2IMAGE_JXL OFF)
set(SDL2IMAGE_LBM OFF)
set(SDL2IMAGE_PCX OFF)
set(SDL2IMAGE_PNM OFF)
set(SDL2IMAGE_QOI OFF)
set(SDL2IMAGE_SVG OFF)
set(SDL2IMAGE_TGA OFF)
set(SDL2IMAGE_TIF OFF)
set(SDL2IMAGE_WEBP OFF)
set(SDL2IMAGE_XCF OFF)
set(SDL2IMAGE_XPM OFF)
set(SDL2IMAGE_XV OFF)
add_subdirectory(lib/SDL_image)
set(SDL2_IMAGE_INCLUDE_DIR lib/SDL_image/include)
set(SDL2_IMAGE_LIBRARY SDL2_image)
# opusfile caused issues in macos build and we don't need it anyways
set(SDL2MIXER_OPUS OFF)
add_subdirectory(lib/SDL_mixer)
set(SDL2_MIXER_INCLUDE_DIR lib/SDL_mixer/include)
set(SDL2_MIXER_LIBRARY SDL2_mixer)
add_subdirectory(lib/SDL_ttf)
set(SDL2_TTF_INCLUDE_DIR lib/SDL_ttf/include)
set(SDL2_TTF_LIBRARY SDL2_ttf)
# Include lua lib
add_subdirectory(lib/lua-5.3.5)
set(LUA_LIBRARIES lua)
set(LUA_INCLUDE_DIR lib/lua-5.3.5/src)
# Include PHYSFS lib
set(PHYSFS_BUILD_SHARED off CACHE INTERNAL "" FORCE)
set(PHYSFS_BUILD_TEST off CACHE INTERNAL "" FORCE)
add_subdirectory(lib/physfs-3.0)
include_directories(lib/physfs-3.0/src)
set(PHYSFS_LIBRARY physfs-static)
set(PHYSFS_INCLUDE_DIR physfs-3.0/src)
include_directories(
${PROJECT_BINARY_DIR}
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR}
${PHYSFS_INCLUDE_DIR}
${LUA_INCLUDE_DIR}
lib/sqlite3
lib/bh_random/src
lib/checksum/src
)
if (CMOCKA_FOUND)
include_directories(
${CMOCKA_INCLUDE_DIR}
)
endif(CMOCKA_FOUND)
if (NOT MSVC)
add_definitions(-std=gnu11
-pedantic -Wall -Wextra -Wshadow
-Wpointer-arith -Wcast-qual
-Wstrict-prototypes
-Wmissing-prototypes
-Wconversion -Wno-sign-conversion
)
if (NOT APPLE)
add_definitions(-static -static-libgcc -static-libstdc++)
endif ()
endif (NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
if (STEAM)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSTEAM_BUILD")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DSTEAM_BUILD")
set(STEAM_SOURCES
src/steam/steamworks_api_wrapper.c
)
else ()
set(STEAM_SOURCES "")
endif ()
if (MINGW)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DMINGW")
endif (MINGW)
if (NOT MSVC AND NOT NINJA)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__FNAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
else ()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__FNAME__=__FILE__")
endif ()
# PROGRAMS:
add_executable(breakhack
src/main.c
src/texture.c
src/screenresolution.c
src/sprite.c
src/sprite_util.c
src/util.c
src/event.c
src/player.c
src/save.c
src/map.c
src/map_lua.c
src/camera.c
src/timer.c
src/roommatrix.c
src/position.c
src/monster.c
src/stats.c
src/actiontext.c
src/random.c
src/time.c
src/linkedlist.c
src/hashtable.c
src/gui.c
src/item.c
src/item_builder.c
src/pointer.c
src/gui_button.c
src/particle_engine.c
src/particle_emitter.c
src/menu.c
src/collisions.c
src/keyboard.c
src/input.c
src/mixer.c
src/io_util.c
src/physfsrwops.c
src/skillbar.c
src/texturecache.c
src/skill.c
src/projectile.c
src/vector2d.c
src/map_room_modifiers.c
lib/sqlite3/sqlite3.c
src/db.c
src/settings.c
src/actiontextbuilder.c
src/animation.c
src/trap.c
src/artifact.c
src/screen.c
src/hiscore.c
src/object.c
src/gui_util.c
src/tooltip.c
src/gamecontroller.c
src/effect_util.c
${STEAM_SOURCES}
)
if (MSVC)
source_group("Header files" REGULAR_EXPRESSION ".*\\.h")
source_group("Source files" REGULAR_EXPRESSION ".*\\.c")
endif ()
# Sqlite has some warnings that I we don't need to see
set_source_files_properties(lib/sqlite3/sqlite3.c COMPILE_FLAGS -w)
target_link_libraries(breakhack
${CMAKE_DL_LIBS} # Sqlite needs DL libs
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARY}
${SDL2_TTF_LIBRARY}
${SDL2_MIXER_LIBRARY}
${LUA_LIBRARIES}
${PHYSFS_LIBRARY}
bh_random
checksum
)
if (MSVC OR MINGW)
target_link_libraries(breakhack
${SDL2_MAIN_LIBRARY}
)
endif ()
if (STEAM)
target_link_libraries(breakhack
${STEAMWORKS_LIBRARY}
steamworks_c_wrapper
)
endif ()
if (MSVC)
set_target_properties(breakhack PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE /NODEFAULTLIB:MSVCRTD")
set_target_properties(breakhack PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
set_target_properties(breakhack PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
set_target_properties(breakhack PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
set_target_properties(breakhack PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /NODEFAULTLIB:MSVCRTD")
set_target_properties(breakhack PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS")
endif (MSVC)
# TESTS:
IF (CMOCKA_FOUND AND NOT OSX AND NOT CLANG)
find_package(Threads REQUIRED)
enable_testing()
add_executable(test_util test/test_util.c src/util.c)
target_link_libraries(test_util ${CMOCKA_LIBRARY})
add_test(test_util test_util)
add_executable(test_linkedlist test/test_linkedlist.c src/linkedlist.c src/util.c)
target_link_libraries(test_linkedlist ${CMOCKA_LIBRARY})
add_test(test_linkedlist test_linkedlist)
add_executable(test_hashtable test/test_hashtable.c src/hashtable.c src/util.c)
target_link_libraries(test_hashtable ${CMOCKA_LIBRARY})
add_test(test_hashtable test_hashtable)
add_executable(test_input test/test_input.c src/input.c src/keyboard.c)
target_link_libraries(test_input
${CMOCKA_LIBRARY}
${SDL2_LIBRARY}
)
#set_target_properties(test_input PROPERTIES
#LINK_FLAGS "-Wl,--wrap,keyboard_direction_press -Wl,--wrap,keyboard_press")
add_test(test_input test_input)
ENDIF ()
# LINT:
if (CPPCHECK_FOUND)
add_custom_target(lint
COMMAND ${CPPCHECK_EXECUTABLE} --force --language=c --template=gcc --error-exitcode=1 --quiet --suppress=missingInclude --inline-suppr --enable=warning,style,performance,portability,information,missingInclude src/
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Run cppcheck"
)
endif (CPPCHECK_FOUND)
if (NOT DEBUG_BUILD)
add_custom_target(assets_pack ALL
COMMAND ${CMAKE_COMMAND} -E tar "-cf" "../assets.pack" "--format=zip" --
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Characters"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Commissions"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/GUI"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Items"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Objects"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Sounds"
"${CMAKE_CURRENT_SOURCE_DIR}/assets/Extras"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets
)
add_custom_target(data_pack ALL
COMMAND ${CMAKE_COMMAND} -E tar "-cf" "../data.pack" "--format=zip" --
"mapgen.lua"
"maproombuilder.lua"
"menumapgen.lua"
"monstergen.lua"
"trapgen.lua"
"chestgen.lua"
"layoutparser.lua"
"pitlayouts.dat"
"walllayouts.dat"
"shoplayouts.dat"
"lockedroomlayouts.dat"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
)
endif ()
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT "Release")
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
if (WIN32)
if (STEAM)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
lib/steamworks_c_wrapper/sdk/redistributable_bin/steam_api.dll
)
endif ()
else ()
if (STEAM)
SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
lib/steamworks_c_wrapper/sdk/redistributable_bin/linux64/libsteam_api.so
build_deps/linux/breakhack.run
)
endif ()
endif ()
include(InstallRequiredSystemLibraries)
INSTALL(TARGETS breakhack
COMPONENT Release
RUNTIME DESTINATION bin/
)
INSTALL(FILES assets.pack data.pack
COMPONENT Release
DESTINATION share/breakhack/
)
set(CPACK_INSTALL_CMAKE_PROJECTS "${PROJECT_BINARY_DIR};breakhack;Release;.")
set(CPACK_PACKAGE_NAME "BreakHack")
set(CPACK_PACKAGE_VENDOR "OliveShark")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/package)
set(CPACK_PACKAGE_VERSION_MAJOR ${breakhack_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${breakhack_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${breakhack_PATCH_VERSION})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "BreakHack")
set(CPACK_PACKAGE_CHECKSUM "MD5")
if (WIN32)
set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-win32")
else ()
set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
endif ()
if (STEAM)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}-steambuild")
endif ()
if(UNIX)
set(CPACK_GENERATOR TGZ ZIP)
set(CPACK_STRIP_FILES breakhack)
set(CPACK_SOURCE_STRIP_FILES "")
elseif(WIN32)
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_GENERATOR NSIS ZIP)
endif()
include(CPack)