[Cmake-commits] CMake branch, next, updated. v2.8.11.2-4012-ga44800c

Rolf Eike Beer eike at sf-mail.de
Tue Aug 27 13:49:12 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  a44800c084ce56567b1951c3d50675808d8a5bb6 (commit)
       via  63fba61020b8d1fceeeb22c330c8308a59e202ce (commit)
      from  5d9c38ce546390b0ffc910b4c73f9297451858c1 (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=a44800c084ce56567b1951c3d50675808d8a5bb6
commit a44800c084ce56567b1951c3d50675808d8a5bb6
Merge: 5d9c38c 63fba61
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Tue Aug 27 13:48:53 2013 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Tue Aug 27 13:48:53 2013 -0400

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


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=63fba61020b8d1fceeeb22c330c8308a59e202ce
commit 63fba61020b8d1fceeeb22c330c8308a59e202ce
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: Tue Aug 27 19:48:48 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..e885e5c
--- /dev/null
+++ b/Modules/FindCXXFeatures.cmake
@@ -0,0 +1,161 @@
+# - 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_delegating_constructors_FOUND - delegating constructors
+#  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-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)
+
+function(test_set_flag FLAG NAME)
+    check_cxx_compiler_flag("${FLAG}" _HAS_${NAME}_FLAG)
+    if (_HAS_${NAME}_FLAG)
+        set(CXX11_COMPILER_FLAGS "${FLAG}" PARENT_SCOPE)
+    endif ()
+endfunction()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "XL")
+    test_set_flag("-qlanglvl=extended0x" CXX0x)
+elseif (CMAKE_CXX_COMPILER_ID MATCHES "(Borland|Watcom)")
+    # No C++11 flag for those compilers, but check_cxx_compiler_flag()
+    # can't detect because they either will not always complain (Borland)
+    # or will hang (Watcom).
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND WIN32)
+    # The Intel compiler on Windows may use these flags.
+    test_set_flag("/Qstd=c++11" CXX11)
+    if (NOT CXX11_COMPILER_FLAGS)
+        test_set_flag("/Qstd=c++0x" CXX0x)
+    endif ()
+else ()
+    test_set_flag("-std=c++11" CXX11)
+    if (NOT CXX11_COMPILER_FLAGS)
+        test_set_flag("-std=c++0x" CXX0x)
+    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-${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}"
+                OUTPUT_VARIABLE _SRCFILE_COMPILE_PASS_OUTPUT)
+
+    if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
+        try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
+                    COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}"
+                    OUTPUT_VARIABLE _SRCFILE_COMPILE_FAIL_OUTPUT)
+        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")
+        file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+          "Checking C++ support for ${_LOG_NAME} passed.\n"
+          "Compile pass output:\n${_SRCFILE_COMPILE_PASS_OUTPUT}\n"
+          "Compile fail output:\n${_SRCFILE_COMPILE_FAIL_OUTPUT}\n")
+    else ()
+        message(STATUS "Checking C++ support for ${_LOG_NAME}: not supported")
+        file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+          "Checking C++ support for ${_LOG_NAME} failed.\n"
+          "Compile pass output:\n${_SRCFILE_COMPILE_PASS_OUTPUT}\n"
+          "Compile fail output:\n${_SRCFILE_COMPILE_FAIL_OUTPUT}\n")
+    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
+    delegating_constructors
+    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-auto.cxx b/Modules/FindCXXFeatures/cxx11-auto.cxx
new file mode 100644
index 0000000..19491e6
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-auto.cxx
@@ -0,0 +1,11 @@
+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-auto_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-auto_fail_compile.cxx
new file mode 100644
index 0000000..ac152d5
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-class_override_final.cxx b/Modules/FindCXXFeatures/cxx11-class_override_final.cxx
new file mode 100644
index 0000000..5e938ff
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-class_override_final_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-class_override_final_fail_compile.cxx
new file mode 100644
index 0000000..bc00b27
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-constexpr.cxx b/Modules/FindCXXFeatures/cxx11-constexpr.cxx
new file mode 100644
index 0000000..ba66d65
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-cstdint_header.cxx b/Modules/FindCXXFeatures/cxx11-cstdint_header.cxx
new file mode 100644
index 0000000..d02e93c
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-decltype.cxx b/Modules/FindCXXFeatures/cxx11-decltype.cxx
new file mode 100644
index 0000000..ce33089
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-defaulted_functions.cxx b/Modules/FindCXXFeatures/cxx11-defaulted_functions.cxx
new file mode 100644
index 0000000..c7ca5b8
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-delegating_constructors.cxx b/Modules/FindCXXFeatures/cxx11-delegating_constructors.cxx
new file mode 100644
index 0000000..e2f6abd
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-delegating_constructors.cxx
@@ -0,0 +1,25 @@
+class del {
+public:
+    del();
+    del(int k);
+
+    int m_k;
+};
+
+del::del()
+    : del(42)
+{
+}
+
+del::del(int k)
+    : m_k(k)
+{
+}
+
+int main()
+{
+    del q(41);
+    del a;
+
+    return a.m_k - q.m_k - 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-deleted_functions.cxx b/Modules/FindCXXFeatures/cxx11-deleted_functions.cxx
new file mode 100644
index 0000000..c1ec2b9
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-deleted_functions_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-deleted_functions_fail_compile.cxx
new file mode 100644
index 0000000..216f074
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-deleted_functions_fail_compile.cxx
@@ -0,0 +1,18 @@
+struct A {
+    A() = delete;
+    ~A() = delete;
+    int m;
+    int ret();
+};
+
+int A::ret()
+{
+    return 2 * m;
+}
+
+int main(void)
+{
+    A bar;
+    bar.m = 1;
+    return bar.ret();
+}
diff --git a/Modules/FindCXXFeatures/cxx11-func_identifier.cxx b/Modules/FindCXXFeatures/cxx11-func_identifier.cxx
new file mode 100644
index 0000000..e29273b
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-initializer_list.cxx b/Modules/FindCXXFeatures/cxx11-initializer_list.cxx
new file mode 100644
index 0000000..a23e962
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-initializer_list.cxx
@@ -0,0 +1,28 @@
+#include <initializer_list>
+#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-lambda.cxx b/Modules/FindCXXFeatures/cxx11-lambda.cxx
new file mode 100644
index 0000000..a302b2f
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-lambda.cxx
@@ -0,0 +1,5 @@
+int main()
+{
+    int ret = 0;
+    return ([&ret]() -> int { return ret; })();
+}
diff --git a/Modules/FindCXXFeatures/cxx11-long_long.cxx b/Modules/FindCXXFeatures/cxx11-long_long.cxx
new file mode 100644
index 0000000..3fa59fb
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-nullptr.cxx b/Modules/FindCXXFeatures/cxx11-nullptr.cxx
new file mode 100644
index 0000000..317f471
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-nullptr.cxx
@@ -0,0 +1,19 @@
+int func(int)
+{
+    return 1;
+}
+
+int func(void *)
+{
+    return 0;
+}
+
+int main(void)
+{
+    void *v = nullptr;
+
+    if (v)
+        return 1;
+
+    return func(nullptr);
+}
diff --git a/Modules/FindCXXFeatures/cxx11-nullptr_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-nullptr_fail_compile.cxx
new file mode 100644
index 0000000..adfd24f
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-nullptr_fail_compile.cxx
@@ -0,0 +1,6 @@
+int main(void)
+{
+    int i = nullptr;
+
+    return 1;
+}
diff --git a/Modules/FindCXXFeatures/cxx11-rvalue_references.cxx b/Modules/FindCXXFeatures/cxx11-rvalue_references.cxx
new file mode 100644
index 0000000..e6e7e5a
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-sizeof_member.cxx b/Modules/FindCXXFeatures/cxx11-sizeof_member.cxx
new file mode 100644
index 0000000..8aebc55
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-static_assert.cxx b/Modules/FindCXXFeatures/cxx11-static_assert.cxx
new file mode 100644
index 0000000..5976cfc
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-static_assert_fail_compile.cxx b/Modules/FindCXXFeatures/cxx11-static_assert_fail_compile.cxx
new file mode 100644
index 0000000..484abc0
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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-variadic_templates.cxx b/Modules/FindCXXFeatures/cxx11-variadic_templates.cxx
new file mode 100644
index 0000000..e81ca9d
--- /dev/null
+++ b/Modules/FindCXXFeatures/cxx11-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..c6cee61 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.FindCXXFeatures FindCXXFeatures)
 
   add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
     --build-and-test
