enable_cxx11.cmake 1.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# enable the c++11 features. From cmake version 3.0 this is simply done by setting
# the cxx_standard variables. For older cmake version the compile-flags must be added manually.
if (ENABLE_CXX11)
  list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
  if (${CMAKE_VERSION} VERSION_GREATER "3.0")
      set(CMAKE_CXX_STANDARD 11)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
  else()
    if (CMAKE_COMPILER_IS_GNUCXX)
        set(GXX_MIN_VER "4.8")
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GXX_MIN_VER)
            message (FATAL_ERROR "For C++11-Features the G++ Compiler must be at least version $GXX_MIN_VER")
        endif ()
        list(APPEND COMPILEFLAGS "-std=gnu++11")
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        set(CLANG_MIN_VER "3.0")
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_MIN_VER)
            message (FATAL_ERROR "For C++11-Features the Clang Compiler must be at least version $CLANG_MIN_VER")
        endif ()
        list(APPEND COMPILEFLAGS "-std=c++11")
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
        set(INTEL_MIN_VER "12.1")
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS INTEL_MIN_VER)
            message (FATAL_ERROR "For C++11-Features the Intel C++ Compiler must be at least version $INTEL_MIN_VER")
        endif ()
        list(APPEND COMPILEFLAGS "-std=c++11")
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
        set(MSVC_MIN_VER "12.0")
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MIN_VER)
            message (FATAL_ERROR "For C++11-Features the MSVC C++ Compiler must be at least version $MSVC_MIN_VER")
        endif ()
    endif ()
  endif()
else ()
  list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
endif (ENABLE_CXX11)