-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrict.cmake
More file actions
65 lines (59 loc) · 2.81 KB
/
Strict.cmake
File metadata and controls
65 lines (59 loc) · 2.81 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
# Build types for various sanitizer modes
set(CMAKE_CONFIGURATION_TYPES "ASAN;MSAN;USAN" CACHE STRING "" FORCE)
# General compile and link options
set(COMPILE_OPTS -O3 -Wall -Wextra -Werror -pedantic -pedantic-errors)
set(LINK_OPTS "")
# Sanitizers options
if (CMAKE_BUILD_TYPE MATCHES ASAN)
list(APPEND COMPILE_OPTS -O1 -fsanitize=address -fno-omit-frame-pointer
-fno-sanitize-recover=all)
list(APPEND LINK_OPTS -fsanitize=address)
endif()
if (CMAKE_BUILD_TYPE MATCHES MSAN)
list(APPEND COMPILE_OPTS -O1 -fsanitize=memory
-fno-omit-frame-pointer -fsanitize-memory-track-origins=2
-fno-sanitize-recover=all)
list(APPEND LINK_OPTS -fsanitize=memory
-fsanitize-memory-track-origins=2)
endif()
if (CMAKE_BUILD_TYPE MATCHES USAN)
list(APPEND COMPILE_OPTS -O1
-fsanitize=undefined,float-cast-overflow,float-divide-by-zero
-fno-omit-frame-pointer -fno-sanitize-recover=all
-fsanitize-recover=alignment)
list(APPEND LINK_OPTS
-fsanitize=undefined,float-cast-overflow,float-divide-by-zero)
endif()
# Configure clang-tidy
if (${USE_CLANG_TIDY})
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
endif()
function(setup_warnings TARGET)
# Warnings
target_compile_options(${TARGET} PUBLIC -Wno-error-unknown-warning-option) # just in case if some warnings are unavialable
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()
# ICA
if (EXISTS ${PATH_TO_ICA})
message(STATUS "path to ICA: ${PATH_TO_ICA}")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang -load")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang ${PATH_TO_ICA}")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang -add-plugin")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang ica-plugin")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang -plugin-arg-ica-plugin")
target_compile_options(${TARGET} PUBLIC "SHELL:-Xclang checks=all=err")
endif()
endfunction(setup_warnings)