diff --git a/Tests/Module/FindCXXFeatures/CMakeLists.txt b/Tests/Module/FindCXXFeatures/CMakeLists.txt
new file mode 100644
index 0000000..6b60954
--- /dev/null
+++ b/Tests/Module/FindCXXFeatures/CMakeLists.txt
@@ -0,0 +1,327 @@
+cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
+project(FindCXXFeatures CXX)
+
+# all detectable features
+set(_all_cxx_features
+        auto
+        class_override_final
+        constexpr
+        cstdint_header
+        decltype
+        defaulted_functions
+        delegating_constructors
+        deleted_functions
+        func_identifier
+        initializer_list
+        lambda
+        long_long
+        nullptr
+        rvalue_references
+        sizeof_member
+        static_assert
+        variadic_templates
+)
+
+# a feature that even a non-supporting compiler can offer
+# when the correct headers are present
+set(_header_on_features
+        cstdint_header
+)
+
+# features that need the proper headers in place, i.e. a
+# supporting compiler with older headers will fail
+# nullptr test intentionally does not test for nullptr_t so it
+# is independent of any headers
+set(_header_off_features
+        ${_header_on_features}
+        initializer_list
+)
+
+unset(_expected_features)
+unset(_expected_cxx11_flag)
+unset(_compiler_unknown_features)
+unset(_compiler_unknown_flag)
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    # no idea since when this is supported, but it is at least
+    # supported since 3.1
+    list(APPEND _expected_features
+         long_long
+         func_identifier)
+
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
+        set(_expected_cxx11_flag "-std=c++0x")
+        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+            set(_expected_cxx11_flag "-std=c++11")
+            list(APPEND _expected_features
+                 class_override_final
+                 delegating_constructors)
+        endif ()
+        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
+            list(APPEND _expected_features
+                 nullptr)
+        endif ()
+        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
+            list(APPEND _expected_features
+                 constexpr
+                 lambda)
+        endif ()
+        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
+            list(APPEND _expected_features
+                 auto
+                 cstdint_header
+                 defaulted_functions
+                 deleted_functions
+                 initializer_list
+                 sizeof_member)
+        endif ()
+        list(APPEND _expected_features
+             decltype
+             rvalue_references
+             static_assert
+             variadic_templates)
+    endif ()
+    # At least on one AIX dashboard machine the detection fails with
+    # gcc 2.9, looks like that didn't properly detect the flags.
+    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3)
+        set(_compiler_unknown_flag TRUE)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
+        list(APPEND _expected_features
+             class_override_final)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
+        list(APPEND _expected_features
+             auto
+             cstdint_header
+             decltype
+             lambda
+             nullptr
+             rvalue_references
+             static_assert)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.01)
+        list(APPEND _expected_features
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Borland")
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.60)
+        list(APPEND _expected_features
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "XL")
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.1)
+        set(_expected_cxx11_flag "-qlanglvl=extended0x")
+        list(APPEND _expected_features
+             long_long)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.1)
+        # func_identifier and sizeof_member are here because they were detected on a
+        # test machine but it is unclear since when they are supported
+        list(APPEND _expected_features
+             auto
+             decltype
+             delegating_constructors
+             func_identifier
+             sizeof_member
+             static_assert
+             variadic_templates)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1)
+        list(APPEND _expected_features
+             constexpr
+             rvalue_references)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
+    # values found by looking on the test output, may be present much longer
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
+        list(APPEND _expected_features
+             long_long
+             sizeof_member)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
+    # values found by looking on the test output, may be present much longer
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.3)
+        list(APPEND _expected_features
+             func_identifier
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.1)
+        if (WIN32)
+            set(_expected_cxx11_flag "/Qstd=c++0x")
+        else ()
+            set(_expected_cxx11_flag "-std=c++0x")
+        endif ()
+        list(APPEND _expected_features
+             func_identifier
+             long_long
+             static_assert)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
+        list(APPEND _expected_features
+             auto
+             decltype
+             defaulted_functions
+             deleted_functions
+             func_identifier
+             lambda
+             long_long
+             rvalue_references
+             sizeof_member
+             static_assert)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1)
+        list(APPEND _expected_features
+             variadic_templates)
+    endif ()
+    # constexpr is partially supported in version 13, it may
+    # already show up for this version depending on the check file.
+    # The same applies to initializer lists.
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
+        if (WIN32)
+            set(_expected_cxx11_flag "/Qstd=c++11")
+        else ()
+            set(_expected_cxx11_flag "-std=c++11")
+        endif ()
+        list(APPEND _expected_features
+             nullptr)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
+        list(APPEND _expected_features
+             class_override_final
+             constexpr
+             delegating_constructors
+             initializer_list)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Watcom")
+    # values found by looking on the test output, may be present much longer
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.70)
+        list(APPEND _expected_features
+             func_identifier
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MIPSpro")
+    # values found by looking on the test output, may be present much longer
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.4.4)
+        list(APPEND _expected_features
+             func_identifier
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP")
+    # values found by looking on the test output, may be present much longer
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.20)
+        list(APPEND _expected_features
+             func_identifier
+             long_long)
+    endif ()
+elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
+        set(_expected_cxx11_flag "-std=c++0x")
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.9)
+        list(APPEND _expected_features
+             auto
+             class_override_final
+             constexpr
+             decltype
+             deleted_functions
+             func_identifier
+             long_long
+             rvalue_references
+             sizeof_member
+             static_assert
+             variadic_templates)
+    endif ()
+    if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 3.0.0)
+        # FreeBSD 9.0 and 10.0 both identify as Clang 3.0, but one has -std=c++0x,
+        # the other has -stc=c++11.
+        set(_compiler_unknown_flag TRUE)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3)
+         set(_expected_cxx11_flag "-std=c++11")
+         list(APPEND _expected_features
+             defaulted_functions
+             delegating_constructors
+             nullptr)
+    endif ()
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
+         set(_expected_cxx11_flag "-std=c++11")
+         list(APPEND _expected_features
+             cstdint_header
+             initializer_list)
+    endif ()
+    # Clang supports lambda since 3.1, but at least the version shipped with
+    # MacOS 10.7 crashes with our testcase, so this support wouldn't be reliable.
+    if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
+         set(_expected_cxx11_flag "-std=c++11")
+         list(APPEND _expected_features
+             lambda)
+    endif ()
+else ()
+    message(STATUS "CTEST_FULL_OUTPUT")
+    message(WARNING "Your C++ compiler configuration is not in the list of known configurations")
+    set(_compiler_unknown_features TRUE)
+    set(_compiler_unknown_flag TRUE)
+endif ()
+
+find_package(CXXFeatures)
+
+unset(_send_logs)
+
+foreach (flag IN LISTS _all_cxx_features)
+    list(FIND _expected_features "${flag}" _flag_index)
+    set(_full_flag CXXFeatures_${flag}_FOUND)
+    if (${_full_flag})
+        add_definitions("-D${_full_flag}")
+        message(STATUS "Compiler C++ support flag ${_full_flag} set")
+        if (_flag_index EQUAL -1 AND NOT _compiler_unknown_features)
+            list(FIND _header_on_features "${flag}" _flag_index)
+            if (_flag_index EQUAL -1)
+                message(WARNING "C++ feature '${flag}' was detected, but not expected")
+                set(_compiler_unknown_flag TRUE)
+            else ()
+                message(STATUS "C++ feature '${flag}' was detected because of additional header present")
+            endif ()
+        endif ()
+    else ()
+        if (NOT _flag_index EQUAL -1)
+            list(FIND _header_off_features "${flag}" _flag_index)
+            if (_flag_index EQUAL -1)
+                message(SEND_ERROR "Expected C++ feature '${flag}' not detected")
+            else ()
+                message(WARNING "Expected C++ feature '${flag}' not detected, support probably missing in library")
+            endif ()
+            set(_send_logs TRUE)
+        endif ()
+    endif ()
+endforeach (flag)
+
+# Variables must be expanded here so it still works if both are empty.
+if (NOT "${CXX11_COMPILER_FLAGS}" STREQUAL "${_expected_cxx11_flag}")
+    if (_compiler_unknown_flag)
+        message(WARNING    "Found C++11 flag '${CXX11_COMPILER_FLAGS}' but expected '${_expected_cxx11_flag}'")
+    else ()
+        message(SEND_ERROR "Found C++11 flag '${CXX11_COMPILER_FLAGS}' but expected '${_expected_cxx11_flag}'")
+        set(_send_logs TRUE)
+    endif ()
+endif ()
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
+add_executable(FindCXXFeatures cxxfeatures.cxx)
+
+enable_testing()
+if (NOT CROSS_COMPILING)
+    add_test(NAME FindCXXFeatures COMMAND FindCXXFeatures)
+endif ()
+
+if (_send_logs)
+    if (EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log")
+        file(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log" _output_log)
+        message(STATUS "-=-=-= Compiler output log:\n${_output_log}\n")
+    endif ()
+    if (EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log")
+        file(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log" _error_log)
+        message(STATUS "-=-=-= Compiler error log:\n${_error_log}\n")
+    endif ()
+endif ()
diff --git a/Tests/Module/FindCXXFeatures/cxxfeatures.cxx b/Tests/Module/FindCXXFeatures/cxxfeatures.cxx
new file mode 100644
index 0000000..5a3c72f
--- /dev/null
+++ b/Tests/Module/FindCXXFeatures/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 !!nix;
+}

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

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list