[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Using C++ conditionnally
From: |
Timothée Lecomte |
Subject: |
Using C++ conditionnally |
Date: |
Tue, 2 May 2006 02:44:54 +0200 (CEST) |
User-agent: |
SquirrelMail/1.4.4 |
Hi all !
I have written a so-called terminal for gnuplot [1], based on wxWidgets
[2] among other libraries.
[1] http://www.gnuplot.info
[2] http://www.wxwidgets.org
gnuplot is written in C, wxWidgets is a gui library written in C++, and
the terminal is supposed to be compiled optionally.
I had to add AC_PROG_CXX and AC_PROG_CXXCPP to the configure.in file. As
many of you may know, they should not be called conditionally, so the
script do call them unconditionally.
But, of course, users should still be able to compile gnuplot if they
don't have any C++ compiler. In this case, the macro AC_PROG_CXX does not
fail, but sets by default CXX to g++, even if it is not present, so that
automake will finally think that the project contains some C++ files, and
use g++ to link the object files. .... And there it fails.
So I did the following :
[...]
dnl wxWidgets terminal needs C++
dnl These tests cannot be called conditionally.
dnl However, even if there is no C++ compiler on the system,
dnl autoconf will set CXX as g++ : this must be reverted.
AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG_PUSH([C++])
AC_MSG_CHECKING(whether $CXX is actually working)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <iostream>]],
[[const char hw[] = "Hello, World\n"; std::cout << hw;]])],
[AC_MSG_RESULT([yes])
working_cxx=yes],
[AC_MSG_RESULT([no])
working_cxx=no
CXX=$CC ])
AC_LANG_POP([C++])
AC_ARG_ENABLE(wxwidgets, [ --disable-wxwidgets wxWidgets terminal
(default enabled)], enable_wxwidgets=no, enable_wxwidgets=yes)
if test "${enable_wxwidgets}" = yes
then
dnl variable used to determine if all checks pass
enable_wxwidgets_ok=yes
dnl Check for the C++ compiler
if test "${working_cxx}" = "no"; then
AC_MSG_WARN([No C++ compiler found. The wxWidgets terminal will
not be
compiled.])
enable_wxwidgets_ok=no
fi
fi
[...]
Can you comment on this, and tell me if it is sure enough ? It works for
me (autoconf 2.59, I tried it by renaming g++ and c++ to somethings else),
but I would like to be sure that it will work on future autoconf versions.
Or is there a smarter way to do it ?
Thank you for the great work done on the autotools.
Best regards,
Timothée Lecomte
- Using C++ conditionnally,
Timothée Lecomte <=