commit 499c5cfe571a29b6cb74d84528c1b6ace0f85d67
Author: Kornel Benko <[email protected]>
Date:   Sun Dec 15 11:41:28 2013 +0100

    Adapt cmake build to use c++11 features also for clang compiler

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa16d10..09f9462 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -213,11 +213,11 @@ if(UNIX OR MINGW)
                set(LYX_USE_TR1_REGEX 0)
        endif()
        if (LYX_ENABLE_CXX11)
-               if(GCC_VERSION VERSION_GREATER 4.7)
-                       set(LYX_GCC11_MODE "-std=gnu++11")
-               elseif(GCC_VERSION VERSION_GREATER 4.2)
-                       set(LYX_GCC11_MODE "-std=gnu++0x")
+               find_package(CXX11Compiler)
+               if(NOT CXX11COMPILER_FOUND)
+                       message(FATAL_ERROR "A C++11 compatible compiler is 
required.")
                endif()
+               set(LYX_GCC11_MODE "${CXX11_FLAG}")
        endif()
 else()
        if(MSVC10)
diff --git a/development/cmake/modules/FindCXX11Compiler.cmake 
b/development/cmake/modules/FindCXX11Compiler.cmake
new file mode 100644
index 0000000..e43e449
--- /dev/null
+++ b/development/cmake/modules/FindCXX11Compiler.cmake
@@ -0,0 +1,95 @@
+# This file is part of lyx.
+#
+# The module comes from the enblend project, slightly modified.
+#
+# Check if compiler supports C++11 features 
+# and which compiler switches are necessary
+# CXX11_FLAG : contains the necessary compiler flag
+
+#
+# Copyright (c) 2013 Thomas Modes <tmodes@@users.sourceforge.net>
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the copyright
+#         notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the copyright
+#         notice, this list of conditions and the following disclaimer in the
+#         documentation and/or other materials provided with the distribution.
+#  3. The name of the author may not be used to endorse or promote products
+#         derived from this software without specific prior written permission.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with lyx; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+INCLUDE(CheckCXXSourceCompiles)
+INCLUDE(FindPackageHandleStandardArgs)
+
+if (CMAKE_CXX_COMPILER MATCHES "clang")
+  set(CXX11_FLAG_CANDIDATES "--std=c++11")
+else()
+  set(CXX11_FLAG_CANDIDATES
+    "--std=gnu++11"
+    "--std=c++11"
+    "--std=gnu++0x"
+  )
+endif()
+
+# sample openmp source code to test
+SET(CXX11_TEST_SOURCE 
+"
+template <typename T>
+struct check
+{
+    static_assert(sizeof(int) <= sizeof(T), \"not big enough\");
+};
+
+typedef check<check<bool>> right_angle_brackets;
+
+class TestDeleted
+{
+public:
+    TestDeleted() = delete;
+};
+
+
+int a;
+decltype(a) b;
+
+typedef check<int> check_type;
+check_type c;
+check_type&& cr = static_cast<check_type&&>(c);
+
+auto d = a;
+
+int main() {
+  return 0;
+};
+")
+
+# check c compiler
+FOREACH(FLAG ${CXX11_FLAG_CANDIDATES})
+  SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+  SET(CMAKE_REQUIRED_FLAGS "${FLAG}")
+  UNSET(CXX11_FLAG_DETECTED CACHE)
+  CHECK_CXX_SOURCE_COMPILES("${CXX11_TEST_SOURCE}" CXX11_FLAG_DETECTED)
+  SET(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
+  IF(CXX11_FLAG_DETECTED)
+    SET(CXX11_FLAG "${FLAG}")
+    BREAK()
+  ENDIF()
+ENDFOREACH()
+
+# handle the standard arguments for find_package
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(CXX11Compiler DEFAULT_MSG CXX11_FLAG)
+
+MARK_AS_ADVANCED(CXX11_FLAG)

Reply via email to