1 dnl Autoconf support for C++
2 dnl Copyright (C) 1988 Eleftherios Gkioulekas <lf@amath.washington.edu>
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 3 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program; if not, write to the Free Software
16 dnl Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301, USA.
18 dnl As a special exception to the GNU General Public License, if you
19 dnl distribute this file as part of a program that contains a configuration
20 dnl script generated by Autoconf, you may include it under the same
21 dnl distribution terms that you use for the rest of that program.
23 # -----------------------------------------------------------------
24 # This macro should be called to configure your C++ compiler.
25 # When called, the macro does the following things:
26 # 1. It finds an appropriate C++ compiler
27 # If you passed the flag --with-cxx=foo, then it uses that
29 # 2. Checks whether the compiler accepts the -g
30 # ------------------------------------------------------------------
32 AC_DEFUN([LF_CONFIGURE_CXX],[
33 AC_REQUIRE([AC_PROG_CXX])dnl
34 AC_REQUIRE([AC_PROG_CXXCPP])dnl
38 # -----------------------------------------------------------------------
39 # This macro tests the C++ compiler for various portability problem.
40 # 1. Defines CXX_HAS_NO_BOOL if the compiler does not support the bool
42 # 2. Defines CXX_HAS_BUGGY_FOR_LOOPS if the compiler has buggy
43 # scoping for the for-loop
44 # 3. Defines USE_ASSERT if the user wants to use assertions
45 # -----------------------------------------------------------------------
48 AC_DEFUN([LF_CXX_PORTABILITY],[
51 dnl Check for common C++ portability problems
59 dnl Check whether we have bool
60 AC_MSG_CHECKING(whether C++ has bool)
61 AC_TRY_RUN([main() { bool b1=true; bool b2=false; }],
62 [ AC_MSG_RESULT(yes) ],
64 AC_DEFINE(CXX_HAS_NO_BOOL,[],[Define if C++ is missing bool type]) ],
65 [ AC_MSG_WARN(Don't cross-compile)]
68 dnl Test whether C++ has buggy for-loops
69 AC_MSG_CHECKING(whether C++ has buggy scoping in for-loops)
70 AC_TRY_COMPILE([#include <iostream.h>], [
71 for (int i=0;i<10;i++) { }
72 for (int i=0;i<10;i++) { }
73 ], [ AC_MSG_RESULT(no) ],
75 AC_DEFINE(CXX_HAS_BUGGY_FOR_LOOPS,[],[Define if for loop scoping is broken]) ])
77 dnl Test whether the user wants to enable assertions
78 AC_MSG_CHECKING(whether user wants assertions)
80 [ --disable-assert don't use cpp.h assert],
81 [ AC_DEFINE(NDEBUG,[],[Define to disable asserts (don't doit!)])
83 [ AC_MSG_RESULT(yes) ],
86 dnl Test whether C++ has std::isnan
87 AC_MSG_CHECKING(whether C++ has std::isnan)
88 AC_TRY_COMPILE([#include <cmath>], [
90 ], [ AC_MSG_RESULT(yes)
91 AC_DEFINE(CXX_HAS_STD_ISNAN,[],[Define if has std::isnan]) ],
92 [ AC_MSG_RESULT(no) ])
94 dnl Done with the portability checks
95 dnl AC_LANG_POP([C++])
99 AH_BOTTOM([// Workaround for compilers with buggy for-loop scoping
100 // That's quite a few compilers actually including recent versions of
101 // Dec Alpha cxx, HP-UX CC and SGI CC.
102 // The trivial "if" statement provides the correct scoping to the
105 #ifdef CXX_HAS_BUGGY_FOR_LOOPS
107 #define for if(1) for
111 AH_BOTTOM([// If the C++ compiler we use doesn't have bool, then
112 // the following is a near-perfect work-around.
113 // You must make sure your code does not depend on "int" and "bool"
114 // being two different types, in overloading for instance.
116 #ifdef CXX_HAS_NO_BOOL