@@ -133,37 +133,40 @@ macro(add_sanitizer_flag flag)
133
133
set (check_name "HAS_MSAN" )
134
134
endif ()
135
135
136
- # Check C and CXX compilers for given sanitizer flag.
136
+ # Check C and CXX compilers for a given sanitizer flag.
137
137
check_c_compiler_flag ("${SANITIZER_FLAG} " "C_${check_name} " )
138
+ if (NOT C_${check_name} )
139
+ message (FATAL_ERROR "sanitizer '${flag} ' is not supported by the C compiler)" )
140
+ endif ()
138
141
if (CMAKE_CXX_COMPILE_FEATURES )
139
142
check_cxx_compiler_flag ("${SANITIZER_FLAG} " "CXX_${check_name} " )
143
+ if (NOT CXX_${check_name} )
144
+ message (FATAL_ERROR "sanitizer '${flag} ' is not supported by the CXX compiler)" )
145
+ endif ()
140
146
endif ()
141
- if (NOT ${C_${check_name}} OR NOT ${CXX_${check_name}} )
142
- message (FATAL_ERROR "${flag} sanitizer is not supported (either by C or CXX compiler)" )
143
- endif ()
147
+
148
+ add_compile_options ("${SANITIZER_FLAG} " )
144
149
145
150
# Check C and CXX compilers for sanitizer arguments.
146
- if (${ SANITIZER_ARGS} )
151
+ if (SANITIZER_ARGS )
147
152
check_c_compiler_flag ("${SANITIZER_ARGS} " "C_HAS_SAN_ARGS" )
153
+ if (NOT C_HAS_SAN_ARGS )
154
+ message (FATAL_ERROR "sanitizer argument '${SANITIZER_ARGS} ' is not supported by the C compiler)" )
155
+ endif ()
148
156
if (CMAKE_CXX_COMPILE_FEATURES )
149
157
check_cxx_compiler_flag ("${SANITIZER_ARGS} " "CXX_HAS_SAN_ARGS" )
150
- endif ( )
151
- if ( NOT ${C_HAS_SAN_ARGS} OR NOT ${CXX_HAS_SAN_ARGS} )
152
- message ( FATAL_ERROR "sanitizer argument ${SANITIZER_ARGS} is not supported (either by C or CXX compiler)" )
158
+ if ( NOT CXX_HAS_SAN_ARGS )
159
+ message ( FATAL_ERROR "sanitizer argument ' ${SANITIZER_ARGS} ' is not supported by the CXX compiler)" )
160
+ endif ( )
153
161
endif ()
154
162
155
- set (SANITIZER_OPTION "${SANITIZER_FLAG} ${SANITIZER_ARGS} " )
156
- else ()
157
- # No sanitizer argument was set. For now, that's the case for MSVC.
158
- set (SANITIZER_OPTION "${SANITIZER_FLAG} " )
163
+ add_compile_options ("${SANITIZER_ARGS} " )
159
164
endif ()
160
165
161
- add_compile_options ("${SANITIZER_OPTION} " )
162
-
163
166
# Clang/gcc needs the flag added to the linker. The Microsoft LINK linker doesn't recognize
164
167
# sanitizer flags and will give a LNK4044 warning.
165
168
if (NOT MSVC )
166
- add_link_options ("${SANITIZER_OPTION } " )
169
+ add_link_options ("${SANITIZER_FLAG } " )
167
170
endif ()
168
171
169
172
set (CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS} )
0 commit comments