enable_cxx11.cmake 2.35 KB
Newer Older
1
2
3
# 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)
4
5
6
7
    list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
    if (${CMAKE_VERSION} VERSION_GREATER "3.0")
        set(CMAKE_CXX_STANDARD 11)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
8
9
10
11
12
13
14
15
        if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # cmake can not detect intel compile features
          set(REQUIRED_CXX_FEATURES "cxx_alias_templates" "cxx_auto_type" "cxx_lambdas" "cxx_override" "cxx_range_for" "cxx_static_assert" "cxx_variadic_templates")

          add_library(test_compiler_features cmake/dummy.cc)
          foreach(feature ${REQUIRED_CXX_FEATURES})
              target_compile_features(test_compiler_features PUBLIC ${feature})
          endforeach(feature)
        endif ()
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    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 ()
40
        endif ()
41
    endif()
42
else ()
43
    list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
44
endif (ENABLE_CXX11)