Add cmake C++14 feature check
authorRoland Schulz <roland.schulz@intel.com>
Fri, 25 Jan 2019 21:29:15 +0000 (13:29 -0800)
committerPaul Bauer <paul.bauer.q@gmail.com>
Tue, 29 Jan 2019 12:54:33 +0000 (13:54 +0100)
Change-Id: Ia4e2185aca2a8e1ff1b07cc9b49cfee33a6de705

cmake/gmxTestCompilerProblems.cmake

index c1355ac1ab329201adc0ca0aadaaa4c4f4437369..67afbc171ff393de895f9363b882780d77b9b8ca 100644 (file)
@@ -46,6 +46,29 @@ macro(gmx_test_compiler_problems)
         message(WARNING "The versions of the C and C++ compilers do not match (${CMAKE_C_COMPILER_VERSION} and ${CMAKE_CXX_COMPILER_VERSION}, respectively). Mixing different C/C++ compilers can cause problems.")
     endif()
 
+    # Error if compiler doesn't support required C++14 features. Relaxed constexpr is currently only required
+    # feature. It is also one of the last implemented C++14 features by all supported compilers.
+    if(NOT "cxx_relaxed_constexpr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
+        if(CMAKE_COMPILER_IS_GNUCXX)
+            set(cxx_required_version "GCC version 5")
+        elseif(MSVC)
+            if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.15) # cmake reports no support because of bugs but
+                set(cxx_required_version "Visual Studio 2017") # we support it.
+            endif()
+        elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+            set(cxx_required_version "Clang 3.6") # For feature complete C++14 only 3.4 is needed.
+                                                  # But prior version have bugs (e.g. debug symbol support)
+        elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+            set(cxx_required_version "Intel Compiler 2017")
+        else()
+            message(FATAL_ERROR "The compiler doesn't have sufficient C++14 support.")
+        endif()
+        if (cxx_required_version)
+            message(FATAL_ERROR "${cxx_required_version} or later required. "
+                                "Earlier versions don't have full C++14 support.")
+        endif()
+    endif()
+
     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "XL")
         check_cxx_source_compiles(
 "// Test in-class array initalizers used with constructor initializer lists