-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
128 lines (99 loc) · 2.96 KB
/
CMakeLists.txt
File metadata and controls
128 lines (99 loc) · 2.96 KB
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
cmake_minimum_required(VERSION 3.16)
project(skiresort
VERSION 1.0.0
DESCRIPTION "Modular ski resort simulation written in C"
LANGUAGES C
)
# ---- Global build settings --------------------------------------------------
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ---- Project options --------------------------------------------------------
option(SKIRESORT_ENABLE_WARNINGS "Enable strict compiler warnings" ON)
option(SKIRESORT_ENABLE_SANITIZERS "Enable address/undefined sanitizers in Debug builds" ON)
option(SKIRESORT_BUILD_TESTS "Build test targets" ON)
# ---- Interface targets: warnings / sanitizers -------------------------------
add_library(skiresort_warnings INTERFACE)
add_library(skiresort_sanitizers INTERFACE)
if(SKIRESORT_ENABLE_WARNINGS)
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(skiresort_warnings INTERFACE
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wconversion
-Werror
)
elseif(MSVC)
target_compile_options(skiresort_warnings INTERFACE
/W4
/WX
)
endif()
endif()
if(SKIRESORT_ENABLE_SANITIZERS)
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(skiresort_sanitizers INTERFACE
$<$<CONFIG:Debug>:-fsanitize=address,undefined -g>
)
target_link_options(skiresort_sanitizers INTERFACE
$<$<CONFIG:Debug>:-fsanitize=address,undefined>
)
endif()
endif()
# ---- Library ----------------------------------------------------------------
set(SKIRESORT_SOURCES
src/bistro.c
src/bus.c
src/bus_stop.c
src/car.c
src/car_park.c
src/clock.c
src/gondola.c
src/hotel.c
src/input.c
src/lift.c
src/lift_queue.c
src/list.c
src/node.c
src/person.c
src/probability.c
src/queue.c
src/resort.c
src/simulation.c
src/slope.c
src/station.c
)
add_library(skiresort ${SKIRESORT_SOURCES})
target_include_directories(skiresort
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_definitions(skiresort
PUBLIC
_POSIX_C_SOURCE=199309L # for usage of nanosleep() (clock.h)
)
target_link_libraries(skiresort
PUBLIC
m
PRIVATE
skiresort_warnings
skiresort_sanitizers
)
# ---- Executable -------------------------------------------------------------
add_executable(skiresort_app
app/main.c
)
target_link_libraries(skiresort_app
PRIVATE
skiresort
skiresort_warnings
skiresort_sanitizers
)
# ---- Tests ------------------------------------------------------------------
include(CTest)
if(BUILD_TESTING AND SKIRESORT_BUILD_TESTS)
add_subdirectory(tests)
endif()