3
0
mirror of https://github.com/triqs/dft_tools synced 2025-01-12 05:58:18 +01:00

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
This commit is contained in:
Olivier Parcollet 2013-12-10 11:53:58 +01:00
parent 02b6cedd14
commit 0b166461ef
2 changed files with 19 additions and 11 deletions

View File

@ -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)

View File

@ -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