source: filezilla/trunk/fuentes/m4/cxx_compile_stdcxx_14.m4 @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 5.5 KB
Line 
1# This is based on AX_CXX_COMPILE_STDCXX_11 from the Autoconf archive
2#
3# SYNOPSIS
4#
5#   CXX_COMPILE_STDCXX_14([ext|noext],[mandatory|optional])
6#
7# DESCRIPTION
8#
9#   Check for baseline language coverage in the compiler for the C++14
10#   standard; if necessary, add switches to CXXFLAGS to enable support.
11#
12#   The first argument, if specified, indicates whether you insist on an
13#   extended mode (e.g. -std=gnu++14) or a strict conformance mode (e.g.
14#   -std=c++14).  If neither is specified, you get whatever works, with
15#   preference for an extended mode.
16#
17#   The second argument, if specified 'mandatory' or if left unspecified,
18#   indicates that baseline C++14 support is required and that the macro
19#   should error out if no mode with that support is found.  If specified
20#   'optional', then configuration proceeds regardless, after defining
21#   HAVE_CXX14 if and only if a supporting mode is found.
22#
23# LICENSE
24#
25#   Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
26#   Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
27#   Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
28#   Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
29#   Copyright (c) 2015 Tim Kosse <tim.kosse@filezilla-project.org>
30#
31#   Copying and distribution of this file, with or without modification, are
32#   permitted in any medium without royalty provided the copyright notice
33#   and this notice are preserved. This file is offered as-is, without any
34#   warranty.
35
36#serial 10
37
38m4_define([_CXX_COMPILE_STDCXX_14_testbody], [[
39  #include <memory>
40
41  bool make_unique_test() {
42    auto p = std::make_unique<int>(14);
43    return static_cast<bool>(p);
44  }
45
46  // Also test some C++11 stuff just to be sure
47 
48  #include <unordered_map>
49  template <typename T>
50  struct umt {
51    std::unordered_map<int, T> map;
52  };   
53
54  template <typename T>
55    struct check
56    {
57      static_assert(sizeof(int) <= sizeof(T), "not big enough");
58    };
59
60    struct Base {
61    virtual void f() {}
62    };
63    struct Child : public Base {
64    virtual void f() override {}
65    };
66
67    typedef check<check<bool>> right_angle_brackets;
68
69    int a;
70    decltype(a) b;
71
72    typedef check<int> check_type;
73    check_type c;
74    check_type&& cr = static_cast<check_type&&>(c);
75
76    auto d = a;
77    auto l = [](){};
78    // Prevent Clang error: unused variable 'l' [-Werror,-Wunused-variable]
79    struct use_l { use_l() { l(); } };
80
81    // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
82    // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this
83    namespace test_template_alias_sfinae {
84        struct foo {};
85
86        template<typename T>
87        using member = typename T::member_type;
88
89        template<typename T>
90        void func(...) {}
91
92        template<typename T>
93        void func(member<T>*) {}
94
95        void test();
96
97        void test() {
98            func<foo>(0);
99        }
100    }
101]])
102
103AC_DEFUN([CXX_COMPILE_STDCXX_14], [dnl
104  m4_if([$1], [], [],
105        [$1], [ext], [],
106        [$1], [noext], [],
107        [m4_fatal([invalid argument `$1' to CXX_COMPILE_STDCXX_14])])dnl
108  m4_if([$2], [], [cxx_compile_cxx14_required=true],
109        [$2], [mandatory], [cxx_compile_cxx14_required=true],
110        [$2], [optional], [cxx_compile_cxx14_required=false],
111        [m4_fatal([invalid second argument `$2' to CXX_COMPILE_STDCXX_14])])
112  AC_LANG_PUSH([C++])dnl
113  ac_success=no
114  AC_CACHE_CHECK(whether $CXX supports C++14 features by default,
115  _cv_cxx_compile_cxx14,
116  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_CXX_COMPILE_STDCXX_14_testbody])],
117    [_cv_cxx_compile_cxx14=yes],
118    [_cv_cxx_compile_cxx14=no])])
119  if test x$_cv_cxx_compile_cxx14 = xyes; then
120    ac_success=yes
121  fi
122
123  m4_if([$1], [noext], [], [dnl
124  if test x$ac_success = xno; then
125    for switch in -std=gnu++14 -std=gnu++1y; do
126      cachevar=AS_TR_SH([_cv_cxx_compile_cxx14_$switch])
127      AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
128                     $cachevar,
129        [ac_save_CXXFLAGS="$CXXFLAGS"
130         CXXFLAGS="$CXXFLAGS $switch"
131         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_CXX_COMPILE_STDCXX_14_testbody])],
132          [eval $cachevar=yes],
133          [eval $cachevar=no])
134         CXXFLAGS="$ac_save_CXXFLAGS"])
135      if eval test x\$$cachevar = xyes; then
136        CXXFLAGS="$CXXFLAGS $switch"
137        ac_success=yes
138        break
139      fi
140    done
141  fi])
142
143  m4_if([$1], [ext], [], [dnl
144  if test x$ac_success = xno; then
145    for switch in -std=c++14 -std=c++1y; do
146      cachevar=AS_TR_SH([_cv_cxx_compile_cxx14_$switch])
147      AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
148                     $cachevar,
149        [ac_save_CXXFLAGS="$CXXFLAGS"
150         CXXFLAGS="$CXXFLAGS $switch"
151         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_CXX_COMPILE_STDCXX_14_testbody])],
152          [eval $cachevar=yes],
153          [eval $cachevar=no])
154         CXXFLAGS="$ac_save_CXXFLAGS"])
155      if eval test x\$$cachevar = xyes; then
156        CXXFLAGS="$CXXFLAGS $switch"
157        ac_success=yes
158        break
159      fi
160    done
161  fi])
162  AC_LANG_POP([C++])
163  if test x$cxx_compile_cxx14_required = xtrue; then
164    if test x$ac_success = xno; then
165      AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
166    fi
167  else
168    if test x$ac_success = xno; then
169      HAVE_CXX14=0
170      AC_MSG_NOTICE([No compiler with C++14 support was found])
171    else
172      HAVE_CXX14=1
173      AC_DEFINE(HAVE_CXX14,1,
174                [define if the compiler supports basic C++14 syntax])
175    fi
176
177    AC_SUBST(HAVE_CXX14)
178  fi
179])
Note: See TracBrowser for help on using the repository browser.