2 dnl Copyright (C) 2002-2003, 2005, 2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
9 # Sets CXX_CHOICE to 'yes' or 'no', depending on the preferred use of C++.
10 # The default is 'yes'. If the configure.ac contains a definition of the
11 # macro gl_CXX_CHOICE_DEFAULT_NO, then the default is 'no'. In both cases,
12 # the user can change the value by passing the option --disable-cxx or
13 # --enable-cxx, respectively.
15 AC_DEFUN([gl_CXX_CHOICE],
17 AC_MSG_CHECKING([whether to use C++])
18 dnl It would be so nice if plus signs were supported in AC_ARG_ENABLE.
19 dnl Feature request submitted on 2010-03-13.
20 m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
22 [ --enable-cxx also build C++ sources],
23 [CXX_CHOICE="$enableval"],
26 [ --disable-cxx do not build C++ sources],
27 [CXX_CHOICE="$enableval"],
29 AC_MSG_RESULT([$CXX_CHOICE])
30 AC_SUBST([CXX_CHOICE])
33 # gl_PROG_ANSI_CXX([ANSICXX_VARIABLE], [ANSICXX_CONDITIONAL])
34 # Sets ANSICXX_VARIABLE to the name of a sufficiently ANSI C++ compliant
35 # compiler, or to ":" if none is found.
36 # Defines the Automake condition ANSICXX_CONDITIONAL to true if such a compiler
37 # was found, or to false if not.
39 AC_DEFUN([gl_PROG_ANSI_CXX],
41 AC_REQUIRE([gl_CXX_CHOICE])
42 m4_if([$1], [CXX], [],
44 if test "$CXX_CHOICE" = no; then
47 if test -z "$CXX"; then
48 if test -n "$CCC"; then
52 [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
56 if test "$CXX" != ":"; then
57 dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
59 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
61 AC_ARG_VAR([CXX], [C++ compiler command])
62 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])
63 echo 'int main () { return 0; }' > conftest.$ac_ext
64 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
65 gl_cv_prog_ansicxx_works=yes
66 if (./conftest; exit) 2>/dev/null; then
67 gl_cv_prog_ansicxx_cross=no
69 gl_cv_prog_ansicxx_cross=yes
72 gl_cv_prog_ansicxx_works=no
76 AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
77 if test $gl_cv_prog_ansicxx_works = no; then
80 dnl Test for namespaces.
81 dnl We don't bother supporting pre-ANSI-C++ compilers.
82 AC_MSG_CHECKING([whether the C++ compiler supports namespaces])
84 cat <<EOF > conftest.$ac_ext
86 namespace test { using namespace std; }
88 int main () { return 0; }
90 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
91 gl_cv_prog_ansicxx_namespaces=yes
93 gl_cv_prog_ansicxx_namespaces=no
97 AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
98 if test $gl_cv_prog_ansicxx_namespaces = no; then
103 m4_if([$1], [CXX], [],
108 AM_CONDITIONAL([$2], [test "$$1" != ":"])
110 dnl This macro invocation resolves an automake error:
111 dnl /usr/local/share/automake-1.11/am/depend2.am: am__fastdepCXX does not appear in AM_CONDITIONAL
112 dnl /usr/local/share/automake-1.11/am/depend2.am: The usual way to define `am__fastdepCXX' is to add `AC_PROG_CXX'
113 dnl /usr/local/share/automake-1.11/am/depend2.am: to `configure.ac' and run `aclocal' and `autoconf' again.
114 _AM_DEPENDENCIES([CXX])