Initial import to Git
[profile/ivi/common-api-dbus-runtime.git] / CommonAPI-DBus / m4 / ax_cxx_compile_stdcxx_11.m4
1 # ============================================================================
2 #  http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3 # ============================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_CXX_COMPILE_STDCXX_11([ext|noext])
8 #
9 # DESCRIPTION
10 #
11 #   Check for baseline language coverage in the compiler for the C++11
12 #   standard; if necessary, add switches to CXXFLAGS to enable support.
13 #   Errors out if no mode that supports C++11 baseline syntax can be found.
14 #   The argument, if specified, indicates whether you insist on an extended
15 #   mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -std=c++11).
16 #   If neither is specified, you get whatever works, with preference for an
17 #   extended mode.
18 #
19 # LICENSE
20 #
21 #   Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
22 #   Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
23 #
24 #   Copying and distribution of this file, with or without modification, are
25 #   permitted in any medium without royalty provided the copyright notice
26 #   and this notice are preserved. This file is offered as-is, without any
27 #   warranty.
28
29 #serial 1
30
31 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
32   template <typename T>
33     struct check
34     {
35       static_assert(sizeof(int) <= sizeof(T), "not big enough");
36     };
37
38     typedef check<check<bool>> right_angle_brackets;
39
40     int a;
41     decltype(a) b;
42
43     typedef check<int> check_type;
44     check_type c;
45     check_type&& cr = static_cast<check_type&&>(c);
46 ])
47
48 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
49   m4_if([$1], [], [],
50         [$1], [ext], [],
51         [$1], [noext], [],
52         [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
53   AC_LANG_ASSERT([C++])dnl
54   ac_success=no
55   AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
56   ax_cv_cxx_compile_cxx11,
57   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
58     [ax_cv_cxx_compile_cxx11=yes],
59     [ax_cv_cxx_compile_cxx11=no])])
60   if test x$ax_cv_cxx_compile_cxx11 = xyes; then
61     ac_success=yes
62   fi
63
64   m4_if([$1], [noext], [], [dnl
65   if test x$ac_success = xno; then
66     for switch in -std=gnu++11 -std=gnu++0x; do
67       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
68       AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
69                      $cachevar,
70         [ac_save_CXXFLAGS="$CXXFLAGS"
71          CXXFLAGS="$CXXFLAGS $switch"
72          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
73           [eval $cachevar=yes],
74           [eval $cachevar=no])
75          CXXFLAGS="$ac_save_CXXFLAGS"])
76       if eval test x\$$cachevar = xyes; then
77         CXXFLAGS="$CXXFLAGS $switch"
78         ac_success=yes
79         break
80       fi
81     done
82   fi])
83
84   m4_if([$1], [ext], [], [dnl
85   if test x$ac_success = xno; then
86     for switch in -std=c++11 -std=c++0x; do
87       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
88       AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
89                      $cachevar,
90         [ac_save_CXXFLAGS="$CXXFLAGS"
91          CXXFLAGS="$CXXFLAGS $switch"
92          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
93           [eval $cachevar=yes],
94           [eval $cachevar=no])
95          CXXFLAGS="$ac_save_CXXFLAGS"])
96       if eval test x\$$cachevar = xyes; then
97         CXXFLAGS="$CXXFLAGS $switch"
98         ac_success=yes
99         break
100       fi
101     done
102   fi])
103
104   if test x$ac_success = xno; then
105     AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
106   fi
107 ])