-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathSpecialtyBuilds.cmake
164 lines (145 loc) · 5.28 KB
/
SpecialtyBuilds.cmake
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
if (CMAKE_BUILD_TYPE MATCHES "RelAssert")
set(REALM_ENABLE_ASSERTIONS ON CACHE BOOL "Build with assertions")
endif()
if (CMAKE_BUILD_TYPE MATCHES "RelASAN")
set(REALM_ASAN ON CACHE BOOL "Build with address sanitizer")
endif()
if (CMAKE_BUILD_TYPE MATCHES "RelTSAN")
set(REALM_TSAN ON CACHE BOOL "Build with address sanitizer")
endif()
if (CMAKE_BUILD_TYPE MATCHES "RelMSAN")
set(REALM_MSAN ON CACHE BOOL "Build with memory sanitizer")
endif()
if (CMAKE_BUILD_TYPE MATCHES "RelUSAN")
set(REALM_USAN ON CACHE BOOL "Build with undefined sanitizer")
endif()
# -------------
# Coverage
# -------------
option(REALM_COVERAGE "Compile with coverage support." OFF)
if(REALM_COVERAGE)
if(MSVC)
message(FATAL_ERROR
"Code coverage is not yet supported on Visual Studio builds")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage -fprofile-arcs -ftest-coverage -fno-elide-constructors")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-inline -fno-inline-small-functions -fno-default-inline")
endif()
endif()
endif()
option(REALM_LLVM_COVERAGE "Compile with llvm's code coverage support." OFF)
if (REALM_LLVM_COVERAGE)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINK_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
else()
message(FATAL_ERROR "Code coverage is only supported with clang")
endif()
endif()
# -------------
# AFL
# -------------
option(REALM_AFL "Compile for fuzz testing." OFF)
if(REALM_AFL)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(FUZZ_COMPILER_NAME "afl-clang++")
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
set(FUZZ_COMPILER_NAME "afl-g++")
else()
message(FATAL_ERROR
"Running AFL with your compiler (${CMAKE_CXX_COMPILER_ID}) is not supported")
endif()
find_program(AFL ${FUZZ_COMPILER_NAME})
if(NOT AFL)
message(FATAL_ERROR "AFL not found!")
endif()
set(CMAKE_CXX_COMPILER "${AFL}")
endif()
# -------------
# libfuzzer
# -------------
option(REALM_LIBFUZZER "Compile with llvm libfuzzer" OFF)
if(REALM_LIBFUZZER)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# todo: add the undefined sanitizer here after blacklisting false positives
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=fuzzer,address")
else()
message(FATAL_ERROR
"Compiling for libfuzzer is only supported with clang")
endif()
endif()
# -------------
# Address Sanitizer
# -------------
option(REALM_ASAN "Compile with address sanitizer support" OFF)
if(REALM_ASAN)
if (MSVC)
set(REALM_SANITIZER_FLAGS /fsanitize=address)
set(REALM_SANITIZER_LINK_FLAGS /INCREMENTAL:NO)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "RelASAN")
list(APPEND REALM_SANITIZER_FLAGS /Ox /Zi)
list(APPEND REALM_SANITIZER_LINK_FLAGS /DEBUG)
elseif (NOT "${CMAKE_BUILD_TYPE}" MATCHES ".*Deb.*")
# disable warning for better stacktrace for asan
# pdbs can be activated with RelWithDebInfo or RelASAN
list(APPEND REALM_SANITIZER_FLAGS /wd5072)
endif()
else()
set(REALM_SANITIZER_FLAGS -fsanitize=address -fno-sanitize-recover=all -fsanitize-address-use-after-scope -fno-omit-frame-pointer)
endif()
endif()
# -------------
# Thread Sanitizer
# -------------
option(REALM_TSAN "Compile with thread sanitizer support" OFF)
if(REALM_TSAN)
if(MSVC)
message(FATAL_ERROR
"The Thread Sanitizer is not yet supported on Visual Studio builds")
else()
set(REALM_SANITIZER_FLAGS -fsanitize=thread -fno-sanitize-recover=all -fno-omit-frame-pointer)
endif()
endif()
# -------------
# Memory Sanitizer
# -------------
option(REALM_MSAN "Compile with memory sanitizer support" OFF)
if(REALM_MSAN)
if(MSVC)
message(FATAL_ERROR
"The Memory Sanitizer is not yet supported on Visual Studio builds")
else()
set(REALM_SANITIZER_FLAGS -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
endif()
endif()
# -------------
# Undefined Sanitizer
# -------------
option(REALM_USAN "Compile with undefined sanitizer support" OFF)
if(REALM_USAN)
if(MSVC)
message(FATAL_ERROR
"The Undefined Sanitizer is not yet supported on Visual Studio builds")
else()
set(REALM_SANITIZER_FLAGS -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer)
endif()
endif()
if (REALM_SANITIZER_FLAGS)
if (NOT MSVC)
if ("${CMAKE_BUILD_TYPE}" MATCHES "Rel[ATMU]SAN")
list(APPEND REALM_SANITIZER_FLAGS -O1 -g)
endif()
set(REALM_SANITIZER_LINK_FLAGS ${REALM_SANITIZER_FLAGS})
if (CMAKE_COMPILER_IS_GNUXX) # activated for clang automatically according to docs
list(APPEND REALM_SANITIZER_LINK_FLAGS -pie)
endif()
endif()
add_compile_options(${REALM_SANITIZER_FLAGS})
if (MSVC)
add_compile_definitions(_DISABLE_STRING_ANNOTATION _DISABLE_VECTOR_ANNOTATION)
endif()
if (REALM_SANITIZER_LINK_FLAGS)
add_link_options(${REALM_SANITIZER_LINK_FLAGS})
endif()
endif()