From 0b166461ef491b13eaafe9245dcdbcebb8543397 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Tue, 10 Dec 2013 11:53:58 +0100 Subject: [PATCH] Add C++14 detection and flags - if compiler detected, compile in c++1y mode. - override with -Dcompiler_is_c14=ON if not detected. - compilation in c++1y on clang 3.4 ok on OS X --- CMakeLists.txt | 10 ++++++++-- cmake/FindCompilerCheck.cmake | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97c2c435..738f65cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,14 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # First check the C++ compiler find_package(CompilerCheck) -# Add C11 flag -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +# Add C11 or C14 flag depending on compiler detection +if (NOT compiler_is_c14) + MESSAGE(STATUS "Compiling in C++11 mode") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +else() + MESSAGE(STATUS "Compiling in C++14 mode") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y") +endif() # Include TRIQS cmake macros find_package(TriqsMacros) diff --git a/cmake/FindCompilerCheck.cmake b/cmake/FindCompilerCheck.cmake index 88ce7a30..9f2d6432 100644 --- a/cmake/FindCompilerCheck.cmake +++ b/cmake/FindCompilerCheck.cmake @@ -19,12 +19,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OUTPUT_VARIABLE _compiler_output RESULT_VARIABLE returncode OUTPUT_STRIP_TRAILING_WHITESPACE) set(compiler_version_min "4.8.1") set(compiler_name "gcc") - set(compiler_group 1) string(REGEX REPLACE ".*([2-5]\\.[0-9]\\.[0-9]).*" "\\1" compiler_version ${_compiler_output}) - #if(compiler_version VERSION_LESS "4.8.0" ) - # set(compiler_is_obsolete_gcc ON) - #endif() + if(NOT compiler_version VERSION_LESS "4.9.0") + set (compiler_is_c14 ON) + endif() elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -32,17 +31,21 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OUTPUT_VARIABLE _compiler_output RESULT_VARIABLE returncode OUTPUT_STRIP_TRAILING_WHITESPACE) set(CMAKE_COMPILER_IS_CLANG TRUE ) set(compiler_name "clang") - set(compiler_group 1) IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Apple which does not has the official clang version number ... string(REGEX REPLACE ".*LLVM ([2-5]\\.[0-9]).*" "\\1" compiler_version ${_compiler_output}) - #set( compiler_version_min "3.2") else() - string(REGEX REPLACE ".*([2-5]\\.[0-9]).*" "\\1" compiler_version ${_compiler_output}) - message(STATUS "Compiler version = ${compiler_version}") + string(REGEX REPLACE ".*([2-5]\\.[0-9]).*" "\\1" compiler_version ${_compiler_output}) endif() + #message(STATUS "Compiler --version output = ${_compiler_output}") + message(STATUS "Compiler version = ${compiler_version}") set( compiler_version_min "3.2") + # does not always work ... To be fixed when clang 3.4 officially released and on OS X. + if(NOT compiler_version VERSION_LESS "3.4") + set (compiler_is_c14 ON) + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion @@ -50,7 +53,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") set(CMAKE_COMPILER_IS_ICC TRUE ) set(compiler_version_min "14.0.0") set(compiler_name "Intel icc") - set(compiler_group 3) #string(REGEX REPLACE "[^0-9]*([0-9]+\\.[0-9]\\.[0-9]).*" "\\1" compiler_version ${_compiler_output}) # for intel 14.0 /test