[Feature Request] CheckCXXXCompilerFlag equivalent in generator expression
I think it would be great to have an equivalent to CheckCXXXCompilerFlag in a generator expression.
Example:
-W-enum-constexpr-conversion
is supported on clang 16+. AppleClang version numbering does not follow the upstream LLVM clang version. In order to properly silence the warning without adding another warning for unknown warning option
, we need to add this only for versions that support this flag.
cmake_policy(PUSH)
cmake_policy(SET CMP0025 NEW) # This is needed to have <CXX_COMPILER_ID> differentiate between Clang and AppleClang
set(clang_16_or_greater "$<AND:$<CXX_COMPILER_ID:Clang>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,16>>")
set(apple_clang_15_or_greater "$<AND:$<CXX_COMPILER_ID:AppleClang>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,15>>")
set(has_enum_constexpr_option "$<OR:${clang_16_or_greater},${apple_clang_15_or_greater}>")
target_compile_options(MyLib INTERFACE
$<${has_enum_constexpr_option}:-Wno-enum-constexpr-conversion>
cmake_policy(POP)
Alternatively,
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wenum-constexpr-conversion has_enum_constexpr_option)
target_compile_options(MyLib INTERFACE
$<${has_enum_constexpr_option}:-Wno-enum-constexpr-conversion>
Ideally one could do something like this directly:
target_compile_options(MyLib INTERFACE $<CXX_COMPILER_FLAG_SUPPORTED:-Wno-enum-constexpr-conversion>)
Edited by Julien Marrec