blob: 83e9ad3d6dba189daa4afb5d15f7cf841a2a1cb7 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001dnl Copyright (C) 1999-2005 Open Source Telecom Corporation.
2dnl Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3dnl
4dnl This program is free software; you can redistribute it and/or modify
5dnl it under the terms of the GNU General Public License as published by
6dnl the Free Software Foundation; either version 2 of the License, or
7dnl (at your option) any later version.
8dnl
9dnl This program is distributed in the hope that it will be useful,
10dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12dnl GNU General Public License for more details.
13dnl
14dnl You should have received a copy of the GNU General Public License
15dnl along with this program; if not, write to the Free Software
16dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17dnl
18dnl As a special exception to the GNU General Public License, if you
19dnl distribute this file as part of a program that contains a configuration
20dnl script generated by Autoconf, you may include it under the same
21dnl distribution terms that you use for the rest of that program.
22
23
24AC_DEFUN([OST_CXX_PROGRAMMING],[
25 AC_REQUIRE([OST_PROG_CC_POSIX])
26 AC_PROG_CPP
27 AC_PROG_CXX
28 AC_PROG_CXXCPP
29
30 dnl
31 dnl Check for common C++ portability problems
32 dnl
33
34 AC_LANG_SAVE
35 ac_save_CXXFLAGS="$CXXFLAGS"
36 CXXFLAGS=""
37 AC_LANG_CPLUSPLUS
38
39 dnl Check whether we have bool
40 AC_CACHE_CHECK(whether ${CXX} has built-in bool type,
41 ac_cv_cxx_bool_type,
42 AC_TRY_COMPILE(,
43 [bool b1=true; bool b2=false;],
44 ac_cv_cxx_bool_type=yes,
45 ac_cv_cxx_bool_type=no
46 )
47 )
48
49 if test $ac_cv_cxx_bool_type = yes ; then
50 AC_DEFINE(HAVE_BOOL_TYPE, [1], [have bool type])
51 fi
52
53 AC_LANG_RESTORE
54 CXXFLAGS="$ac_save_CXXFLAGS"
55 AH_BOTTOM([
56#ifndef HAVE_BOOL_TYPE
57typedef enum { true=1, false=0 } bool;
58#endif
59
60
61 ])
62])
63
64AC_DEFUN([OST_CXX_NEW_INIT],[
65AC_REQUIRE([OST_PROG_CC_POSIX])
66# AC_PROG_CPP
67# AC_PROG_CXX
68# AC_PROG_CXXCPP
69
70 dnl
71 dnl Check for common C++ portability problems
72 dnl
73
74 AC_LANG_SAVE
75 ac_save_CXXFLAGS="$CXXFLAGS"
76 CXXFLAGS=""
77 AC_LANG_CPLUSPLUS
78
79 dnl Check whether we have bool
80 AC_CACHE_CHECK([whether ${CXX} has new(size_t,void*)],
81 ac_cv_cxx_new_init,
82 AC_TRY_COMPILE([#include <new>
83#include <iostream>
84using namespace std;],
85 [int* p1 = new int();
86int* p2 = new (p1) int();
87return 0;],
88 ac_cv_cxx_new_init=yes,
89 ac_cv_cxx_new_init=no
90 )
91 )
92
93 if test $ac_cv_cxx_new_init = yes ; then
94 AC_DEFINE(CCXX_HAVE_NEW_INIT, [1], [have new with init])
95 fi
96
97 AC_LANG_RESTORE
98 CXXFLAGS="$ac_save_CXXFLAGS"
99 AH_BOTTOM([
100#ifdef CCXX_NAMESPACES
101#define USING(x) using namespace x;
102#else
103#define USING(x)
104#endif
105
106#ifdef __KCC
107#define KAI_NONSTD_IOSTREAM 1
108#endif
109 ])
110])
111
112AC_DEFUN([OST_CXX_ARRAYS],[
113 AC_REQUIRE([OST_CXX_PROGRAMMING])
114 dnl
115 dnl Determine C++ support for dynamic sized arrays in stack frame.
116 dnl
117
118 AC_LANG_SAVE
119 AC_LANG_CPLUSPLUS
120 ac_save_CXXFLAGS="$CXXFLAGS"
121 CXXFLAGS=""
122
123 AC_CACHE_CHECK(wheather dynamic arrays in stack frame,
124 ost_cv_cxx_array,
125 AC_TRY_COMPILE(,[
126 int x;
127 int y\[x\];
128 return 0;
129 ], ost_cv_cxx_array=no, ost_cv_array=yes)
130 )
131 if test "$ost_cv_cxx_array" = yes ; then
132 AC_DEFINE(HAVE_DYN_ARRAY, [1], [c++ dynamic arrays in stack frame])
133 fi
134 AC_LANG_RESTORE
135 CXXFLAGS="$ac_save_CXXFLAGS"
136])
137
138AC_DEFUN([OST_CXX_IOSTREAM],[
139 AC_REQUIRE([OST_CXX_PROGRAMMING])
140 dnl
141 dnl Determine kind of C++ iostream support.
142 dnl
143
144 AC_LANG_SAVE
145 ac_save_CXXFLAGS="$CXXFLAGS"
146 CXXFLAGS=""
147 AC_LANG_CPLUSPLUS
148 AC_CACHE_CHECK(wheather old style iostreams,
149 ost_cv_cxx_iostream,
150 AC_TRY_COMPILE([
151#include <iostream>
152using namespace std;
153
154class mystr : public streambuf, public iostream
155{
156 mystr();
157};
158
159mystr::mystr() : streambuf(), iostream((streambuf *)this)
160{
161}
162 ],[return 0;],
163 ost_cv_cxx_iostream=no,
164 ost_cv_cxx_iostream=yes
165 )
166 )
167 if test $ost_cv_cxx_iostream = yes ; then
168 AC_DEFINE(HAVE_OLD_IOSTREAM, [1], [old style iostreams])
169 fi
170 AC_CHECK_HEADERS(sstream)
171
172 AC_LANG_RESTORE
173 CXXFLAGS="$ac_save_CXXFLAGS"
174])
175
176AC_DEFUN([OST_CXX_NAMESPACE],[
177 AC_REQUIRE([OST_CXX_PROGRAMMING])
178
179 dnl
180 dnl Determine if C++ supports namespaces.
181 dnl
182
183 AC_LANG_SAVE
184 ac_save_CXXFLAGS="$CXXFLAGS"
185 CXXFLAGS=""
186 AC_LANG_CPLUSPLUS
187 AC_CACHE_CHECK(whether ${CXX} supports namespace,
188 ost_cv_cxx_namespace,
189 AC_TRY_COMPILE([
190#include <iostream>
191namespace Test { using namespace std; }],[return 0;],
192 ost_cv_cxx_namespace=yes,
193 ost_cv_cxx_namespace=no
194 )
195 )
196
197 if test "$ost_cv_cxx_namespace" = yes ; then
198 AC_DEFINE(CCXX_NAMESPACES, [1], [has c++ namespaces])
199 fi
200
201 AC_LANG_RESTORE
202 CXXFLAGS="$ac_save_CXXFLAGS"
203])
204
205AC_DEFUN([OST_CXX_MUTABLE],[
206 AC_REQUIRE([OST_CXX_PROGRAMMING])
207
208 dnl
209 dnl Determine if C++ supports mutable members.
210 dnl
211
212 AC_LANG_SAVE
213 ac_save_CXXFLAGS="$CXXFLAGS"
214 CXXFLAGS=""
215 AC_LANG_CPLUSPLUS
216
217 AC_CACHE_CHECK(whether ${CXX} supports mutable,
218 ost_cv_cxx_mutable,
219 AC_TRY_COMPILE([
220class t {mutable int i;};], [return 0;],
221 ost_cv_cxx_mutable=yes,
222 ost_cv_cxx_mutable=no
223 )
224 )
225
226 if test $ost_cv_cxx_mutable = no ; then
227 COMMON_FLAGS="$COMMON_FLAGS -Dmutable"
228 fi
229
230 AC_LANG_RESTORE
231 CXXFLAGS="$ac_save_CXXFLAGS"
232])
233
234AC_DEFUN([OST_CXX_NOEXCEPTIONS],[
235 AC_REQUIRE([OST_CXX_PROGRAMMING])
236
237 dnl
238 dnl Disable C++ exception handling whenever possible.
239 dnl
240
241 AC_LANG_SAVE
242 ac_save_CXXFLAGS="$CXXFLAGS"
243 CXXFLAGS=""
244 AC_LANG_CPLUSPLUS
245
246 dnl strip -fexceptions flag if used
247 optflags=$CXXFLAGS
248 if test ! -z "$optflags" ; then
249 CXXFLAGS=""
250 for opt in $optflags ; do
251 case $opt in
252 *rtti*)
253 ;;
254 *exceptions*)
255 ;;
256 *)
257 CXXFLAGS="$CXXFLAGS $opt"
258 ;;
259 esac
260 done
261 fi
262 AC_CACHE_CHECK(whether ${CXX} supports -fno-exceptions,
263 ac_cv_cxx_noexception_flag,[
264 echo 'void f(){}' >conftest.cpp
265 if test -z "`${CXX} -fno-exceptions -c conftest.cpp 2>&1`"; then
266 COMMON_FLAGS="$COMMON_FLAGS -fno-exceptions"
267 ac_cv_cxx_noexception_flag=yes
268 else
269 ac_cv_cxx_noexception_flag=no
270 fi
271 rm -f conftest*
272 ])
273
274 AC_CACHE_CHECK(whether ${CXX} supports -fno-rtti,
275 ac_cv_cxx_no_rtti_flag,[
276 echo '#include <sstream>' >conftest.cpp
277 echo 'void f(){}' >>conftest.cpp
278 if test -z "`${CXX} -fno-rtti -c conftest.cpp 2>&1`"; then
279 COMMON_FLAGS="$COMMON_FLAGS -fno-rtti"
280 ac_cv_cxx_no_rtti_flag=yes
281 else
282 ac_cv_cxx_no_rtti_flag=no
283 fi
284 rm -f conftest*
285 ])
286
287 AC_CACHE_CHECK(whether ${CXX} supports -fno-check-new,
288 ac_cv_cxx_no_check_new_flag,[
289 echo 'void f(){}' >conftest.cpp
290 if test -z "`${CXX} -fno-check-new -c conftest.cpp 2>&1`"; then
291 COMMON_FLAGS="$COMMON_FLAGS -fno-check-new"
292 ac_cv_cxx_no_check_new_flag=yes
293 else
294 ac_cv_cxx_no_check_new_flag=no
295 fi
296 rm -f conftest*
297 ])
298
299 AC_CACHE_CHECK(whether ${CXX} supports -finline,
300 ac_cv_cxx_inline_flag,[
301 echo 'void f(){}' >conftest.cpp
302 if test -z "`${CXX} -finline -c conftest.cpp 2>&1`"; then
303 COMMON_FLAGS="$COMMON_FLAGS -finline"
304 ac_cv_cxx_inline_flag=yes
305 else
306 ac_cv_cxx_inline_flag=no
307 fi
308 rm -f conftest*
309 ])
310
311
312 AC_LANG_RESTORE
313 CXXFLAGS="$ac_save_CXXFLAGS"
314])
315
316AC_DEFUN([OST_CXX_EXCEPTIONS],[
317 AC_REQUIRE([OST_CXX_PROGRAMMING])
318
319 dnl
320 dnl Enable C++ exception handling whenever possible.
321 dnl
322
323 AC_LANG_SAVE
324 ac_save_CXXFLAGS="$CXXFLAGS"
325 CXXFLAGS=""
326 AC_LANG_CPLUSPLUS
327
328 dnl strip -fno-exceptions flag if used
329 optflags=$CXXFLAGS
330 if test ! -z "$optflags" ; then
331 CXXFLAGS=""
332 for opt in $optflags ; do
333 case $opt in
334 *no-rtti*)
335 ;;
336 *omit-frame-pointer*)
337 ;;
338 *no-exceptions*)
339 ;;
340 *)
341 CXXFLAGS="$CXXFLAGS $opt"
342 ;;
343 esac
344 done
345 fi
346
347 dnl Check for exception handling
348 AC_CACHE_CHECK(whether ${CXX} supports -fhandle-exceptions,
349 ac_cv_cxx_exception_flag,[
350 echo 'void f(){}' >conftest.cpp
351 if test -z "`${CXX} -fhandle-exceptions -c conftest.cpp 2>&1`"; then
352 ac_cv_cxx_exception_flag=yes
353 COMMON_FLAGS="$COMMON_FLAGS -fhandle-exceptions"
354 else
355 ac_cv_cxx_exception_flag=no
356 fi
357 rm -f conftest*
358 ])
359
360 if test $ac_cv_cxx_exception_flag = "yes" ; then
361 ac_cv_cxx_exception_handling=yes
362 else
363 AC_CACHE_CHECK(whether ${CXX} supports exception handling,
364 ac_cv_cxx_exception_handling,
365 AC_TRY_COMPILE(
366 [void f(void)
367 {
368 throw "abc";
369 }
370 void g(void)
371 {
372 try {
373 f();
374 }
375 catch(char*){}
376 }
377 ],,
378 ac_cv_cxx_exception_handling=yes,
379 ac_cv_cxx_exception_handling=no
380 )
381 )
382 fi
383
384 if test $ac_cv_cxx_exception_handling = yes ; then
385 AC_DEFINE(CCXX_EXCEPTIONS, [1], [has c++ exception handling])
386 AC_CHECK_HEADERS(exception)
387 fi
388
389 AC_LANG_RESTORE
390 CXXFLAGS="$ac_save_CXXFLAGS"
391 AH_BOTTOM([
392#ifndef CCXX_EXCEPTIONS
393/* disable HAVE_EXCEPTION */
394#ifdef HAVE_EXCEPTION
395#undef HAVE_EXCEPTION
396#endif
397/* throw - replacement to throw an exception */
398#define THROW(x) abort()
399/* throw - replacement to declare an exception */
400#define THROWS(x)
401/* throw - for empty list */
402#define NEW_THROWS
403#define THROWS_EMPTY
404/*
405 * work around dangeling if/else combinations:
406 */
407#else
408#define THROW(x) throw x
409#define THROWS(x) throw(x)
410#define NEW_THROWS throw()
411#define THROWS_EMPTY throw()
412#endif
413
414 ])
415])
416