New module 'ansi-c++-opt'.
[pspp] / m4 / ansi-c++.m4
1 # ansi-c++.m4 serial 2
2 dnl Copyright (C) 2002-2003, 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.
6
7 dnl From Bruno Haible.
8
9 # gl_PROG_ANSI_CXX([ANSICXX_VARIABLE], [ANSICXX_CONDITIONAL])
10 # Sets ANSICXX_VARIABLE to the name of a sufficiently ANSI C++ compliant
11 # compiler, or to ":" if none is found.
12 # Defines the Automake condition ANSICXX_CONDITIONAL to true if such a compiler
13 # was found, or to false if not.
14
15 AC_DEFUN([gl_PROG_ANSI_CXX],
16 [
17   m4_if([$1], [CXX], [],
18     [gl_save_CXX="$CXX"])
19   if test -z "$CXX"; then
20     if test -n "$CCC"; then
21       CXX="$CCC"
22     else
23       AC_CHECK_PROGS([CXX], [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC], [:])
24     fi
25   fi
26   if test "$CXX" != ":"; then
27     dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
28     dnl upon failure.
29     AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
30     AC_LANG_PUSH([C++])
31     AC_ARG_VAR([CXX], [C++ compiler command])
32     AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])
33     echo 'int main () { return 0; }' > conftest.$ac_ext
34     if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
35       gl_cv_prog_ansicxx_works=yes
36       if (./conftest; exit) 2>/dev/null; then
37         gl_cv_prog_ansicxx_cross=no
38       else
39         gl_cv_prog_ansicxx_cross=yes
40       fi
41     else
42       gl_cv_prog_ansicxx_works=no
43     fi
44     rm -fr conftest*
45     AC_LANG_POP([C++])
46     AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
47     if test $gl_cv_prog_ansicxx_works = no; then
48       CXX=:
49     else
50       dnl Test for namespaces.
51       dnl We don't bother supporting pre-ANSI-C++ compilers.
52       AC_MSG_CHECKING([whether the C++ compiler supports namespaces])
53       AC_LANG_PUSH([C++])
54       cat <<EOF > conftest.$ac_ext
55 #include <iostream>
56 namespace test { using namespace std; }
57 std::ostream* ptr;
58 int main () { return 0; }
59 EOF
60       if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
61         gl_cv_prog_ansicxx_namespaces=yes
62       else
63         gl_cv_prog_ansicxx_namespaces=no
64       fi
65       rm -fr conftest*
66       AC_LANG_POP([C++])
67       AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
68       if test $gl_cv_prog_ansicxx_namespaces = no; then
69         CXX=:
70       fi
71     fi
72   fi
73   m4_if([$1], [CXX], [],
74     [$1="$CXX"
75      CXX="$gl_save_CXX"])
76   AC_SUBST([$1])
77
78   AM_CONDITIONAL([$2], [test "$$1" != ":"])
79
80   dnl This macro invocation resolves an automake error:
81   dnl /usr/local/share/automake-1.11/am/depend2.am: am__fastdepCXX does not appear in AM_CONDITIONAL
82   dnl /usr/local/share/automake-1.11/am/depend2.am:   The usual way to define `am__fastdepCXX' is to add `AC_PROG_CXX'
83   dnl /usr/local/share/automake-1.11/am/depend2.am:   to `configure.ac' and run `aclocal' and `autoconf' again.
84   _AM_DEPENDENCIES([CXX])
85 ])