pthread-cond: Fix compilation error on native Windows.
[gnulib.git] / m4 / ansi-c++.m4
blob129f362e8a66d08de79c5ce275a2df7a05760a9c
1 # ansi-c++.m4
2 # serial 13
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.
8 dnl From Bruno Haible.
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],
22        [AC_ARG_ENABLE([c++],
23           [  --enable-c++            also build C++ sources],
24           [CXX_CHOICE="$enableval"],
25           [CXX_CHOICE=no])],
26        [AC_ARG_ENABLE([c++],
27           [  --disable-c++           do not build C++ sources],
28           [CXX_CHOICE="$enableval"],
29           [CXX_CHOICE=yes])])],
30     [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
31        [AC_ARG_ENABLE([cxx],
32           [  --enable-cxx            also build C++ sources],
33           [CXX_CHOICE="$enableval"],
34           [CXX_CHOICE=no])],
35        [AC_ARG_ENABLE([cxx],
36           [  --disable-cxx           do not build C++ sources],
37           [CXX_CHOICE="$enableval"],
38           [CXX_CHOICE=yes])])])
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
55     CXX=no
56   fi
57   if test -z "$CXX"; then
58     if test -n "$CCC"; then
59       CXX="$CCC"
60     else
61       AC_CHECK_TOOLS([CXX],
62                      [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
63                      [:])
64     fi
65   fi
66   if test "$CXX" != no; then
67     dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
68     dnl upon failure.
69     AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
70     AC_LANG_PUSH([C++])
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
78       else
79         gl_cv_prog_ansicxx_cross=yes
80       fi
81     else
82       gl_cv_prog_ansicxx_works=no
83     fi
84     rm -fr conftest*
85     AC_LANG_POP([C++])
86     AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
87     if test $gl_cv_prog_ansicxx_works = no; then
88       CXX=no
89     else
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])
93       AC_LANG_PUSH([C++])
94       cat <<EOF > conftest.$ac_ext
95 #include <iostream>
96 namespace test { using namespace std; }
97 std::ostream* ptr;
98 int main () { return 0; }
99 EOF
100       if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
101         gl_cv_prog_ansicxx_namespaces=yes
102       else
103         gl_cv_prog_ansicxx_namespaces=no
104       fi
105       rm -fr conftest*
106       AC_LANG_POP([C++])
107       AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
108       if test $gl_cv_prog_ansicxx_namespaces = no; then
109         CXX=no
110       fi
111     fi
112   fi
113   m4_if([$1], [CXX], [],
114     [$1="$CXX"
115      CXX="$gl_saved_CXX"])
116   AC_SUBST([$1])
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.
127     AC_LANG_PUSH([C++])
128     _AC_LANG_COMPILER_GNU
129     if test $ac_compiler_gnu = yes; then
130       GXX=yes
131     else
132       GXX=
133     fi
134     _AC_PROG_CXX_G
135     AC_LANG_POP([C++])
136   else
137     AM_CONDITIONAL([am__fastdepCXX], [false])
138   fi
141 # gl_ANSI_CXX
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])