mirror of
https://github.com/google/benchmark.git
synced 2024-12-28 21:40:15 +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)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
function(add_cxx_compiler_flag FLAG)
|
function(add_cxx_compiler_flag FLAG)
|
||||||
if(ARGV1)
|
string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG)
|
||||||
set(VARIANT ${ARGV1})
|
string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
|
||||||
string(TOLOWER ${VARIANT} VARIANT)
|
|
||||||
set(VARIANT " ${VARIANT}")
|
|
||||||
endif()
|
|
||||||
string(TOUPPER "HAVE_${FLAG}" SANITIZED_FLAG)
|
|
||||||
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
||||||
string(REGEX REPLACE "_+" "_" 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})
|
if(${SANITIZED_FLAG})
|
||||||
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
|
set(VARIANT ${ARGV1})
|
||||||
string(TOUPPER "${VARIANT}" VARIANT)
|
if(ARGV1)
|
||||||
|
string(TOUPPER "_${VARIANT}" VARIANT)
|
||||||
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
|
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
Loading…
Reference in New Issue
Block a user