[Cmake-commits] CMake branch, next, updated. v2.8.12.2-1493-g52c0892

Brad King brad.king at kitware.com
Wed Feb 19 10:18:58 EST 2014


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  52c0892f9d73fef74da1fc321952001df25e2349 (commit)
       via  6ba5e39d54f7ecfeed7385b28e9f604bc1d9ff46 (commit)
      from  64c4708d66d8b0588b8031f1e98697490165dd8a (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=52c0892f9d73fef74da1fc321952001df25e2349
commit 52c0892f9d73fef74da1fc321952001df25e2349
Merge: 64c4708 6ba5e39
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed Feb 19 10:18:57 2014 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Feb 19 10:18:57 2014 -0500

    Merge topic 'cxx11' into next
    
    6ba5e39d Add FindCXXFeatures module to check for C++ features (#13842)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6ba5e39d54f7ecfeed7385b28e9f604bc1d9ff46
commit 6ba5e39d54f7ecfeed7385b28e9f604bc1d9ff46
Author:     Rolf Eike Beer <eike at sf-mail.de>
AuthorDate: Fri Aug 2 21:55:22 2013 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Feb 19 10:14:27 2014 -0500

    Add FindCXXFeatures module to check for C++ features (#13842)

diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 7a06be6..63d3de3 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -80,6 +80,7 @@ All Modules
    /module/FindBullet
    /module/FindBZip2
    /module/FindCABLE
+   /module/FindCXXFeatures
    /module/FindCoin3D
    /module/FindCUDA
    /module/FindCups
diff --git a/Help/module/FindCXXFeatures.rst b/Help/module/FindCXXFeatures.rst
new file mode 100644
index 0000000..328f8db
--- /dev/null
+++ b/Help/module/FindCXXFeatures.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindCXXFeatures.cmake
diff --git a/Modules/FindCXXFeatures.cmake b/Modules/FindCXXFeatures.cmake
new file mode 100644
index 0000000..389aef9
--- /dev/null
+++ b/Modules/FindCXXFeatures.cmake
@@ -0,0 +1,165 @@
+#.rst:
+# FindCXXFeatures
+# ---------------
+#
+# 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 8074a01..fe6cb58 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -365,6 +365,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:
 Help/manual/cmake-modules.7.rst                    |    1 +
 Help/module/FindCXXFeatures.rst                    |    1 +
 Modules/FindCXXFeatures.cmake                      |  165 ++++++++++
 Modules/FindCXXFeatures/cxx11-auto.cxx             |   11 +
 .../FindCXXFeatures/cxx11-auto_fail_compile.cxx    |    7 +
 .../FindCXXFeatures/cxx11-class_override_final.cxx |   21 ++
 .../cxx11-class_override_final_fail_compile.cxx    |   25 ++
 Modules/FindCXXFeatures/cxx11-constexpr.cxx        |   19 ++
 Modules/FindCXXFeatures/cxx11-cstdint_header.cxx   |   11 +
 Modules/FindCXXFeatures/cxx11-decltype.cxx         |   10 +
 .../FindCXXFeatures/cxx11-defaulted_functions.cxx  |   13 +
 .../cxx11-delegating_constructors.cxx              |   25 ++
 .../FindCXXFeatures/cxx11-deleted_functions.cxx    |   10 +
 .../cxx11-deleted_functions_fail_compile.cxx       |   18 ++
 Modules/FindCXXFeatures/cxx11-func_identifier.cxx  |   10 +
 Modules/FindCXXFeatures/cxx11-initializer_list.cxx |   28 ++
 Modules/FindCXXFeatures/cxx11-lambda.cxx           |    5 +
 Modules/FindCXXFeatures/cxx11-long_long.cxx        |    7 +
 Modules/FindCXXFeatures/cxx11-nullptr.cxx          |   19 ++
 .../FindCXXFeatures/cxx11-nullptr_fail_compile.cxx |    6 +
 .../FindCXXFeatures/cxx11-rvalue_references.cxx    |   57 ++++
 Modules/FindCXXFeatures/cxx11-sizeof_member.cxx    |   14 +
 Modules/FindCXXFeatures/cxx11-static_assert.cxx    |    5 +
 .../cxx11-static_assert_fail_compile.cxx           |    5 +
 .../FindCXXFeatures/cxx11-variadic_templates.cxx   |   23 ++
 Tests/CMakeLists.txt                               |    1 +
 Tests/Module/FindCXXFeatures/CMakeLists.txt        |  327 ++++++++++++++++++++
 Tests/Module/FindCXXFeatures/cxxfeatures.cxx       |   57 ++++
 28 files changed, 901 insertions(+)
 create mode 100644 Help/module/FindCXXFeatures.rst
 create mode 100644 Modules/FindCXXFeatures.cmake
 create mode 100644 Modules/FindCXXFeatures/cxx11-auto.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-auto_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-class_override_final.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-class_override_final_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-constexpr.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-cstdint_header.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-decltype.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-defaulted_functions.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-delegating_constructors.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-deleted_functions.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-deleted_functions_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-func_identifier.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-initializer_list.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-lambda.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-long_long.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-nullptr.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-nullptr_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-rvalue_references.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-sizeof_member.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-static_assert.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-static_assert_fail_compile.cxx
 create mode 100644 Modules/FindCXXFeatures/cxx11-variadic_templates.cxx
 create mode 100644 Tests/Module/FindCXXFeatures/CMakeLists.txt
 create mode 100644 Tests/Module/FindCXXFeatures/cxxfeatures.cxx


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list