3 dnl Copyright (C) 2002-2003, 2005, 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
10 # Sets CXX_CHOICE to 'yes' or 'no', depending on the preferred use of C++.
11 # The default is 'yes'. If the configure.ac contains a definition of the
12 # macro gl_CXX_CHOICE_DEFAULT_NO, then the default is 'no'. In both cases,
13 # the user can change the value by passing the option --disable-cxx or
14 # --enable-cxx, respectively.
16 AC_DEFUN([gl_CXX_CHOICE],
18 AC_MSG_CHECKING([whether to use C++])
19 dnl Plus signs are supported in AC_ARG_ENABLE starting with autoconf-2.66.
20 m4_version_prereq([2.66],
21 [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
23 [ --enable-c++ also build C++ sources],
24 [CXX_CHOICE="$enableval"],
27 [ --disable-c++ do not build C++ sources],
28 [CXX_CHOICE="$enableval"],
30 [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
32 [ --enable-cxx also build C++ sources],
33 [CXX_CHOICE="$enableval"],
36 [ --disable-cxx do not build C++ sources],
37 [CXX_CHOICE="$enableval"],
39 AC_MSG_RESULT([$CXX_CHOICE])
40 AC_SUBST([CXX_CHOICE])
43 # gl_PROG_ANSI_CXX([ANSICXX_VARIABLE], [ANSICXX_CONDITIONAL])
44 # Sets ANSICXX_VARIABLE to the name of a sufficiently ANSI C++ compliant
45 # compiler, or to "no" if none is found.
46 # Defines the Automake condition ANSICXX_CONDITIONAL to true if such a compiler
47 # was found, or to false if not.
49 AC_DEFUN([gl_PROG_ANSI_CXX],
51 AC_REQUIRE([gl_CXX_CHOICE])
52 m4_if([$1], [CXX], [],
53 [gl_saved_CXX="$CXX"])
54 if test "$CXX_CHOICE" = no; then
57 if test -z "$CXX"; then
58 if test -n "$CCC"; then
62 [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
66 if test "$CXX" != no; then
67 dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
69 AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
71 AC_ARG_VAR([CXX], [C++ compiler command])
72 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])
73 echo 'int main () { return 0; }' > conftest.$ac_ext
74 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
75 gl_cv_prog_ansicxx_works=yes
76 if (./conftest; exit) 2>/dev/null; then
77 gl_cv_prog_ansicxx_cross=no
79 gl_cv_prog_ansicxx_cross=yes
82 gl_cv_prog_ansicxx_works=no
86 AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
87 if test $gl_cv_prog_ansicxx_works = no; then
90 dnl Test for namespaces.
91 dnl We don't bother supporting pre-ANSI-C++ compilers.
92 AC_MSG_CHECKING([whether the C++ compiler supports namespaces])
94 cat <<EOF > conftest.$ac_ext
96 namespace test { using namespace std; }
98 int main () { return 0; }
100 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
101 gl_cv_prog_ansicxx_namespaces=yes
103 gl_cv_prog_ansicxx_namespaces=no
107 AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
108 if test $gl_cv_prog_ansicxx_namespaces = no; then
113 m4_if([$1], [CXX], [],
115 CXX="$gl_saved_CXX"])
118 AM_CONDITIONAL([$2], [test "$$1" != no])
120 if test "$$1" != no; then
121 dnl This macro invocation resolves an automake error:
122 dnl /usr/local/share/automake-1.11/am/depend2.am: am__fastdepCXX does not appear in AM_CONDITIONAL
123 dnl /usr/local/share/automake-1.11/am/depend2.am: The usual way to define 'am__fastdepCXX' is to add 'AC_PROG_CXX'
124 dnl /usr/local/share/automake-1.11/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
125 _AM_DEPENDENCIES([CXX])
126 dnl Determine a good default for the CXXFLAGS variable.
128 _AC_LANG_COMPILER_GNU
129 if test $ac_compiler_gnu = yes; then
137 AM_CONDITIONAL([am__fastdepCXX], [false])
142 # Sets CXX to the name of a sufficiently ANSI C++ compliant compiler, or to
143 # "no" if none is found.
144 # Defines the Automake condition ANSICXX to true if such a compiler was found,
145 # or to false if not.
146 AC_DEFUN([gl_ANSI_CXX],
148 gl_PROG_ANSI_CXX([CXX], [ANSICXX])
149 dnl This line is needed in order to avoid trouble with Autoconf. It makes
150 dnl sure that Autoconf does not insert expansions of AC_PROG_CXX at random
151 dnl places. See <https://savannah.gnu.org/support/?110294>.
152 m4_provide([AC_PROG_CXX])