From 33ceb042b70ac035962569e57da894e50aaa3960 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Mon, 20 Feb 2017 04:18:49 +0100 Subject: [PATCH] cmake: Fix check_and_add_flag() with Visual Studio generators --- CMake/CheckAndAddFlag.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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()