Use a unique variable name when checking if a flag is valid (#3532)

This commit is contained in:
Paul Fultz II 2021-10-30 02:07:06 -05:00 committed by GitHub
parent e998cd13ca
commit 1f5c3670bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -1,15 +1,17 @@
include(CheckCXXCompilerFlag)
function(add_compile_options_safe FLAG)
check_cxx_compiler_flag(${FLAG} _has_flag)
if (_has_flag)
string(MAKE_C_IDENTIFIER "HAS_CXX_FLAG${FLAG}" mangled_flag)
check_cxx_compiler_flag(${FLAG} ${mangled_flag})
if (${mangled_flag})
add_compile_options(${FLAG})
endif()
endfunction()
function(target_compile_options_safe TARGET FLAG)
check_cxx_compiler_flag(${FLAG} _has_flag)
if (_has_flag)
string(MAKE_C_IDENTIFIER "HAS_CXX_FLAG${FLAG}" mangled_flag)
check_cxx_compiler_flag(${FLAG} ${mangled_flag})
if (${mangled_flag})
target_compile_options(${TARGET} PRIVATE ${FLAG})
endif()
endfunction()