Rex Dieter 8acc3d
From e1c69c277ea6005cc358434679b83fa1cb752756 Mon Sep 17 00:00:00 2001
Rex Dieter 8acc3d
From: =?UTF-8?q?Dan=20Vr=C3=A1til?= <dvratil@redhat.com>
Rex Dieter 8acc3d
Date: Tue, 23 Sep 2014 18:00:34 +0200
Rex Dieter adf30a
Subject: [PATCH 09/30] Test whether compiler supports all required C++11
Rex Dieter 8acc3d
 features at configure time
Rex Dieter 8acc3d
Rex Dieter 8acc3d
To prevent ugly compilation errors when someone tries to compile Akonadi
Rex Dieter 8acc3d
with a compiler that does not support all C++11 features we use, we run
Rex Dieter 8acc3d
a try_compile check in CMakeLists.txt.
Rex Dieter 8acc3d
---
Rex Dieter 8acc3d
 CMakeLists.txt | 18 ++++++++++++++++++
Rex Dieter 8acc3d
 1 file changed, 18 insertions(+)
Rex Dieter 8acc3d
Rex Dieter 8acc3d
diff --git a/CMakeLists.txt b/CMakeLists.txt
Rex Dieter 8acc3d
index e081d23..2d790c9 100644
Rex Dieter 8acc3d
--- a/CMakeLists.txt
Rex Dieter 8acc3d
+++ b/CMakeLists.txt
Rex Dieter 8acc3d
@@ -216,6 +216,24 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER MATCHES "icc" OR (CMAKE_CXX_COMP
Rex Dieter 8acc3d
   set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
Rex Dieter 8acc3d
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wnon-virtual-dtor -Wundef -Wcast-align -Wchar-subscripts -Wall -Wextra -Wpointer-arith -Wformat-security -fno-common")
Rex Dieter 8acc3d
 
Rex Dieter 8acc3d
+  file(WRITE ${CMAKE_BINARY_DIR}/cxx11_check.cpp
Rex Dieter 8acc3d
+       "enum Enum { Value = 1 };
Rex Dieter 8acc3d
+        struct Class {
Rex Dieter 8acc3d
+            Class(int val) { (void)val; };
Rex Dieter 8acc3d
+            // Delegating constructor
Rex Dieter 8acc3d
+            Class(): Class(42) {};
Rex Dieter 8acc3d
+            // New-style enumerator
Rex Dieter 8acc3d
+            Class(Enum e = Enum::Value) { (void)e; };
Rex Dieter 8acc3d
+        };
Rex Dieter 8acc3d
+        int main() {}
Rex Dieter 8acc3d
+       ")
Rex Dieter 8acc3d
+  try_compile(CXX11_SUPPORTED
Rex Dieter 8acc3d
+              ${CMAKE_BINARY_DIR}/cxx11_check
Rex Dieter 8acc3d
+              ${CMAKE_BINARY_DIR}/cxx11_check.cpp)
Rex Dieter 8acc3d
+  if (NOT CXX11_SUPPORTED)
Rex Dieter 8acc3d
+      message(FATAL_ERROR "Compiler does not support all required C++11 features")
Rex Dieter 8acc3d
+  endif()
Rex Dieter 8acc3d
+
Rex Dieter 8acc3d
   # debugfull target
Rex Dieter 8acc3d
   set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline" CACHE STRING "Flags used by the C++ compiler during debugfull builds." FORCE)
Rex Dieter 8acc3d
   set(CMAKE_C_FLAGS_DEBUGFULL   "-g3 -fno-inline" CACHE STRING "Flags used by the C compiler during debugfull builds." FORCE)
Rex Dieter 8acc3d
-- 
Rex Dieter adf30a
2.1.0
Rex Dieter 8acc3d