From 7298744a58cdd34fff28afed3c142aaaba1ff940 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Thu, 13 Jun 2013 23:40:00 +0200 Subject: [PATCH] bail out if some required C++-2011 features are not available --- CMakeLists.txt | 14 ++++++++++++++ cmake/Modules/FindCXX11Features.cmake | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08e69f894..a87d323b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ set (${project}_DEPS ${${PROJECT}_DEPENDS_LIST} ) + # C++ project cmake_minimum_required (VERSION 2.8) project(${${project}_NAME}) @@ -92,6 +93,19 @@ include (UseWarnings) include (OpmFind) find_and_append_package_list_to (${project} ${${project}_DEPS}) +# make sure the C++-2011 features which we rely on are supported +if (NOT HAVE_ARRAY) + message(FATAL_ERROR "std::array must be supported by the compiler for the ${project} module to work") +endif() + +if (NOT HAVE_STATIC_ASSERT) + message(FATAL_ERROR "static assertations (via static_assert) must be supported for the ${project} module to work") +endif() + +if (NOT HAVE_AUTO) + message(FATAL_ERROR "The 'auto' keyword must be supported by the compiler for the ${project} module to work") +endif() + # put debug information into every executable include (UseDebugSymbols) diff --git a/cmake/Modules/FindCXX11Features.cmake b/cmake/Modules/FindCXX11Features.cmake index 001a386af..85f2f3419 100644 --- a/cmake/Modules/FindCXX11Features.cmake +++ b/cmake/Modules/FindCXX11Features.cmake @@ -12,7 +12,8 @@ # HAVE_CONSTEXPR True if constexpr attribute is available # HAVE_INTEGRAL_CONSTANT True if compiler supports integral_constant # HAVE_STATIC_ASSERT True if static_assert is available -# HAVE_VARIADIC_TEMPLATES True if variadic templates are supprt +# HAVE_AUTO True if the compiler supports the auto keyword +# HAVE_VARIADIC_TEMPLATES True if variadic templates are supported # HAVE_VARIADIC_CONSTRUCTOR_SFINAE True if variadic constructor sfinae is supported # HAVE_RVALUE_REFERENCES True if rvalue references are supported # HAVE_TUPLE True if std::tuple is available @@ -189,6 +190,16 @@ CHECK_CXX_SOURCE_COMPILES(" " HAVE_STATIC_ASSERT ) +# auto keyword +CHECK_CXX_SOURCE_COMPILES(" + int main(void) + { + auto foo = 1.23; + return 0; + } +" HAVE_AUTO +) + # variadic template support CHECK_CXX_SOURCE_COMPILES(" #include