[Cmake-commits] CMake branch, next, updated. v2.8.11.2-3623-gbcb0a4b

Rolf Eike Beer eike at sf-mail.de
Fri Aug 2 15:58:52 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  bcb0a4b02550eef6fb774919f847d3121e7aabf6 (commit)
       via  8ea3dcd28d290f5eb15ab2caeab1ca925dd8c136 (commit)
      from  7e31e51eea43afd13acced2bc5dc49d54c0fb302 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bcb0a4b02550eef6fb774919f847d3121e7aabf6
commit bcb0a4b02550eef6fb774919f847d3121e7aabf6
Merge: 7e31e51 8ea3dcd
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Fri Aug 2 15:58:50 2013 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Aug 2 15:58:50 2013 -0400

    Merge topic 'cxx11' into next
    
    8ea3dcd add module to check for C++ features (#13842)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8ea3dcd28d290f5eb15ab2caeab1ca925dd8c136
commit 8ea3dcd28d290f5eb15ab2caeab1ca925dd8c136
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Fri Aug 2 21:55:22 2013 +0200
Commit:     Rolf Eike Beer <eike at sf-mail.de>
CommitDate: Fri Aug 2 21:55:22 2013 +0200

    add module to check for C++ features (#13842)

diff --git a/Modules/FindCXXFeatures.cmake b/Modules/FindCXXFeatures.cmake
new file mode 100644
index 0000000..a4acb2c
--- /dev/null
+++ b/Modules/FindCXXFeatures.cmake
@@ -0,0 +1,132 @@
+# - Check which features of the C++ standard the compiler supports
+#
+# When found it will set the following variables
+#
+#  CXX11_COMPILER_FLAGS                   - the compiler flags needed to get C++11 features
+#
+#  CXXFeatures_auto_FOUND                 - auto keyword
+#  CXXFeatures_class_override_final_FOUND - override and final keywords for classes and methods
+#  CXXFeatures_constexpr_FOUND            - constexpr keyword
+#  CXXFeatures_cstdint_header_FOUND       - cstdint header
+#  CXXFeatures_decltype_FOUND             - decltype keyword
+#  CXXFeatures_defaulted_functions_FOUND  - default keyword for functions
+#  CXXFeatures_deleted_functions_FOUND    - delete keyword for functions
+#  CXXFeatures_func_identifier_FOUND      - __func__ preprocessor constant
+#  CXXFeatures_initializer_list_FOUND     - initializer list
+#  CXXFeatures_lambda_FOUND               - lambdas
+#  CXXFeatures_long_long_FOUND            - long long signed & unsigned types
+#  CXXFeatures_nullptr_FOUND              - nullptr
+#  CXXFeatures_rvalue_references_FOUND    - rvalue references
+#  CXXFeatures_sizeof_member_FOUND        - sizeof() non-static members
+#  CXXFeatures_static_assert_FOUND        - static_assert()
+#  CXXFeatures_variadic_templates_FOUND   - variadic templates
+
+#=============================================================================
+# Copyright 2011,2012,2013 Rolf Eike Beer <eike at sf-mail.de>
+# Copyright 2012 Andreas Weis
+# Copyright 2013 Jan Kundrát
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+if (NOT CMAKE_CXX_COMPILER_LOADED)
+    message(FATAL_ERROR "CXXFeatures modules only works if language CXX is enabled")
+endif ()
+
+#
+### Check for needed compiler flags
+#
+include(${CMAKE_CURRENT_LIST_DIR}/CheckCXXCompilerFlag.cmake)
+check_cxx_compiler_flag("-std=c++11" _HAS_CXX11_FLAG)
+if (_HAS_CXX11_FLAG)
+    set(CXX11_COMPILER_FLAGS "-std=c++11")
+else ()
+    check_cxx_compiler_flag("-std=c++0x" _HAS_CXX0X_FLAG)
+    if (_HAS_CXX0X_FLAG)
+        set(CXX11_COMPILER_FLAGS "-std=c++0x")
+    endif ()
+endif ()
+
+function(cxx_check_feature FEATURE_NAME)
+    set(RESULT_VAR "CXXFeatures_${FEATURE_NAME}_FOUND")
+    if (DEFINED ${RESULT_VAR})
+        return()
+    endif()
+
+    set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${FEATURE_NAME}")
+
+    set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/FindCXXFeatures/cxx11-test-${FEATURE_NAME})
+    set(_LOG_NAME "\"${FEATURE_NAME}\"")
+    message(STATUS "Checking C++ support for ${_LOG_NAME}")
+
+    set(_SRCFILE "${_SRCFILE_BASE}.cxx")
+    set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cxx")
+
+    try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
+                COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
+
+    if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
+        try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
+                    COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
+        if (_TMP_RESULT)
+            set(${RESULT_VAR} FALSE)
+        else ()
+            set(${RESULT_VAR} TRUE)
+        endif ()
+    endif ()
+
+    if (${RESULT_VAR})
+        message(STATUS "Checking C++ support for ${_LOG_NAME}: works")
+    else ()
+        message(STATUS "Checking C++ support for ${_LOG_NAME}: not supported")
+    endif ()
+    set(${RESULT_VAR} "${${RESULT_VAR}}" CACHE INTERNAL "C++ support for ${_LOG_NAME}")
+endfunction(cxx_check_feature)
+
+set(_CXX_ALL_FEATURES
+    auto
+    class_override_final
+    constexpr
+    cstdint_header
+    decltype
+    defaulted_functions
+    deleted_functions
+    func_identifier
+    initializer_list
+    lambda
+    long_long
+    nullptr
+    rvalue_references
+    sizeof_member
+    static_assert
+    variadic_templates
+)
+
+if (CXXFeatures_FIND_COMPONENTS)
+    foreach (_cxx_feature IN LISTS CXXFeatures_FIND_COMPONENTS)
+        list(FIND _CXX_ALL_FEATURES "${_cxx_feature}" _feature_index)
+        if (_feature_index EQUAL -1)
+            message(FATAL_ERROR "Unknown component: '${_cxx_feature}'")
+        endif ()
+    endforeach ()
+    unset(_feature_index)
+else ()
+    set(CXXFEATURES_FIND_COMPONENTS ${_CXX_ALL_FEATURES})
+endif ()
+
+foreach (_cxx_feature IN LISTS CXXFEATURES_FIND_COMPONENTS)
+    cxx_check_feature(${_cxx_feature} ${FEATURE_NAME})
+endforeach (_cxx_feature)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+set(DUMMY_VAR TRUE)
+find_package_handle_standard_args(CXXFeatures REQUIRED_VARS DUMMY_VAR HANDLE_COMPONENTS)
+unset(DUMMY_VAR)
+unset(_CXX_ALL_FEATURES)
diff --git a/Modules/FindCXXFeatures/cxx11-test-auto.cxx b/Modules/FindCXXFeatures/cxx11-test-auto.cxx
new file mode 100644
index 0000000..cb600e5
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-auto.cxx
@@ -0,0 +1,12 @@
+
+int main()
+{
+    auto i = 5;
+    auto f = 3.14159f;
+    auto d = 3.14159;
+    bool ret = (
+        (sizeof(f) < sizeof(d)) &&
+        (sizeof(i) == sizeof(int))
+    );
+    return ret ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-auto_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-test-auto_fail_compile.cxx
new file mode 100644
index 0000000..ac152d5
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-auto_fail_compile.cxx
@@ -0,0 +1,7 @@
+int main(void)
+{
+    // must fail because there is no initializer
+    auto i;
+
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-class_override_final.cxx b/Modules/FindCXXFeatures/cxx11-test-class_override_final.cxx
new file mode 100644
index 0000000..5e938ff
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-class_override_final.cxx
@@ -0,0 +1,21 @@
+class base {
+public:
+    virtual int foo(int a)
+     { return 4 + a; }
+    virtual int bar(int a) final
+     { return a - 2; }
+};
+
+class sub final : public base {
+public:
+    virtual int foo(int a) override
+     { return 8 + 2 * a; };
+};
+
+int main(void)
+{
+    base b;
+    sub s;
+
+    return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-class_override_final_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-test-class_override_final_fail_compile.cxx
new file mode 100644
index 0000000..bc00b27
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-class_override_final_fail_compile.cxx
@@ -0,0 +1,25 @@
+class base {
+public:
+    virtual int foo(int a)
+     { return 4 + a; }
+    virtual int bar(int a) final
+     { return a - 2; }
+};
+
+class sub final : public base {
+public:
+    virtual int foo(int a) override
+     { return 8 + 2 * a; };
+    virtual int bar(int a)
+     { return a; }
+};
+
+class impossible : public sub { };
+
+int main(void)
+{
+    base b;
+    sub s;
+
+    return 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-constexpr.cxx b/Modules/FindCXXFeatures/cxx11-test-constexpr.cxx
new file mode 100644
index 0000000..ba66d65
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-constexpr.cxx
@@ -0,0 +1,19 @@
+constexpr int square(int x)
+{
+    return x * x;
+}
+
+constexpr int the_answer()
+{
+    return 42;
+}
+
+int main()
+{
+    int test_arr[square(3)];
+    bool ret = (
+        (square(the_answer()) == 1764) &&
+        (sizeof(test_arr)/sizeof(test_arr[0]) == 9)
+    );
+    return ret ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-cstdint_header.cxx b/Modules/FindCXXFeatures/cxx11-test-cstdint_header.cxx
new file mode 100644
index 0000000..d02e93c
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-cstdint_header.cxx
@@ -0,0 +1,11 @@
+#include <cstdint>
+
+int main()
+{
+    bool test =
+        (sizeof(int8_t) == 1) &&
+        (sizeof(int16_t) == 2) &&
+        (sizeof(int32_t) == 4) &&
+        (sizeof(int64_t) == 8);
+    return test ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-decltype.cxx b/Modules/FindCXXFeatures/cxx11-test-decltype.cxx
new file mode 100644
index 0000000..ce33089
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-decltype.cxx
@@ -0,0 +1,10 @@
+bool check_size(int i)
+{
+    return sizeof(int) == sizeof(decltype(i));
+}
+
+int main()
+{
+    bool ret = check_size(42);
+    return ret ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-defaulted_functions.cxx b/Modules/FindCXXFeatures/cxx11-test-defaulted_functions.cxx
new file mode 100644
index 0000000..c7ca5b8
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-defaulted_functions.cxx
@@ -0,0 +1,13 @@
+struct A {
+    int foo;
+
+    A(int foo): foo(foo) {}
+    A() = default;
+};
+
+int main(void)
+{
+    A bar;
+    A baz(10);
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-deleted_functions.cxx b/Modules/FindCXXFeatures/cxx11-test-deleted_functions.cxx
new file mode 100644
index 0000000..c1ec2b9
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-deleted_functions.cxx
@@ -0,0 +1,10 @@
+struct A {
+    A() = delete;
+    A(int) {}
+};
+
+int main(void)
+{
+    A bar(10);
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-deleted_functions_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-test-deleted_functions_fail_compile.cxx
new file mode 100644
index 0000000..f32a7b1
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-deleted_functions_fail_compile.cxx
@@ -0,0 +1,9 @@
+struct A {
+    ~A() = delete;
+};
+
+int main(void)
+{
+    A bar;
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-func_identifier.cxx b/Modules/FindCXXFeatures/cxx11-test-func_identifier.cxx
new file mode 100644
index 0000000..e29273b
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-func_identifier.cxx
@@ -0,0 +1,10 @@
+#include <string.h>
+
+int main(void)
+{
+    if (!__func__)
+        return 1;
+    if (!(*__func__))
+        return 1;
+    return strstr(__func__, "main") != 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-initializer_list.cxx b/Modules/FindCXXFeatures/cxx11-test-initializer_list.cxx
new file mode 100644
index 0000000..35e6c38
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-initializer_list.cxx
@@ -0,0 +1,27 @@
+#include <vector>
+
+class seq {
+public:
+    seq(std::initializer_list<int> list);
+
+    int length() const;
+private:
+    std::vector<int> m_v;
+};
+
+seq::seq(std::initializer_list<int> list)
+    : m_v(list)
+{
+}
+
+int seq::length() const
+{
+    return m_v.size();
+}
+
+int main(void)
+{
+    seq a = {18, 20, 2, 0, 4, 7};
+
+    return (a.length() == 6) ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-lambda.cxx b/Modules/FindCXXFeatures/cxx11-test-lambda.cxx
new file mode 100644
index 0000000..a302b2f
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-lambda.cxx
@@ -0,0 +1,5 @@
+int main()
+{
+    int ret = 0;
+    return ([&ret]() -> int { return ret; })();
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-long_long.cxx b/Modules/FindCXXFeatures/cxx11-test-long_long.cxx
new file mode 100644
index 0000000..3fa59fb
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-long_long.cxx
@@ -0,0 +1,7 @@
+int main(void)
+{
+    long long l;
+    unsigned long long ul;
+
+    return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-nullptr.cxx b/Modules/FindCXXFeatures/cxx11-test-nullptr.cxx
new file mode 100644
index 0000000..e87ca65
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-nullptr.cxx
@@ -0,0 +1,9 @@
+#include <cstddef>
+
+int main(void)
+{
+    void *v = nullptr;
+    std::nullptr_t n = nullptr;
+
+    return v ? 1 : 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-nullptr_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-test-nullptr_fail_compile.cxx
new file mode 100644
index 0000000..adfd24f
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-nullptr_fail_compile.cxx
@@ -0,0 +1,6 @@
+int main(void)
+{
+    int i = nullptr;
+
+    return 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-rvalue_references.cxx b/Modules/FindCXXFeatures/cxx11-test-rvalue_references.cxx
new file mode 100644
index 0000000..e6e7e5a
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-rvalue_references.cxx
@@ -0,0 +1,57 @@
+#include <cassert>
+
+class rvmove {
+public:
+   void *ptr;
+   char *array;
+
+   rvmove()
+    : ptr(0),
+    array(new char[10])
+   {
+     ptr = this;
+   }
+
+   rvmove(rvmove &&other)
+    : ptr(other.ptr),
+    array(other.array)
+   {
+    other.array = 0;
+    other.ptr = 0;
+   }
+
+   ~rvmove()
+   {
+    assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
+    delete[] array;
+   }
+
+   rvmove &operator=(rvmove &&other)
+   {
+     delete[] array;
+     ptr = other.ptr;
+     array = other.array;
+     other.array = 0;
+     other.ptr = 0;
+     return *this;
+   }
+
+   static rvmove create()
+   {
+     return rvmove();
+   }
+private:
+  rvmove(const rvmove &);
+  rvmove &operator=(const rvmove &);
+};
+
+int main()
+{
+  rvmove mine;
+  if (mine.ptr != &mine)
+    return 1;
+  mine = rvmove::create();
+  if (mine.ptr == &mine)
+    return 1;
+  return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-sizeof_member.cxx b/Modules/FindCXXFeatures/cxx11-test-sizeof_member.cxx
new file mode 100644
index 0000000..8aebc55
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-sizeof_member.cxx
@@ -0,0 +1,14 @@
+struct foo {
+    char bar;
+    int baz;
+};
+
+int main(void)
+{
+    bool ret = (
+        (sizeof(foo::bar) == 1) &&
+        (sizeof(foo::baz) >= sizeof(foo::bar)) &&
+        (sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz))
+    );
+    return ret ? 0 : 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-static_assert.cxx b/Modules/FindCXXFeatures/cxx11-test-static_assert.cxx
new file mode 100644
index 0000000..5976cfc
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-static_assert.cxx
@@ -0,0 +1,5 @@
+int main(void)
+{
+    static_assert(0 < 1, "your ordering of integers is screwed");
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-static_assert_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-test-static_assert_fail_compile.cxx
new file mode 100644
index 0000000..484abc0
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-static_assert_fail_compile.cxx
@@ -0,0 +1,5 @@
+int main(void)
+{
+    static_assert(1 < 0, "your ordering of integers is screwed");
+    return 0;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-test-variadic_templates.cxx b/Modules/FindCXXFeatures/cxx11-test-variadic_templates.cxx
new file mode 100644
index 0000000..e81ca9d
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-test-variadic_templates.cxx
@@ -0,0 +1,23 @@
+int Accumulate()
+{
+    return 0;
+}
+
+template<typename T, typename... Ts>
+int Accumulate(T v, Ts... vs)
+{
+    return v + Accumulate(vs...);
+}
+
+template<int... Is>
+int CountElements()
+{
+    return sizeof...(Is);
+}
+
+int main()
+{
+    int acc = Accumulate(1, 2, 3, 4, -5);
+    int count = CountElements<1,2,3,4,5>();
+    return ((acc == 5) && (count == 5)) ? 0 : 1;
+}
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 16693de..067fba0 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -338,6 +338,7 @@ if(BUILD_TESTING)
   list(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
 
   ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
+  ADD_TEST_MACRO(Module.CXXFeatures CXXFeatures)
 
   add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
     --build-and-test
diff --git a/Tests/Module/CXXFeatures/CMakeLists.txt b/Tests/Module/CXXFeatures/CMakeLists.txt
new file mode 100644
index 0000000..dd5be4c
--- /dev/null
+++ b/Tests/Module/CXXFeatures/CMakeLists.txt
@@ -0,0 +1,66 @@
+cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
+project(CxxFeatures CXX)
+
+find_package(CXXFeatures)
+
+set(_all_cxx_features
+        CXXFeatures_auto_FOUND
+        CXXFeatures_class_override_final_FOUND
+        CXXFeatures_constexpr_FOUND
+        CXXFeatures_cstdint_header_FOUND
+        CXXFeatures_decltype_FOUND
+        CXXFeatures_defaulted_functions_FOUND
+        CXXFeatures_deleted_functions_FOUND
+        CXXFeatures_func_identifier_FOUND
+        CXXFeatures_initializer_list_FOUND
+        CXXFeatures_lambda_FOUND
+        CXXFeatures_long_long_FOUND
+        CXXFeatures_nullptr_FOUND
+        CXXFeatures_rvalue_references_FOUND
+        CXXFeatures_sizeof_member_FOUND
+        CXXFeatures_static_assert_FOUND
+        CXXFeatures_variadic_templates_FOUND
+)
+
+unset(_expected_features)
+unset(_expected_cxx11_flag)
+unset(_compiler_unknown_features)
+
+if (CMAKE_COMPILER_IS_GNUCXX)
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+        set(_expected_features ${_all_cxx_features})
+        set(_expected_cxx11_flag "-std=c++11")
+    else ()
+        set(_expected_features CXXFeatures_long_long_FOUND)
+        set(_expected_cxx11_flag "-std=c++0x")
+    endif ()
+else ()
+    message(WARNING "Your C++ compiler configuration is not in the list of known configurations")
+    set(_compiler_unknown_features TRUE)
+endif ()
+
+foreach (flag IN LISTS _all_cxx_features)
+    list(FIND _expected_features "${flag}" _flag_index)
+    if (${flag})
+        add_definitions("-D${flag}")
+        message(STATUS "Compiler C++ support flag ${flag} set")
+        if (_flag_index EQUAL -1 AND NOT _compiler_unknown_features)
+            message(SEND_ERROR "C++ feature '${flag}' was detected, but not expected")
+        endif ()
+    else ()
+        if (NOT _flag_index EQUAL -1)
+            message(SEND_ERROR "Expected C++ feature '${flag}' not detected")
+        endif ()
+    endif ()
+endforeach (flag)
+
+if (NOT CXX11_COMPILER_FLAGS STREQUAL _expected_cxx11_flag)
+    message(SEND_ERROR "Found C++11 flag '${CXX11_COMPILER_FLAGS}' but expected '${_expected_cxx11_flag}'")
+endif ()
+set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS})
+add_executable(CXXFeatures cxxfeatures.cxx)
+
+enable_testing()
+if (NOT CROSS_COMPILING)
+    add_test(NAME CXXFeatures COMMAND CXXFeatures)
+endif ()
diff --git a/Tests/Module/CXXFeatures/cxxfeatures.cxx b/Tests/Module/CXXFeatures/cxxfeatures.cxx
new file mode 100644
index 0000000..d0a50e1
--- /dev/null
+++ b/Tests/Module/CXXFeatures/cxxfeatures.cxx
@@ -0,0 +1,57 @@
+#if defined(CXXFEATURES_CSTDINT_FOUND)
+#include <cstdint>
+#endif
+
+#include <sys/types.h>
+
+struct thing {
+    unsigned char one;
+#if defined(CXXFEATURES_CSTDINT_FOUND)
+    uint32_t four;
+#endif
+#if defined(CXXFEATURES_LONG_LONG_FOUND)
+    long long eight;
+#endif
+};
+
+#include <stdio.h>
+
+int main()
+{
+#if defined (CXXFEATURES_NULLPTR_FOUND)
+    void *nix = nullptr;
+#else /* CXXFEATURES_NULLPTR_FOUND */
+    void *nix = 0;
+#endif /* CXXFEATURES_NULLPTR_FOUND */
+
+#if defined(CXXFEATURES_STATIC_ASSERT_FOUND)
+    static_assert(1 < 42, "Your C++ compiler is b0rked");
+#endif /* CXXFEATURES_STATIC_ASSERT_FOUND */
+
+#if defined(CXXFEATURES___FUNC___FOUND)
+    const char *funcname = __func__;
+    printf("the name of main() function is: %s\n", funcname);
+#endif /* CXXFEATURES_FUNC_FOUND */
+
+#if defined(CXXFEATURES_SIZEOF_MEMBER_FOUND)
+    size_t onesize = sizeof(thing::one);
+#if defined(CXXFEATURES_STATIC_ASSERT_FOUND)
+    static_assert(sizeof(thing::one) == 1, "Your char is not one byte long");
+#endif /* CXXFEATURES_STATIC_ASSERT_FOUND */
+
+#if defined(CXXFEATURES_CSTDINT_FOUND)
+    size_t foursize = sizeof(thing::four);
+#if defined(CXXFEATURES_STATIC_ASSERT_FOUND)
+    static_assert(sizeof(thing::four) == 4, "Your uint32_t is not 32 bit long");
+#endif /* CXXFEATURES_STATIC_ASSERT_FOUND */
+#endif /* CXXFEATURES_CSTDINT_FOUND */
+#if defined(CXXFEATURES_LONG_LONG_FOUND)
+    size_t eightsize = sizeof(thing::eight);
+#if defined(CXXFEATURES_STATIC_ASSERT_FOUND)
+    static_assert(sizeof(thing::eight) == 8, "Your long long is not 64 bit long");
+#endif /* CXXFEATURES_STATIC_ASSERT_FOUND */
+#endif /* CXXFEATURES_LONG_LONG_FOUND */
+#endif /* CXXFEATURES_SIZEOF_MEMBER_FOUND */
+
+    return 0;
+}

-----------------------------------------------------------------------

Summary of changes:
 Modules/FindCXXFeatures.cmake                      |  132 ++++++++++++++++++++
 Modules/FindCXXFeatures/cxx11-test-auto.cxx        |   12 ++
 .../cxx11-test-auto_fail_compile.cxx               |    7 +
 .../cxx11-test-class_override_final.cxx            |   21 +++
 ...xx11-test-class_override_final_fail_compile.cxx |   25 ++++
 Modules/FindCXXFeatures/cxx11-test-constexpr.cxx   |   19 +++
 .../FindCXXFeatures/cxx11-test-cstdint_header.cxx  |   11 ++
 Modules/FindCXXFeatures/cxx11-test-decltype.cxx    |   10 ++
 .../cxx11-test-defaulted_functions.cxx             |   13 ++
 .../cxx11-test-deleted_functions.cxx               |   10 ++
 .../cxx11-test-deleted_functions_fail_compile.cxx  |    9 ++
 .../FindCXXFeatures/cxx11-test-func_identifier.cxx |   10 ++
 .../cxx11-test-initializer_list.cxx                |   27 ++++
 Modules/FindCXXFeatures/cxx11-test-lambda.cxx      |    5 +
 Modules/FindCXXFeatures/cxx11-test-long_long.cxx   |    7 +
 Modules/FindCXXFeatures/cxx11-test-nullptr.cxx     |    9 ++
 .../cxx11-test-nullptr_fail_compile.cxx            |    6 +
 .../cxx11-test-rvalue_references.cxx               |   57 +++++++++
 .../FindCXXFeatures/cxx11-test-sizeof_member.cxx   |   14 ++
 .../FindCXXFeatures/cxx11-test-static_assert.cxx   |    5 +
 .../cxx11-test-static_assert_fail_compile.cxx      |    5 +
 .../cxx11-test-variadic_templates.cxx              |   23 ++++
 Tests/CMakeLists.txt                               |    1 +
 Tests/Module/CXXFeatures/CMakeLists.txt            |   66 ++++++++++
 Tests/Module/CXXFeatures/cxxfeatures.cxx           |   57 +++++++++
 25 files changed, 561 insertions(+), 0 deletions(-)
 create mode 100644 Modules/FindCXXFeatures.cmake
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-auto.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-auto_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-class_override_final.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-class_override_final_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-constexpr.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-cstdint_header.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-decltype.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-defaulted_functions.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-deleted_functions.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-deleted_functions_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-func_identifier.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-initializer_list.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-lambda.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-long_long.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-nullptr.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-nullptr_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-rvalue_references.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-sizeof_member.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-static_assert.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-static_assert_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-test-variadic_templates.cxx
 create mode 100644 Tests/Module/CXXFeatures/CMakeLists.txt
 create mode 100644 Tests/Module/CXXFeatures/cxxfeatures.cxx


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list