cmake: Extend cc-option support to C++
The target_cc_option[_fallback]() CMake extentions are now C++ aware. This means that they will now test options with both C and C++ compiler and include flags appropriately. This fixes a warning that was issued when -Wno-pointer-sign was used with .cpp files. cc1plus: warning: command line option ‘-Wno-pointer-sign’ is valid for C/ObjC but not for C++ NB: This patch is designed to only affect CONFIG_CPLUSPLUS builds in case there are any adverse affects with using generator expressions. Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
parent
935e95be41
commit
f71c3fa665
1 changed files with 28 additions and 10 deletions
|
@ -644,6 +644,8 @@ endfunction()
|
||||||
#
|
#
|
||||||
# lang must be C or CXX
|
# lang must be C or CXX
|
||||||
#
|
#
|
||||||
|
# TODO: Support ASM
|
||||||
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
#
|
#
|
||||||
# check_compiler_flag(C "-Wall" my_check)
|
# check_compiler_flag(C "-Wall" my_check)
|
||||||
|
@ -667,20 +669,36 @@ function(check_compiler_flag lang option ok)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(target_cc_option target scope option)
|
function(target_cc_option target scope option)
|
||||||
string(MAKE_C_IDENTIFIER check${option} check)
|
target_cc_option_fallback(${target} ${scope} ${option} "")
|
||||||
check_c_compiler_flag(${option} ${check})
|
|
||||||
target_compile_option_ifdef(${check} ${target} ${scope} ${option})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# Support an optional second option for when the first option is
|
# Support an optional second option for when the first option is not
|
||||||
# not supported.
|
# supported.
|
||||||
function(target_cc_option_fallback target scope option1 option2)
|
function(target_cc_option_fallback target scope option1 option2)
|
||||||
string(MAKE_C_IDENTIFIER check${option1} check)
|
if(CONFIG_CPLUSPLUS)
|
||||||
check_c_compiler_flag(${option1} ${check})
|
foreach(lang C CXX)
|
||||||
if(${check})
|
# For now, we assume that all flags that apply to C/CXX also
|
||||||
target_compile_options(${target} ${scope} ${option1})
|
# apply to ASM.
|
||||||
|
check_compiler_flag(${lang} ${option1} check)
|
||||||
|
if(${check})
|
||||||
|
target_compile_options(${target} ${scope}
|
||||||
|
$<$<COMPILE_LANGUAGE:${lang}>:${option1}>
|
||||||
|
$<$<COMPILE_LANGUAGE:ASM>:${option1}>
|
||||||
|
)
|
||||||
|
elseif(option2)
|
||||||
|
target_compile_options(${target} ${scope}
|
||||||
|
$<$<COMPILE_LANGUAGE:${lang}>:${option2}>
|
||||||
|
$<$<COMPILE_LANGUAGE:ASM>:${option2}>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
else()
|
else()
|
||||||
target_compile_options(${target} ${scope} ${option2})
|
check_compiler_flag(C ${option1} check)
|
||||||
|
if(${check})
|
||||||
|
target_compile_options(${target} ${scope} ${option1})
|
||||||
|
elseif(option2)
|
||||||
|
target_compile_options(${target} ${scope} ${option2})
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue