This repository was archived by the owner on Sep 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
75 lines (63 loc) · 3.13 KB
/
CMakeLists.txt
File metadata and controls
75 lines (63 loc) · 3.13 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
cmake_minimum_required(VERSION 3.13)
project(calc)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CONFIGURATION_TYPES "ASAN;MSAN;USAN" CACHE STRING "" FORCE)
if (CMAKE_BUILD_TYPE MATCHES ASAN)
set(COMPILE_OPTS -Wall -Wextra -Werror -pedantic -pedantic-errors
-O1 -fsanitize=address -fno-omit-frame-pointer
-fno-inline -fno-sanitize-recover=all)
set(LINK_OPTS -fsanitize=address)
endif()
if (CMAKE_BUILD_TYPE MATCHES MSAN)
set(COMPILE_OPTS -Wall -Wextra -Werror -pedantic -pedantic-errors
-O1 -fsanitize=memory
-fno-omit-frame-pointer -fsanitize-memory-track-origins=2
-fno-sanitize-recover=all)
set(LINK_OPTS -fsanitize=memory -fsanitize-memory-track-origins=2)
endif()
if (CMAKE_BUILD_TYPE MATCHES USAN)
set(COMPILE_OPTS -Wall -Wextra -Werror -pedantic -pedantic-errors
-O1 -fsanitize=undefined,float-cast-overflow,float-divide-by-zero
-fno-omit-frame-pointer -fno-sanitize-recover=all
-fsanitize-recover=alignment)
set(LINK_OPTS -fsanitize=undefined,float-cast-overflow,float-divide-by-zero)
endif()
if (${USE_CLANG_TIDY})
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
endif()
function(setup_warnings TARGET)
target_compile_options(${TARGET} PUBLIC -Wno-unknown-warning-option)
target_compile_options(${TARGET} PUBLIC -Wold-style-cast)
target_compile_options(${TARGET} PUBLIC -Wnull-dereference)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${TARGET} PUBLIC -Wduplicated-branches)
target_compile_options(${TARGET} PUBLIC -Wduplicated-cond)
target_compile_options(${TARGET} PUBLIC -Wsuggest-override)
target_compile_options(${TARGET} PUBLIC -Wuseless-cast)
target_compile_options(${TARGET} PUBLIC -Wreturn-local-addr)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${TARGET} PUBLIC -Wreturn-stack-address)
target_compile_options(${TARGET} PUBLIC -Wloop-analysis)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(${TARGET} PUBLIC -Wreturn-stack-address)
target_compile_options(${TARGET} PUBLIC -Wloop-analysis)
endif()
endfunction(setup_warnings)
add_library(${PROJECT_NAME}_lib include/calc.hpp src/calc.cpp)
target_include_directories(${PROJECT_NAME}_lib PUBLIC include)
target_compile_options(${PROJECT_NAME}_lib PUBLIC ${COMPILE_OPTS})
target_link_options(${PROJECT_NAME}_lib PUBLIC ${LINK_OPTS})
setup_warnings(${PROJECT_NAME}_lib)
add_executable(${PROJECT_NAME} src/main.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTS})
target_link_options(${PROJECT_NAME} PRIVATE ${LINK_OPTS})
setup_warnings(${PROJECT_NAME})
# linking Main against the library
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib)
option(COMMON_TESTS "Enable common tests" ON)
option(FAC_LOG_VARIANT "Enable tests for fac-log" OFF)
option(FOLD_VARIANT "Enable tests for fold" OFF)
option(NUMBER_SYSTEM_VARIANT "Enable tests for number-system" ON)
option(TRIG_VARIANT "Enable tests for trig" OFF)
add_subdirectory(tests)