diff --git a/CMake/CheckAndAddFlag.cmake b/CMake/CheckAndAddFlag.cmake index 9494664e0a..edd0e8cc7e 100644 --- a/CMake/CheckAndAddFlag.cmake +++ b/CMake/CheckAndAddFlag.cmake @@ -27,13 +27,23 @@ function(check_and_add_flag var flag) message(FATAL_ERROR "check_and_add_flag called with incorrect arguments: ${ARGN}") endif() + set(is_c "$") + set(is_cxx "$") + + # The Visual Studio generators don't support COMPILE_LANGUAGE + # So we fail all the C flags and only actually test CXX ones + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(is_c "0") + set(is_cxx "1") + endif() + check_c_compiler_flag(${flag} FLAG_C_${var}) if(FLAG_C_${var}) - add_compile_options("$<$,${genexp_config_test}>:${flag}>") + add_compile_options("$<$:${flag}>") endif() check_cxx_compiler_flag(${flag} FLAG_CXX_${var}) if(FLAG_CXX_${var}) - add_compile_options("$<$,${genexp_config_test}>:${flag}>") + add_compile_options("$<$:${flag}>") endif() endfunction()