root/mpich2/branches/dev/kumudb/confdb/aclocal_cxx.m4 @ 4870

Revision 4870, 8.8 KB (checked in by kumudb, 5 months ago)

Merge from trunk to kumudb r4748:r4869

Line 
1dnl
2dnl C++ macros
3dnl
4dnl Many compilers generate directories that hold information while compiling
5dnl and using templates.  This definition attempts to find their names (so
6dnl that they can be cleaned later).
7dnl
8dnl This was inspired by similar code in the MPI-C++ distribution from
9dnl the University of Notre Dame.
10dnl PAC_PROG_CXX_TEMPLATE_DIR(dirname)
11dnl sets dirname to the name of the template directory, or to empty
12dnl if it can not be determined.
13AC_DEFUN([PAC_PROG_CXX_TEMPLATE_DIR],[
14AC_CACHE_CHECK([for C++ template repository directory name],
15pac_cv_cxx_template_dir,[
16mkdir conftest_dir
17cd conftest_dir
18AC_LANG_SAVE
19AC_LANG_CPLUSPLUS
20cat > conftest_1.h <<EOF
21template <class T>
22class foo {
23public:
24   foo( T in ) : data( in ) { in.member(1); };
25   void member( int i );
26private:
27   T data;
28};
29class bar {
30public:
31   bar( int i ) { data = i; };
32   void member( int i ) { data = data + i; };
33private:
34   int data;
35};
36EOF
37cat > conftest_1.${ac_ext} <<EOF
38#include "conftest_1.h"
39
40void my_function( void )
41{
42   foo<bar> v1(6);
43   foo< foo<bar> > v2(v1);
44}
45EOF
46cat > conftest.${ac_ext} <<EOF
47#include "conftest_1.h"
48
49void my_function( void );
50
51template <class T>
52void foo<T>::member(int i)
53{
54 i++;
55}
56int main( int argc, char *argv[] )
57{
58    foo<bar> v1(6);
59    foo< foo<bar> > v2(v1);
60    my_function();
61    return 0;
62}
63EOF
64#
65ac_compile_special='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest_1.$ac_ext 1>&AC_FD_CC'
66if AC_TRY_EVAL(ac_compile_special) ; then
67    if AC_TRY_EVAL(ac_compile) ; then
68        # Look for a new directory
69        for file in `ls` ; do
70            if test -d "$file" -a "$file" != "." -a "$file" != ".." ; then
71                 pac_cv_cxx_template_dir="$pac_cv_cxx_template_dir $file"
72            fi
73        done
74        pac_cv_cxx_template_dir_name="$pac_cv_cxx_template_dir"
75        if test -z "$pac_cv_cxx_template_dir" ; then
76            pac_cv_cxx_template_dir="could not determine"
77        fi
78    else
79        echo "configure: failed program was:" >&AC_FD_CC
80        cat conftest.$ac_ext >&AC_FD_CC
81        pac_cv_cxx_template_dir="could not determine"
82    fi
83else
84    echo "configure: failed program was:" >&AC_FD_CC
85    cat conftest_1.$ac_ext >&AC_FD_CC
86    pac_cv_cxx_template_dir="templates not supported"
87fi
88cd ..
89#rm -rf conftest_dir
90AC_LANG_RESTORE
91])
92$1="$pac_cv_cxx_template_dir_name"
93])
94#
95# This is a replacement that checks that FAILURES are signaled as well
96# (later configure macros look for the .o file, not just success from the
97# compiler, but they should not HAVE to
98#
99AC_DEFUN([PAC_PROG_CXX_WORKS],
100[AC_PROG_CXX_WORKS
101AC_MSG_CHECKING([whether the C++ compiler sets its return status correctly])
102AC_LANG_SAVE
103AC_LANG_CXX
104AC_TRY_COMPILE(,[int a = bzzzt;],notbroken=no,notbroken=yes)
105AC_MSG_RESULT($notbroken)
106if test "$notbroken" = "no" ; then
107    AC_MSG_ERROR([installation or configuration problem: C++ compiler does not
108correctly set error code when a fatal error occurs])
109fi
110])
111dnl
112dnl This is from crypt.to/autoconf-archive, slightly modified.
113dnl It defines bool as int if it is not availalbe
114dnl
115AC_DEFUN([AC_CXX_BOOL],
116[AC_CACHE_CHECK(whether the compiler recognizes bool as a built-in type,
117ac_cv_cxx_bool,
118[AC_LANG_SAVE
119 AC_LANG_CPLUSPLUS
120 AC_TRY_COMPILE([
121int f(int  x){return 1;}
122int f(char x){return 1;}
123int f(bool x){return 1;}
124],[bool b = true; return f(b);],
125 ac_cv_cxx_bool=yes, ac_cv_cxx_bool=no)
126 AC_LANG_RESTORE
127])
128if test "$ac_cv_cxx_bool" != yes; then
129  AC_DEFINE(bool,int,[define if bool is a built-in type])
130fi
131])
132
133dnl
134dnl This is from crypt.to/autoconf-archive, slightly modified (name defined)
135dnl
136AC_DEFUN([AC_CXX_EXCEPTIONS],
137[AC_CACHE_CHECK(whether the compiler supports exceptions,
138ac_cv_cxx_exceptions,
139[AC_LANG_SAVE
140 AC_LANG_CPLUSPLUS
141 AC_TRY_COMPILE(,[try { throw  1; } catch (int i) { return i; }],
142 ac_cv_cxx_exceptions=yes, ac_cv_cxx_exceptions=no)
143 AC_LANG_RESTORE
144])
145if test "$ac_cv_cxx_exceptions" = yes; then
146  AC_DEFINE(HAVE_CXX_EXCEPTIONS,,[define if the compiler supports exceptions])
147fi
148])
149
150dnl
151dnl This is from crypt.to/autoconf-archive, slightly modified (name defined)
152dnl
153AC_DEFUN([AC_CXX_HAVE_COMPLEX],
154[AC_CACHE_CHECK(whether the C++ compiler has complex<T>,
155ac_cv_cxx_have_complex,
156[AC_REQUIRE([AC_CXX_NAMESPACES])
157 AC_LANG_SAVE
158 AC_LANG_CPLUSPLUS
159 AC_TRY_COMPILE([#include <complex>
160#ifdef HAVE_NAMESPACES
161using namespace std;
162#endif],[complex<float> a; complex<double> b; return 0;],
163 ac_cv_cxx_have_complex=yes, ac_cv_cxx_have_complex=no)
164 AC_LANG_RESTORE
165])
166if test "$ac_cv_cxx_have_complex" = yes; then
167  AC_DEFINE(HAVE_CXX_COMPLEX,,[define if the C++ compiler has complex<T>])
168fi
169])
170dnl
171dnl This is from crypt.to/autoconf-archive
172dnl
173AC_DEFUN([AC_CXX_NAMESPACES],
174[AC_CACHE_CHECK(whether the compiler implements namespaces,
175ac_cv_cxx_namespaces,
176[AC_LANG_SAVE
177 AC_LANG_CPLUSPLUS
178 AC_TRY_COMPILE([namespace Outer { namespace Inner { int i = 0; }}],
179                [using namespace Outer::Inner; return i;],
180 ac_cv_cxx_namespaces=yes, ac_cv_cxx_namespaces=no)
181 AC_LANG_RESTORE
182])
183if test "$ac_cv_cxx_namespaces" = yes; then
184  AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces])
185fi
186])
187dnl
188dnl Some compilers support namespaces but don't know about std
189dnl
190AC_DEFUN([AC_CXX_NAMESPACE_STD],
191[AC_REQUIRE([AC_CXX_NAMESPACES])
192AC_CACHE_CHECK(whether the compiler implements the namespace std,
193ac_cv_cxx_namespace_std,
194[ac_cv_cxx_namespace_std=no
195if test "$ac_cv_cxx_namespaces" = yes ; then
196   AC_LANG_SAVE
197   AC_LANG_CPLUSPLUS
198   AC_TRY_COMPILE([
199#include <iostream>
200using namespace std;],
201                [cout << "message\n";],
202 ac_cv_cxx_namespace_std=yes, ac_cv_cxx_namespace_std=no)
203   AC_LANG_RESTORE
204fi
205])
206if test "$ac_cv_cxx_namespace_std" = yes; then
207  AC_DEFINE(HAVE_NAMESPACE_STD,,[define if the compiler implements namespace std])
208fi
209])
210dnl
211dnl
212dnl
213dnl/*D
214dnl PAC_CXX_CHECK_COMPILER_OPTION - Check that a C++ compiler option is
215dnl accepted without warning messages
216dnl
217dnl Synopsis:
218dnl PAC_CXX_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
219dnl
220dnl Output Effects:
221dnl
222dnl If no actions are specified, a working value is added to 'CXXOPTIONS'
223dnl
224dnl Notes:
225dnl This is now careful to check that the output is different, since
226dnl some compilers are noisy.
227dnl
228dnl We are extra careful to prototype the functions in case compiler options
229dnl that complain about poor code are in effect.
230dnl
231dnl Because this is a long script, we have ensured that you can pass a
232dnl variable containing the option name as the first argument.
233dnl D*/
234AC_DEFUN([PAC_CXX_CHECK_COMPILER_OPTION],[
235AC_MSG_CHECKING([whether C++ compiler accepts option $1])
236save_CXXFLAGS="$CXXFLAGS"
237CXXFLAGS="$1 $CXXFLAGS"
238rm -f conftest.out
239echo 'int foo(void);int foo(void){return 0;}' > conftest2.cpp
240echo 'int main(void);int main(void){return 0;}' > conftest.cpp
241if ${CXX-g++} $save_CXXFLAGS $CPPFLAGS -o conftest conftest.cpp $LDFLAGS >conftest.bas 2>&1 ; then
242   if ${CXX-g++} $CXXFLAGS $CPPFLAGS -o conftest conftest.cpp $LDFLAGS >conftest.out 2>&1 ; then
243      if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
244         AC_MSG_RESULT(yes)
245         AC_MSG_CHECKING([whether routines compiled with $1 can be linked with ones compiled without $1])       
246         rm -f conftest.out
247         rm -f conftest.bas
248         if ${CXX-g++} -c $save_CXXFLAGS $CPPFLAGS conftest2.cpp >conftest2.out 2>&1 ; then
249            if ${CXX-g++} $CXXFLAGS $CPPFLAGS -o conftest conftest2.o conftest.cpp $LDFLAGS >conftest.bas 2>&1 ; then
250               if ${CXX-g++} $CXXFLAGS $CPPFLAGS -o conftest conftest2.o conftest.cpp $LDFLAGS >conftest.out 2>&1 ; then
251                  if diff -b conftest.out conftest.bas >/dev/null 2>&1 ; then
252                     AC_MSG_RESULT(yes)   
253                     CXXFLAGS="$save_CXXFLAGS"
254                     ifelse($2,,CXXOPTIONS="$CXXOPTIONS $1",$2)
255                  elif test -s conftest.out ; then
256                     cat conftest.out >&AC_FD_CC
257                     AC_MSG_RESULT(no)
258                     CXXFLAGS="$save_CXXFLAGS"
259                     $3
260                  else
261                     AC_MSG_RESULT(no)
262                     CXXFLAGS="$save_CXXFLAGS"
263                     $3
264                  fi 
265               else
266                  if test -s conftest.out ; then
267                     cat conftest.out >&AC_FD_CC
268                  fi
269                  AC_MSG_RESULT(no)
270                  CXXFLAGS="$save_CXXFLAGS"
271                  $3
272               fi
273            else
274               # Could not link with the option!
275               AC_MSG_RESULT(no)
276            fi
277         else
278            if test -s conftest2.out ; then
279               cat conftest2.out >&AC_FD_CC
280            fi
281            AC_MSG_RESULT(no)
282            CXXFLAGS="$save_CXXFLAGS"
283            $3
284         fi
285      else
286         cat conftest.out >&AC_FD_CC
287         AC_MSG_RESULT(no)
288         $3
289         CXXFLAGS="$save_CXXFLAGS"         
290      fi
291   else
292      AC_MSG_RESULT(no)
293      $3
294      if test -s conftest.out ; then cat conftest.out >&AC_FD_CC ; fi   
295      CXXFLAGS="$save_CXXFLAGS"
296   fi
297else
298    # Could not compile without the option!
299    AC_MSG_RESULT(no)
300fi
301rm -f conftest*
302])
Note: See TracBrowser for help on using the browser.