| 1 |
# - Finds if the compiler has C++11 support |
| 2 |
# This module can be used to detect compiler flags for using C++11, and checks |
| 3 |
# a small subset of the language. |
| 4 |
# |
| 5 |
# The following variables are set: |
| 6 |
# CXX11_FLAGS - flags to add to the CXX compiler for C++11 support |
| 7 |
# CXX11_FOUND - true if the compiler supports C++11 |
| 8 |
# |
| 9 |
# TODO: When compilers starts implementing the whole C++11, check the full set |
| 10 |
|
| 11 |
include(CheckCXXSourceCompiles) |
| 12 |
include(FindPackageHandleStandardArgs) |
| 13 |
|
| 14 |
set(CXX11_FLAG_CANDIDATES |
| 15 |
# Eveerything that automatically accepts C++11 |
| 16 |
" " |
| 17 |
# gcc, clang and Intel Linux |
| 18 |
"-std=c++11" |
| 19 |
# Intel windows |
| 20 |
"/Qstd=c++0x" |
| 21 |
"/Qstd=c++11" |
| 22 |
) |
| 23 |
|
| 24 |
set(CXX11_TEST_SOURCE |
| 25 |
" |
| 26 |
#if defined(_MSC_VER) |
| 27 |
#if _MSC_VER < 1800 |
| 28 |
#error \"Can not compile with C++11\" |
| 29 |
#endif |
| 30 |
#elif __cplusplus < 201103L |
| 31 |
#error \"Can not compile with C++11\" |
| 32 |
#endif |
| 33 |
|
| 34 |
int main() |
| 35 |
{} |
| 36 |
") |
| 37 |
|
| 38 |
foreach(FLAG ${CXX11_FLAG_CANDIDATES}) |
| 39 |
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") |
| 40 |
set(CMAKE_REQUIRED_FLAGS "${FLAG}") |
| 41 |
unset(CXX11_FLAG_DETECTED CACHE) |
| 42 |
message(STATUS "Try C++11 flag = [${FLAG}]") |
| 43 |
check_cxx_source_compiles("${CXX11_TEST_SOURCE}" CXX11_FLAG_DETECTED) |
| 44 |
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") |
| 45 |
if(CXX11_FLAG_DETECTED) |
| 46 |
set(CXX11_FLAGS_INTERNAL "${FLAG}") |
| 47 |
break() |
| 48 |
endif(CXX11_FLAG_DETECTED) |
| 49 |
endforeach(FLAG ${CXX11_FLAG_CANDIDATES}) |
| 50 |
|
| 51 |
set(CXX11_FLAGS "${CXX11_FLAGS_INTERNAL}") |
| 52 |
|
| 53 |
find_package_handle_standard_args(CXX11 DEFAULT_MSG CXX11_FLAGS) |
| 54 |
mark_as_advanced(CXX11_FLAGS) |