more right way to check if compiler support c++11

This commit is contained in:
Evgeniy A. Dushistov
2016-06-02 14:17:02 +03:00
parent d58e6caa25
commit 25c3b6047e
2 changed files with 45 additions and 8 deletions

35
cmake/compiler.cmake Normal file
View File

@@ -0,0 +1,35 @@
function(append value)
foreach(variable ${ARGN})
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
endforeach(variable)
endfunction()
include(CheckCXXCompilerFlag)
if (NOT DEFINED SDCV_COMPILER_IS_GCC_COMPATIBLE)
if (CMAKE_COMPILER_IS_GNUCXX)
set(SDCV_COMPILER_IS_GCC_COMPATIBLE ON)
elseif (MSVC)
set(SDCV_COMPILER_IS_GCC_COMPATIBLE OFF)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set (SDCV_COMPILER_IS_GCC_COMPATIBLE ON)
endif()
endif()
if (MSVC AND (MSVC_VERSION LESS 1900))
message(FATAL_ERROR "MSVC version ${MSVC_VERSION} have no full c++11 support")
elseif (MSVC)
add_definitions(-DNOMINMAX)
elseif (NOT MSVC)
check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
if (CXX_SUPPORTS_CXX11)
append("-std=c++11" CMAKE_CXX_FLAGS)
else ()
message(FATAL_ERROR "sdcv requires C++11 support but the '-std=c++11' flag isn't supported.")
endif()
endif ()
if (SDCV_COMPILER_IS_GCC_COMPATIBLE)
append("-Wall" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_C_FLAGS)
append("-Wall" "-pedantic" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_CXX_FLAGS)
endif ()