forked from omf2097/openomf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
343 lines (296 loc) · 10.2 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
cmake_minimum_required(VERSION 3.7.2)
project(OpenOMF C)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-scripts)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
set(VERSION_MAJOR "0")
set(VERSION_MINOR "6")
set(VERSION_PATCH "6")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# Options
OPTION(USE_TESTS "Build unittests" OFF)
OPTION(USE_TOOLS "Build tools" OFF)
OPTION(USE_OGGVORBIS "Add support for Ogg Vorbis audio" OFF)
OPTION(USE_DUMB "Use libdumb for module playback" OFF)
OPTION(USE_XMP "Use libxmp for module playback" ON)
OPTION(USE_OPENAL "Support OpenAL for audio playback" ON)
OPTION(USE_SANITIZERS "Enable Asan and Ubsan" OFF)
OPTION(USE_TIDY "Use clang-tidy for checks" OFF)
OPTION(USE_FORMAT "Use clang-format for checks" OFF)
# These flags are used for all builds
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "-Wall")
set(CMAKE_C_FLAGS_DEBUG "-ggdb -DDEBUGMODE -Werror -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -fno-omit-frame-pointer -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
add_definitions(-DV_MAJOR=${VERSION_MAJOR} -DV_MINOR=${VERSION_MINOR} -DV_PATCH=${VERSION_PATCH})
# See if we have Git, and use it to fetch current SHA1 hash
find_package(Git)
if(GIT_FOUND)
message(STATUS "Git found: ${GIT_EXECUTABLE}")
execute_process(
COMMAND ${GIT_EXECUTABLE} "rev-parse" "HEAD"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE SHA1_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Git SHA1 Hash: ${SHA1_HASH}")
add_definitions(-DSHA1_HASH="${SHA1_HASH}")
endif()
# System packages (hard dependencies)
find_package(SDL2 REQUIRED)
find_package(enet)
find_package(confuse)
find_package(argtable2)
find_package(PNG)
find_package(ZLIB)
# Check functions and generate platform configuration file
check_symbol_exists(strdup "string.h" HAVE_STD_STRDUP)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/platform.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/platform.h)
# If USE_DUMB flag is on, turn on libdumb
if(USE_DUMB)
find_package(dumb)
add_definitions(-DUSE_DUMB)
if(MINGW)
add_definitions(-D_FILE_OFFSET_BITS=64)
endif()
endif()
# If XMP has been selected, attempt to find it
if(USE_XMP)
find_package(xmp)
add_definitions(-DUSE_XMP)
endif()
# Audio sink selection
if(USE_OPENAL)
find_package(OpenAL)
add_definitions(-DUSE_OPENAL)
else()
message(STATUS "Note! No audio sink selected; Music/sounds will not play.")
endif()
# When building with MingW, do not look for Intl
if(MINGW)
set(LIBINTL_INCLUDE_DIR "")
set(LIBINTL_LIBRARIES "")
else()
find_package(Intl)
endif()
# If we want to build support for vorbis streaming, find these too
if(USE_OGGVORBIS)
find_package(ogg)
find_package(vorbis)
add_definitions(-DUSE_OGGVORBIS)
endif()
# If tests are enabled, find CUnit
if(USE_TESTS)
find_package(CUnit)
endif()
# Only strip on GCC (clang does not appreciate)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,-s")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Wl,-s")
endif()
# Find OpenOMF core sources
file(GLOB_RECURSE OPENOMF_SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/*/*.c")
set(COREINCS
src
${CMAKE_CURRENT_BINARY_DIR}/src/
${SDL2_INCLUDE_DIRS}
${CONFUSE_INCLUDE_DIR}
${Intl_INCLUDE_DIR}
${ENET_INCLUDE_DIR}
${ARGTABLE2_INCLUDE_DIR}
${PNG_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
)
set(CORELIBS
${SDL2_LIBRARIES}
${CONFUSE_LIBRARY}
${Intl_LIBRARIES}
${ENET_LIBRARY}
${ARGTABLE2_LIBRARY}
${PNG_LIBRARY}
${ZLIB_LIBRARY}
)
# Handle module playback libraries
if(USE_DUMB)
set(CORELIBS ${CORELIBS} ${DUMB_LIBRARY})
set(COREINCS ${COREINCS} ${DUMB_INCLUDE_DIR})
endif()
if(USE_XMP)
set(CORELIBS ${CORELIBS} ${XMP_LIBRARY})
set(COREINCS ${COREINCS} ${XMP_INCLUDE_DIR})
endif()
# Audio sinks
if(USE_OPENAL)
set(CORELIBS ${CORELIBS} ${OPENAL_LIBRARY})
set(COREINCS ${COREINCS} ${OPENAL_INCLUDE_DIR})
endif()
# If we support ogg vorbis, add library includes etc.
if(USE_OGGVORBIS)
set(COREINCS ${COREINCS} ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
set(CORELIBS ${CORELIBS} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
endif()
# MingW build should add mingw32 lib
if(MINGW)
set(CORELIBS mingw32 ${CORELIBS})
endif()
# On windows, add winsock2 and winmm
if(WIN32)
set(CORELIBS ${CORELIBS} ws2_32 winmm)
endif()
# On unix platforms, add libm (sometimes needed, it seems)
if(UNIX)
SET(CORELIBS ${CORELIBS} m)
endif()
# Set include directories for all builds
include_directories(${COREINCS})
# Build core sources first as an object library
# this can then be reused in tests and main executable to speed things up
add_library(openomf_core OBJECT ${OPENOMF_SRC})
set(CORELIBS openomf_core ${CORELIBS})
# Set icon for windows executable
if(WIN32)
SET(ICON_RESOURCE "resources/icons/openomf.rc")
endif()
# Build the game binary
add_executable(openomf src/main.c src/engine.c ${ICON_RESOURCE})
# Build tools if requested
set(TOOL_TARGET_NAMES)
if(USE_TOOLS)
add_executable(bktool tools/bktool/main.c
tools/shared/animation_misc.c
tools/shared/conversions.c)
add_executable(aftool tools/aftool/main.c
tools/shared/animation_misc.c
tools/shared/conversions.c)
add_executable(soundtool tools/soundtool/main.c)
add_executable(fonttool tools/fonttool/main.c)
add_executable(languagetool tools/languagetool/main.c)
add_executable(omf_parse tools/stringparser/main.c)
add_executable(afdiff tools/afdiff/main.c)
add_executable(rectool tools/rectool/main.c tools/shared/pilot.c)
add_executable(pictool tools/pictool/main.c)
add_executable(scoretool tools/scoretool/main.c)
add_executable(trntool tools/trntool/main.c tools/shared/pilot.c)
add_executable(altpaltool tools/altpaltool/main.c)
add_executable(chrtool tools/chrtool/main.c tools/shared/pilot.c)
add_executable(setuptool tools/setuptool/main.c tools/shared/pilot.c)
list(APPEND TOOL_TARGET_NAMES
bktool
aftool
soundtool
fonttool
languagetool
omf_parse
afdiff
rectool
pictool
scoretool
trntool
altpaltool
chrtool
setuptool
)
message(STATUS "Development: CLI tools enabled")
else()
message(STATUS "Development: CLI tools disabled")
endif()
# Linting via clang-tidy
if(USE_TIDY)
set_target_properties(openomf PROPERTIES C_CLANG_TIDY "clang-tidy")
set_target_properties(openomf_core PROPERTIES C_CLANG_TIDY "clang-tidy")
foreach(TARGET ${TOOL_TARGET_NAMES})
set_target_properties(${TARGET} PROPERTIES C_CLANG_TIDY "clang-tidy")
endforeach()
message(STATUS "Development: clang-tidy enabled")
else()
message(STATUS "Development: clang-tidy disabled")
endif()
# Formatting via clang-format
if(USE_FORMAT)
include(ClangFormat)
file(
GLOB_RECURSE
SRC_FILES
RELATIVE ${CMAKE_SOURCE_DIR}
"src/*.h"
"src/*.c"
"tools/*.c"
"tools/*.h"
"testing/*.c"
"testing/*.h"
)
clangformat_setup(${SRC_FILES})
message(STATUS "Development: clang-format enabled")
else()
message(STATUS "Development: clang-format disabled")
endif()
# Enable AddressSanitizer if requested (these libs need to be first on the list!)
if(USE_SANITIZERS)
set(CORELIBS asan ubsan ${CORELIBS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined")
message(STATUS "Development: Asan and Ubsan enabled")
else()
message(STATUS "Development: Asan and Ubsan disabled")
endif()
if(MINGW)
# Don't show console on mingw in release builds (but enable if debug mode)
if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
set_target_properties(openomf PROPERTIES LINK_FLAGS "-mwindows")
else()
set_target_properties(openomf PROPERTIES LINK_FLAGS "-mconsole")
endif()
# Make sure console apps are always in terminal output mode.
foreach(TARGET ${TOOL_TARGET_NAMES})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "-mconsole")
endforeach()
# Use static libgcc when on mingw
target_link_options(openomf PRIVATE -static-libgcc)
foreach(TARGET ${TOOL_TARGET_NAMES})
target_link_options(${TARGET} PRIVATE -static-libgcc)
endforeach()
endif()
# Make sure libraries are linked
target_link_libraries(openomf ${CORELIBS})
foreach(TARGET ${TOOL_TARGET_NAMES})
target_link_libraries(${TARGET} ${CORELIBS})
endforeach()
# Testing stuff
if(CUNIT_FOUND)
enable_testing()
include_directories(${CUNIT_INCLUDE_DIR} testing/ src/)
SET(CORELIBS ${CORELIBS} ${CUNIT_LIBRARY})
file(GLOB_RECURSE TEST_SRC RELATIVE ${CMAKE_SOURCE_DIR} "testing/*.c")
add_executable(openomf_test_main ${TEST_SRC})
# This makes loading test resources possible
target_compile_definitions(openomf_test_main PRIVATE
TESTS_ROOT_DIR="${CMAKE_SOURCE_DIR}/testing")
target_link_libraries(openomf_test_main ${CORELIBS})
if(MINGW)
# Always build as a console executable with mingw
set_target_properties(openomf_test_main PROPERTIES LINK_FLAGS "-mconsole")
endif()
add_test(main openomf_test_main)
message(STATUS "Development: Unit-tests are enabled")
else()
message(STATUS "Development: Unit-tests are disabled")
endif()
# Packaging
add_subdirectory(packaging)
# Installation
if(WIN32)
# On windows, generate a flat directory structure under openomf/ subdir.
# This way we have an "openomf/" root directory inside the zip file.
install(TARGETS openomf RUNTIME DESTINATION openomf/ COMPONENT Binaries)
install(FILES resources/openomf.bk DESTINATION openomf/resources/ COMPONENT Data)
install(FILES README.md INSTALL.md LICENSE DESTINATION openomf/ COMPONENT Data)
else()
# On unixy systems, follow standard.
install(TARGETS openomf RUNTIME DESTINATION bin COMPONENT Binaries)
install(FILES resources/openomf.bk resources/icons/openomf.png
DESTINATION share/games/openomf/
COMPONENT Data
)
endif()