diff --git a/kde-modules/KDECompilerSettings.cmake b/kde-modules/KDECompilerSettings.cmake --- a/kde-modules/KDECompilerSettings.cmake +++ b/kde-modules/KDECompilerSettings.cmake @@ -189,32 +189,34 @@ # Pick sensible versions of the C and C++ standards. # Note that MSVC does not have equivalent flags; the features are either # supported or they are not. -if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") - # We use the C89 standard because that is what is common to all our - # compilers (in particular, MSVC 2010 does not support C99) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") -endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +if (NOT MSVC) + if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + # We use the C89 standard because that is what is common to all our + # compilers (in particular, MSVC 2010 does not support C99) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=iso9899:1990") + endif() + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + endif() endif() # Do not merge uninitialized global variables. # This is mostly a "principle of least surprise" thing, but also # has performance benefits. # See https://www.ibm.com/developerworks/community/blogs/zTPF/entry/benefits_of_the_fnocommon_compile_option_peter_lemieszewski?lang=en # Note that this only applies to C code; C++ already behaves like this. if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT MSVC) OR (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-common") endif() # Do not treat the operator name keywords and, bitand, bitor, compl, not, or and xor as synonyms as keywords. # They're not supported under Visual Studio out of the box thus using them limits the portability of code if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT MSVC) OR (CMAKE_C_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names") endif() @@ -263,7 +265,7 @@ # Turn off exceptions by default if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") @@ -285,7 +287,7 @@ endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(${VAR} "${${VAR}} -fexceptions") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT MSVC) set(${VAR} "${${VAR}} -fexceptions") endif() string(STRIP "${${VAR}}" ${VAR}) @@ -313,8 +315,13 @@ else() target_compile_options(${target} ${mode} "$<$:-fexceptions>") endif() - target_compile_options(${target} ${mode} - "$<$,$>:-fexceptions>") + if(MSVC) + target_compile_options(${target} ${mode} + "$<$:-EHsc>") + else() + target_compile_options(${target} ${mode} + "$<$,$>:-fexceptions>") + endif() endfunction() function(KDE_ENABLE_EXCEPTIONS) @@ -341,7 +348,7 @@ ############################################################ if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE) OR - (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT (APPLE OR MSVC)) OR (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT WIN32)) # Linker warnings should be treated as errors set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings ${CMAKE_SHARED_LINKER_FLAGS}") @@ -468,7 +475,7 @@ if (CMAKE_GENERATOR STREQUAL "Ninja" AND ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR - (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))) + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5 AND NOT MSVC))) # Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support. # Rationale in https://github.com/ninja-build/ninja/issues/814 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") diff --git a/kde-modules/KDEFrameworkCompilerSettings.cmake b/kde-modules/KDEFrameworkCompilerSettings.cmake --- a/kde-modules/KDEFrameworkCompilerSettings.cmake +++ b/kde-modules/KDEFrameworkCompilerSettings.cmake @@ -66,7 +66,7 @@ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override" ) endif() -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT MSVC) # -Wgnu-zero-variadic-macro-arguments is triggered by every qCDebug() call and therefore results # in a lot of noise. This warning is only notifying us that clang is emulating the GCC behaviour # instead of the exact standard wording so we can safely ignore it