How it works
The check_<lang>_compiler_flag functions are simply wrappers around the check_<lang>_source_compiles function, which we discussed in the previous recipe. These wrappers provide a shortcut for the common use case where it is not important to check whether a specific code snippet compiles, but whether the compiler understands a set of flags.
Compiler flags for sanitizers are a special case, in that they also need to be passed on to the linker. To achieve this with the check_<lang>_compiler_flag functions, we need to set the CMAKE_REQUIRED_FLAGS variable prior to the call. The flags passed as the first argument would otherwise only be used in the call to the compiler, resulting in a false negative.
One more point to notice in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access