| 1 |
message ("-- Configuring C++11") |
| 2 |
message ("-- System: ${CMAKE_SYSTEM_NAME}") |
| 3 |
|
| 4 |
include (CheckCXXCompilerFlag) |
| 5 |
|
| 6 |
# NOTE: Phase out -std=gnu++0x and --std=c++0x as soon as realistically possible. |
| 7 |
CHECK_CXX_COMPILER_FLAG("-std=c++11" _HAS_CXX11) |
| 8 |
CHECK_CXX_COMPILER_FLAG("-std=c++0x" _HAS_CXX0X) |
| 9 |
CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" _HAS_GNU0X) |
| 10 |
|
| 11 |
if (_HAS_CXX11) |
| 12 |
set (_CXX11_FLAGS "-std=c++11") |
| 13 |
elseif (_HAS_CXX0X) |
| 14 |
message (WARNING "Enabling -std=c++0x draft compile flag. Your compiler does not support the standard '-std=c++11' option. Consider upgrading.") |
| 15 |
set (_CXX11_FLAGS "-std=c++0x") |
| 16 |
elseif (_HAS_GNU0X) |
| 17 |
message (WARNING "Enabling -std=gnu++0x draft compile flag. Your compiler does not support the standard '-std=c++11' option. Consider upgrading.") |
| 18 |
set (_CXX11_FLAGS "-std=gnu++0x") |
| 19 |
else (_HAS_CXX11) |
| 20 |
message (FATAL_ERROR "C++11 support missing. Try upgrading your C++ compiler. If you have a good reason for using an outdated compiler, please let us know at [email protected].") |
| 21 |
endif (_HAS_CXX11) |
| 22 |
|
| 23 |
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 24 |
set (LINUX true) |
| 25 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 26 |
set (DARWIN true) |
| 27 |
set (_CXX11_FLAGS "${_CXX11_FLAGS} -stdlib=libc++") |
| 28 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD") |
| 29 |
set (KFREEBSD true) |
| 30 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 31 |
set (FREEBSD true) |
| 32 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") |
| 33 |
set (OPENBSD true) |
| 34 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") |
| 35 |
set (NETBSD true) |
| 36 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 37 |
set (SOLARIS true) |
| 38 |
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "GNU") |
| 39 |
set (GNUHURD true) |
| 40 |
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN") |
| 41 |
set (CYGWIN true) |
| 42 |
# NOTE: Not setting -std=gnu++0x leads to compile errors even with |
| 43 |
# GCC 4.8.3, and debugging those leads to insanity. Adding this |
| 44 |
# workaround instead of fixing Cygwin. |
| 45 |
set (_CXX11_FLAGS "-std=gnu++0x") |
| 46 |
else (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 47 |
set (UNKNOWN true) |
| 48 |
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 49 |
|
| 50 |
set (CMAKE_CXX_FLAGS "${_CXX11_FLAGS} ${CMAKE_CXX_FLAGS}") |
| 51 |
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}") |