1 # ansi-c++.m4 serial 11
2 dnl Copyright (C) 2002-2003, 2005, 2010-2020 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 Plus signs are supported in AC_ARG_ENABLE starting with autoconf-2.66.
19 m4_version_prereq([2.66],
20 [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
22 [ --enable-c++ also build C++ sources],
23 [CXX_CHOICE="$enableval"],
26 [ --disable-c++ do not build C++ sources],
27 [CXX_CHOICE="$enableval"],
29 [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
31 [ --enable-cxx also build C++ sources],
32 [CXX_CHOICE="$enableval"],
35 [ --disable-cxx do not build C++ sources],
36 [CXX_CHOICE="$enableval"],
38 AC_MSG_RESULT([$CXX_CHOICE])
39 AC_SUBST([CXX_CHOICE])
42 # gl_PROG_ANSI_CXX([ANSICXX_VARIABLE], [ANSICXX_CONDITIONAL])
43 # Sets ANSICXX_VARIABLE to the name of a sufficiently ANSI C++ compliant
44 # compiler, or to "no" if none is found.
45 # Defines the Automake condition ANSICXX_CONDITIONAL to true if such a compiler
46 # was found, or to false if not.
48 AC_DEFUN([gl_PROG_ANSI_CXX],
50 AC_REQUIRE([gl_CXX_CHOICE])
51 m4_if([$1], [CXX], [],
53 if test "$CXX_CHOICE" = no; then
56 if test -z "$CXX"; then
57 if test -n "$CCC"; then
61 [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
65 if test "$CXX" != no; then
66 dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
68 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
70 AC_ARG_VAR([CXX], [C++ compiler command])
71 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])
72 echo 'int main () { return 0; }' > conftest.$ac_ext
73 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
74 gl_cv_prog_ansicxx_works=yes
75 if (./conftest; exit) 2>/dev/null; then
76 gl_cv_prog_ansicxx_cross=no
78 gl_cv_prog_ansicxx_cross=yes
81 gl_cv_prog_ansicxx_works=no
85 AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
86 if test $gl_cv_prog_ansicxx_works = no; then
89 dnl Test for namespaces.
90 dnl We don't bother supporting pre-ANSI-C++ compilers.
91 AC_MSG_CHECKING([whether the C++ compiler supports namespaces])
93 cat <<EOF > conftest.$ac_ext
95 namespace test { using namespace std; }
97 int main () { return 0; }
99 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
100 gl_cv_prog_ansicxx_namespaces=yes
102 gl_cv_prog_ansicxx_namespaces=no
106 AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
107 if test $gl_cv_prog_ansicxx_namespaces = no; then
112 m4_if([$1], [CXX], [],
117 AM_CONDITIONAL([$2], [test "$$1" != no])
119 if test "$$1" != no; then
120 dnl This macro invocation resolves an automake error:
121 dnl /usr/local/share/automake-1.11/am/depend2.am: am__fastdepCXX does not appear in AM_CONDITIONAL
122 dnl /usr/local/share/automake-1.11/am/depend2.am: The usual way to define 'am__fastdepCXX' is to add 'AC_PROG_CXX'
123 dnl /usr/local/share/automake-1.11/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
124 _AM_DEPENDENCIES([CXX])
125 dnl Determine a good default for the CXXFLAGS variable.
127 _AC_LANG_COMPILER_GNU
128 if test $ac_compiler_gnu = yes; then
136 AM_CONDITIONAL([am__fastdepCXX], [false])
141 # Sets CXX to the name of a sufficiently ANSI C++ compliant compiler, or to
142 # "no" if none is found.
143 # Defines the Automake condition ANSICXX to true if such a compiler was found,
144 # or to false if not.
145 AC_DEFUN([gl_ANSI_CXX],
147 gl_PROG_ANSI_CXX([CXX], [ANSICXX])