Skip to content

Commit f063136

Browse files
lukaszstolarczukPatKamin
authored andcommitted
Fix sanitizers flag checks
Co-authored-by: [email protected]
1 parent 3285a5b commit f063136

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

cmake/helpers.cmake

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,40 @@ macro(add_sanitizer_flag flag)
133133
set(check_name "HAS_MSAN")
134134
endif()
135135

136-
# Check C and CXX compilers for given sanitizer flag.
136+
# Check C and CXX compilers for a given sanitizer flag.
137137
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()
138141
if (CMAKE_CXX_COMPILE_FEATURES)
139142
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()
140146
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}")
144149

145150
# Check C and CXX compilers for sanitizer arguments.
146-
if (${SANITIZER_ARGS})
151+
if (SANITIZER_ARGS)
147152
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()
148156
if (CMAKE_CXX_COMPILE_FEATURES)
149157
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()
153161
endif()
154162

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}")
159164
endif()
160165

161-
add_compile_options("${SANITIZER_OPTION}")
162-
163166
# Clang/gcc needs the flag added to the linker. The Microsoft LINK linker doesn't recognize
164167
# sanitizer flags and will give a LNK4044 warning.
165168
if (NOT MSVC)
166-
add_link_options("${SANITIZER_OPTION}")
169+
add_link_options("${SANITIZER_FLAG}")
167170
endif()
168171

169172
set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})

0 commit comments

Comments
 (0)