summaryrefslogtreecommitdiff
path: root/CMake
diff options
context:
space:
mode:
authorFlorent Castelli <florent.castelli@gmail.com>2017-02-20 04:18:49 +0100
committerFlorent Castelli <florent.castelli@gmail.com>2017-03-08 06:46:59 +0100
commit33ceb042b70ac035962569e57da894e50aaa3960 (patch)
treea1f75332f4dbdf7010cd6d26003cef9532f4753f /CMake
parent9572a5105d0bf809e942a107865bd96d7ded237f (diff)
cmake: Fix check_and_add_flag() with Visual Studio generators
Diffstat (limited to 'CMake')
-rw-r--r--CMake/CheckAndAddFlag.cmake14
1 files 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 "$<COMPILE_LANGUAGE:C>")
+ set(is_cxx "$<COMPILE_LANGUAGE: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("$<$<AND:$<COMPILE_LANGUAGE:C>,${genexp_config_test}>:${flag}>")
+ add_compile_options("$<$<AND:${is_c},${genexp_config_test}>:${flag}>")
endif()
check_cxx_compiler_flag(${flag} FLAG_CXX_${var})
if(FLAG_CXX_${var})
- add_compile_options("$<$<AND:$<COMPILE_LANGUAGE:CXX>,${genexp_config_test}>:${flag}>")
+ add_compile_options("$<$<AND:${is_cxx},${genexp_config_test}>:${flag}>")
endif()
endfunction()