mirror of
https://github.com/google/benchmark.git
synced 2024-12-27 13:00:36 +08:00
Improve the CMake C++ flag checker
This checks the flag on the compiler AND linker which allows it to work with flags such as -flto and -fsanitize=address
This commit is contained in:
parent
d51ba32791
commit
fc883f6742
@ -20,18 +20,17 @@ set(__add_cxx_compiler_flag INCLUDED)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
function(add_cxx_compiler_flag FLAG)
|
||||
if(ARGV1)
|
||||
set(VARIANT ${ARGV1})
|
||||
string(TOLOWER ${VARIANT} VARIANT)
|
||||
set(VARIANT " ${VARIANT}")
|
||||
endif()
|
||||
string(TOUPPER "HAVE_${FLAG}" SANITIZED_FLAG)
|
||||
string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG)
|
||||
string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
|
||||
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
||||
string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
||||
check_cxx_compiler_flag(${FLAG} ${SANITIZED_FLAG})
|
||||
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
|
||||
check_cxx_compiler_flag("" ${SANITIZED_FLAG})
|
||||
if(${SANITIZED_FLAG})
|
||||
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
|
||||
string(TOUPPER "${VARIANT}" VARIANT)
|
||||
set(VARIANT ${ARGV1})
|
||||
if(ARGV1)
|
||||
string(TOUPPER "_${VARIANT}" VARIANT)
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
Loading…
Reference in New Issue
Block a user