ansi-c++.m4 4.34 KB
Newer Older
1
# ansi-c++.m4 serial 9
2
dnl Copyright (C) 2002-2003, 2005, 2010-2018 Free Software Foundation, Inc.
3 4 5 6 7 8
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl From Bruno Haible.

9
# Sets CXX_CHOICE to 'yes' or 'no', depending on the preferred use of C++.
10 11 12 13
# The default is 'yes'. If the configure.ac contains a definition of the
# macro gl_CXX_CHOICE_DEFAULT_NO, then the default is 'no'. In both cases,
# the user can change the value by passing the option --disable-cxx or
# --enable-cxx, respectively.
14 15 16 17

AC_DEFUN([gl_CXX_CHOICE],
[
  AC_MSG_CHECKING([whether to use C++])
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  dnl Plus signs are supported in AC_ARG_ENABLE starting with autoconf-2.66.
  m4_version_prereq([2.66],
    [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
       [AC_ARG_ENABLE([c++],
          [  --enable-c++            also build C++ sources],
          [CXX_CHOICE="$enableval"],
          [CXX_CHOICE=no])],
       [AC_ARG_ENABLE([c++],
          [  --disable-c++           do not build C++ sources],
          [CXX_CHOICE="$enableval"],
          [CXX_CHOICE=yes])])],
    [m4_ifdef([gl_CXX_CHOICE_DEFAULT_NO],
       [AC_ARG_ENABLE([cxx],
          [  --enable-cxx            also build C++ sources],
          [CXX_CHOICE="$enableval"],
          [CXX_CHOICE=no])],
       [AC_ARG_ENABLE([cxx],
          [  --disable-cxx           do not build C++ sources],
          [CXX_CHOICE="$enableval"],
          [CXX_CHOICE=yes])])])
38 39 40 41
  AC_MSG_RESULT([$CXX_CHOICE])
  AC_SUBST([CXX_CHOICE])
])

42 43
# gl_PROG_ANSI_CXX([ANSICXX_VARIABLE], [ANSICXX_CONDITIONAL])
# Sets ANSICXX_VARIABLE to the name of a sufficiently ANSI C++ compliant
44
# compiler, or to "no" if none is found.
45 46 47 48 49
# Defines the Automake condition ANSICXX_CONDITIONAL to true if such a compiler
# was found, or to false if not.

AC_DEFUN([gl_PROG_ANSI_CXX],
[
50
  AC_REQUIRE([gl_CXX_CHOICE])
51 52
  m4_if([$1], [CXX], [],
    [gl_save_CXX="$CXX"])
53
  if test "$CXX_CHOICE" = no; then
54
    CXX=no
55
  fi
56 57 58 59
  if test -z "$CXX"; then
    if test -n "$CCC"; then
      CXX="$CCC"
    else
60 61 62
      AC_CHECK_TOOLS([CXX],
                     [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
                     [:])
63 64
    fi
  fi
65
  if test "$CXX" != no; then
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    dnl Use a modified version of AC_PROG_CXX_WORKS that does not exit
    dnl upon failure.
    AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
    AC_LANG_PUSH([C++])
    AC_ARG_VAR([CXX], [C++ compiler command])
    AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])
    echo 'int main () { return 0; }' > conftest.$ac_ext
    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
      gl_cv_prog_ansicxx_works=yes
      if (./conftest; exit) 2>/dev/null; then
        gl_cv_prog_ansicxx_cross=no
      else
        gl_cv_prog_ansicxx_cross=yes
      fi
    else
      gl_cv_prog_ansicxx_works=no
    fi
    rm -fr conftest*
    AC_LANG_POP([C++])
    AC_MSG_RESULT([$gl_cv_prog_ansicxx_works])
    if test $gl_cv_prog_ansicxx_works = no; then
87
      CXX=no
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    else
      dnl Test for namespaces.
      dnl We don't bother supporting pre-ANSI-C++ compilers.
      AC_MSG_CHECKING([whether the C++ compiler supports namespaces])
      AC_LANG_PUSH([C++])
      cat <<EOF > conftest.$ac_ext
#include <iostream>
namespace test { using namespace std; }
std::ostream* ptr;
int main () { return 0; }
EOF
      if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
        gl_cv_prog_ansicxx_namespaces=yes
      else
        gl_cv_prog_ansicxx_namespaces=no
      fi
      rm -fr conftest*
      AC_LANG_POP([C++])
      AC_MSG_RESULT([$gl_cv_prog_ansicxx_namespaces])
      if test $gl_cv_prog_ansicxx_namespaces = no; then
108
        CXX=no
109 110 111 112 113 114 115 116
      fi
    fi
  fi
  m4_if([$1], [CXX], [],
    [$1="$CXX"
     CXX="$gl_save_CXX"])
  AC_SUBST([$1])

117
  AM_CONDITIONAL([$2], [test "$$1" != no])
118

119
  if test "$$1" != no; then
120 121
    dnl This macro invocation resolves an automake error:
    dnl /usr/local/share/automake-1.11/am/depend2.am: am__fastdepCXX does not appear in AM_CONDITIONAL
122 123
    dnl /usr/local/share/automake-1.11/am/depend2.am:   The usual way to define 'am__fastdepCXX' is to add 'AC_PROG_CXX'
    dnl /usr/local/share/automake-1.11/am/depend2.am:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
124 125 126 127
    _AM_DEPENDENCIES([CXX])
  else
    AM_CONDITIONAL([am__fastdepCXX], [false])
  fi
128
])