compile_flag: also pass parameters to the linker during the test
This commit is contained in:
parent
1c5ded53b3
commit
9198bae72d
@ -1,5 +1,13 @@
|
|||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXSourceCompiles)
|
||||||
|
|
||||||
|
# Test if a compiler flag is supported.
|
||||||
|
#
|
||||||
|
# Note: We _cannot_ use check_cxx_compiler_flag because it will not add the
|
||||||
|
# flag to the linker parameters and some compiler flags _must_ be passed to
|
||||||
|
# the linker but the test it performs fails to do so. eg, checking for
|
||||||
|
# -fsanitize=address is impossible with this macro.
|
||||||
|
#
|
||||||
|
# Instead, we roll out own. Yay cmake...
|
||||||
macro (append_compile_flag _flag)
|
macro (append_compile_flag _flag)
|
||||||
string (MAKE_C_IDENTIFIER ${_flag} _name)
|
string (MAKE_C_IDENTIFIER ${_flag} _name)
|
||||||
|
|
||||||
@ -14,14 +22,16 @@ macro (append_compile_flag _flag)
|
|||||||
string (REGEX MATCH "^-Wno-(.+)$" compile_flag_inverse ${_flag})
|
string (REGEX MATCH "^-Wno-(.+)$" compile_flag_inverse ${_flag})
|
||||||
|
|
||||||
if ("x" STREQUAL "x${compile_flag_inverse}")
|
if ("x" STREQUAL "x${compile_flag_inverse}")
|
||||||
check_cxx_compiler_flag (${_flag} compile_flag${_name})
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
|
||||||
else ()
|
else ()
|
||||||
string (REGEX REPLACE "-Wno-" "" _inverse_flag ${_flag})
|
string (REGEX REPLACE "-Wno-" "" _inverse_flag ${_flag})
|
||||||
check_cxx_compiler_flag ("-W${_inverse_flag}" compile_flag${_name})
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS} -W${_inverse_flag}")
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (compile_flag${_name})
|
check_cxx_source_compiles("int main(int,char**) { return 0; }" compile_flag_${_name})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (compile_flag_${_name})
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
|
||||||
endif()
|
endif()
|
||||||
endmacro(append_compile_flag)
|
endmacro(append_compile_flag)
|
||||||
|
Loading…
Reference in New Issue
Block a user