-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
75 lines (58 loc) · 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
cmake_minimum_required(VERSION 3.17)
project(hamurabi VERSION 0.1
DESCRIPTION "Hamurabi - a text adventure game written in C99"
LANGUAGES C ASM
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(DISABLE_TESTS "If tests should be compiled or not" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# C11 minimum
set(CMAKE_C_STANDARD 11)
# Show all warning messages
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Og")
# Build Types
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
CACHE STRING "Choose the type of build, options are: asan lsan msan ubsan"
FORCE)
# AddressSanitize
set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS} -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g"
CACHE STRING "Flags used by the C compiler during AddressSanitizer builds."
FORCE)
# LeakSanitizer
set(CMAKE_C_FLAGS_LSAN
"${CMAKE_C_FLAGS} -fsanitize=leak -fno-omit-frame-pointer -g"
CACHE STRING "Flags used by the C compiler during LeakSanitizer builds."
FORCE)
# MemorySanitizer
set(CMAKE_C_FLAGS_MSAN
"${CMAKE_C_FLAGS} -fsanitize=memory -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g"
CACHE STRING "Flags used by the C compiler during MemorySanitizer builds."
FORCE)
# UndefinedBehaviour
set(CMAKE_C_FLAGS_UBSAN
"${CMAKE_C_FLAGS} -fsanitize=undefined"
CACHE STRING "Flags used by the C compiler during UndefinedBehaviourSanitizer builds."
FORCE)
include_directories(include)
list(APPEND EXTRA_SRC
include/banned.h
include/hamurabi.h
)
list(APPEND HAMURABI_SRC
src/hamurabi.c
)
add_executable(hamurabi
src/main.c
${HAMURABI_SRC}
${EXTRA_SRC}
)
if (NOT DISABLE_TESTS)
find_package(Check REQUIRED)
enable_testing()
include(CheckTest)
set(LIBS
${CHECK_LIBRARIES}
)
CHECK_TEST(check_hamurabi LIBS ${LIBS} SRC ${HAMURABI_SRC} test/check_hamurabi.c DEPS hamurabi)
endif()