-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
193 lines (160 loc) · 4.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
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
cmake_minimum_required(VERSION 3.20)
project(quadratics
VERSION 0.1.0
DESCRIPTION "Solver for quadratic equations with integer coefficients"
LANGUAGES CXX
)
# Add these to cmake to enable functionality
option(ENABLE_COVERAGE "Enable coverage reporting (gcc/clang)" FALSE)
option(ENABLE_ASAN "Enable address sanitizer" FALSE)
option(ENABLE_TSAN "Enable thread sanitizer" FALSE)
option(ENABLE_TESTING "Enable building tests" FALSE)
option(ENABLE_CLANG_TIDY "Enable testing with clang-tidy" FALSE)
option(ENABLE_CPPCHECK "Enable testing with cppcheck" FALSE)
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (gcc/clang)" TRUE)
# Interface for options
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_17)
if(ENABLE_COVERAGE)
target_compile_options(project_options INTERFACE --coverage -O0 -g)
target_link_libraries(project_options INTERFACE --coverage)
endif()
if(ENABLE_ASAN)
target_compile_options(project_options INTERFACE -fsanitize=address)
target_link_libraries(project_options INTERFACE -fsanitize=address)
endif()
if(ENABLE_TSAN)
target_compile_options(project_options INTERFACE -fsanitize=thread)
target_link_libraries(project_options INTERFACE -fsanitize=thread)
endif()
# Interface for warnings
if (UNIX)
add_library(project_warnings INTERFACE)
target_compile_options(project_warnings INTERFACE
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wpedantic
-Wconversion
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
)
endif()
if (MSVC)
add_library(project_warnings INTERFACE)
target_compile_options(project_warnings INTERFACE
-W4
)
endif()
# GCC specific warnings
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(project_warnings INTERFACE
-Wmisleading-indentation
-Wduplicated-cond
-Wlogical-op
-Wuseless-cast
)
endif()
# CLI coloring for compiler
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options (project_options INTERFACE -fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options (project_options INTERFACE -fcolor-diagnostics)
endif ()
endif ()
# Static analysis focused on bugs
if(ENABLE_CPPCHECK)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK
${CPPCHECK}
--suppress=missingIncludeSystem
--inconclusive)
else()
message(SEND_ERROR "cppcheck requested but executable not found")
endif()
endif()
# Static analysis focused on best practices
if(ENABLE_CLANG_TIDY)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY})
else()
message(SEND_ERROR "clang-tidy requested but executable not found")
endif()
endif()
# Main library
add_library(quadratics
src/quadratic.cpp
src/equationqueue.cpp
src/parser.cpp
src/solver.cpp
src/runtime.cpp
)
target_include_directories(quadratics PRIVATE src)
target_link_libraries(quadratics
PRIVATE
project_options
project_warnings
)
# CLI executable
add_executable(quadratics_exe
src/main.cpp
)
set_property(TARGET quadratics_exe PROPERTY OUTPUT_NAME quadratics)
target_include_directories(quadratics_exe PRIVATE src)
target_link_libraries(quadratics_exe
PRIVATE
project_options
project_warnings
quadratics
)
# Tests
if(ENABLE_TESTING)
enable_testing()
find_package(doctest REQUIRED)
include(CTest)
include(doctest)
add_executable(quadratics_test
src/main.t.cpp
src/quadratic.t.cpp
)
target_include_directories(quadratics_test PRIVATE src)
target_link_libraries(quadratics_test PRIVATE
doctest::doctest
project_options
project_warnings
quadratics
)
doctest_discover_tests(quadratics_test)
endif()
# Benchmark
add_executable(quadratics_bench
tools/benchmark/main.cpp
)
target_include_directories(quadratics_bench PRIVATE src tools/benchmark)
target_link_libraries(quadratics_bench
PRIVATE
project_options
project_warnings
quadratics
)
# Sample data generation tool
add_executable(quadratics_gen
tools/gendata/main.cpp
)
target_include_directories(quadratics_gen PRIVATE src tools/gendata)
target_link_libraries(quadratics_gen
PRIVATE
project_options
project_warnings
quadratics
)