-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
97 lines (79 loc) · 3.33 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
cmake_minimum_required(VERSION 3.24)
project(fplayer C)
# use strict C99
set(CMAKE_C_STANDARD 99)
set(PEDANTIC_COMPILER_FLAGS "-Wall -Werror -Wextra -Wno-unused-value -pedantic")
if (DEFINED CMAKE_PREFIX_PATH)
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
include_directories(${CMAKE_PREFIX_PATH}/include)
link_directories(${CMAKE_PREFIX_PATH}/lib)
endif ()
if (APPLE)
# silence macOS OpenAL deprecation warning messages
add_compile_definitions(OPENAL_DEPRECATED=)
endif ()
# clang sanitizer flags
option(USE_ASAN "enable AddressSanitizer" OFF)
option(USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
if (USE_ASAN)
message(STATUS "AddressSanitizer enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
elseif (USE_UBSAN)
message(STATUS "UndefinedBehaviorSanitizer enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
endif ()
# common shared library
file(GLOB_RECURSE COMMON_FILES "common/*.[ch]")
set_source_files_properties(${COMMON_FILES} PROPERTIES COMPILE_FLAGS ${PEDANTIC_COMPILER_FLAGS})
add_library(common STATIC ${COMMON_FILES})
target_include_directories(common PUBLIC "dep/libtinyfseq" "dep/libtinylor" "dep/sl" common)
# mftool executable
file(GLOB_RECURSE MFTOOL_FILES "tool/mftool/*.c")
set_source_files_properties(${MFTOOL_FILES} PROPERTIES COMPILE_FLAGS ${PEDANTIC_COMPILER_FLAGS})
add_executable(mftool ${MFTOOL_FILES})
target_include_directories(mftool PRIVATE common)
target_link_libraries(mftool common)
# gentool executable
file(GLOB_RECURSE GENTOOL_FILES "tool/gentool/*.c")
set_source_files_properties(${GENTOOL_FILES} PROPERTIES COMPILE_FLAGS ${PEDANTIC_COMPILER_FLAGS})
add_executable(gentool ${GENTOOL_FILES})
target_include_directories(gentool PRIVATE common)
target_link_libraries(gentool common zstd)
# fplayer executable
file(GLOB_RECURSE SRC_FILES "src/*.[ch]")
set_source_files_properties(${SRC_FILES} PROPERTIES COMPILE_FLAGS ${PEDANTIC_COMPILER_FLAGS})
add_executable(fplayer ${SRC_FILES})
# compiling on FreeBSD without explicitly linking libusb (used by libserialport) results in a build error
if (CMAKE_HOST_SYSTEM MATCHES "FreeBSD-*")
target_link_libraries(fplayer usb)
endif ()
target_include_directories(fplayer PRIVATE common "dep/cJSON")
target_link_libraries(fplayer m pthread common serialport cjson zstd)
# OpenAL
if (APPLE)
target_link_libraries(fplayer "-framework OpenAL" alut)
else ()
target_link_libraries(fplayer openal alut)
endif ()
# Testing
enable_testing()
add_executable(test_cell test/cell.c src/crmap.c src/cell.c)
target_include_directories(test_cell PRIVATE common src)
target_link_libraries(test_cell common cjson)
add_test(NAME cell COMMAND test_cell)
add_executable(test_fd test/fd.c)
target_include_directories(test_fd PRIVATE common)
target_link_libraries(test_fd common)
add_test(NAME fd COMMAND test_fd)
add_executable(test_queue test/queue.c src/queue.c)
target_include_directories(test_queue PRIVATE common src)
target_link_libraries(test_queue common)
add_test(NAME queue COMMAND test_queue)
add_executable(test_strtolb test/strtolb.c)
target_include_directories(test_strtolb PRIVATE common)
target_link_libraries(test_strtolb common)
add_test(NAME strtolb COMMAND test_strtolb)
add_executable(test_sl test/sl.c)
target_include_directories(test_sl PRIVATE common)
target_link_libraries(test_sl common)
add_test(NAME sl COMMAND test_sl)