From dabd530c922435b7e9301e23c77a661a315dbf18 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Wed, 18 Oct 2006 09:22:57 +0000 Subject: [PATCH] Enhance AT_WITH_QT. * autotroll.m4 (AT_WITH_QT): Take 3 arguments to tweak the build process of Qt apps. --- build-aux/autotroll.m4 | 121 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 98 insertions(+), 23 deletions(-) diff --git a/build-aux/autotroll.m4 b/build-aux/autotroll.m4 index 7fe705e..52bf88e 100644 --- a/build-aux/autotroll.m4 +++ b/build-aux/autotroll.m4 @@ -22,7 +22,11 @@ # DOCUMENTATION # # ------------- # -# Simply invoke AT_WITH_QT in your configure.ac. This will do the following: +# Simply invoke AT_WITH_QT in your configure.ac. AT_WITH_QT can take +# arguments which are documented in depth below. The default arguments are +# equivalant to the default .pro file generated by qmake. +# +# Invokving AT_WITH_QT will do the following: # - Add a --with-qt option to your configure # - Find qmake, moc and uic and save them in the make variables $(QMAKE), # $(MOC), $(UIC). @@ -57,11 +61,34 @@ # BUILT_SOURCES = lcdrange.moc.cpp # ------------------------------------------------------------------------- +# AT_WITH_QT([QT_modules], [QT_config], [QT_misc]) +# ------------------------------------------------ +# Enable Qt support and add an option --with-qt to the configure script. +# +# The QT_modules argument is optionnal and defines extra modules to enable or +# disable (it's equivalant to the QT variable in .pro files). Modules can be +# specified as follows: +# +# AT_WITH_QT => No argument -> No QT value. +# Qmake sets it to "core gui" by default. +# AT_WITH_QT([xml]) => QT += xml +# AT_WITH_QT([+xml]) => QT += xml +# AT_WITH_QT([-gui]) => QT -= gui +# AT_WITH_QT([xml -gui +sql svg]) => QT += xml sql svg +# QT -= gui +# +# The QT_config argument is also optionnal and follows the same convention as +# QT_modules. Instead of changing the QT variable, it changes the CONFIG +# variable, which is used to tweak configuration and compiler options. +# +# The last argument, QT_misc (also optionnal) will be copied as-is the .pro +# file used to guess how to compile Qt apps. You may use it to further tweak +# the build process of Qt apps if tweaking the QT or CONFIG variables isn't +# enough for you. AC_DEFUN([AT_WITH_QT], -[ - test x"$TROLL" != x && echo 'ViM rox emacs.' +[ test x"$TROLL" != x && echo 'ViM rox emacs.' - # Memo: AC_ARG_WITH(package, help-string, [if-given], [if-not-given]) +dnl Memo: AC_ARG_WITH(package, help-string, [if-given], [if-not-given]) AC_ARG_WITH([qt], [AS_HELP_STRING([--with-qt], [Path to Qt @<:@Look in PATH and /usr/local/Trolltech@:>@])], @@ -101,17 +128,18 @@ AC_DEFUN([AT_WITH_QT], fi AC_SUBST([QT_PATH]) + # Get ready to build a test-app with Qt. mkdir conftest.dir cd conftest.dir - cat >conftest.cpp <<_ASEOF -#include -#include -#include + cat >conftest.h <<_ASEOF +#include -class MyWidget : public QWidget +class Foo: public QObject { + Q_OBJECT; public: - MyWidget(QWidget *parent = 0); + Foo(); + ~Foo() {} public slots: void setValue(int value); signals: @@ -119,34 +147,54 @@ signals: private: int value_; }; +_ASEOF -MyWidget::MyWidget(QWidget *parent) - : QWidget(parent), value_ (42) + cat >conftest.cpp <<_ASEOF +#include "conftest.h" +Foo::Foo() + : value_ (42) { - QPushButton* quit = new QPushButton(tr("Quit"), this); - connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); + connect(this, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); } -void MyWidget::setValue(int value) +void Foo::setValue(int value) { value_ = value; } -int main(int argc, char **argv) +int main() { - QApplication app(argc, argv); - MyWidget widget; - widget.show(); - return app.exec(); + Foo f; } _ASEOF if $QMAKE -project; then :; else AC_MSG_ERROR([Calling $QMAKE -project failed.]) fi + + # Find the .pro file generated by qmake. + pro_file='conftest.dir.pro' + test -f $pro_file || pro_file=`echo *.pro` + if test -f "$pro_file"; then :; else + AC_MSG_ERROR([Can't find the .pro file generated by Qmake.]) + fi + +dnl Tweak the value of QT in the .pro if have been the 1st arg. +m4_ifval([$1], [_AT_TWEAK_PRO_FILE([QT], [$1])]) + +dnl Tweak the value of CONFIG in the .pro if have been given a 2nd arg. +m4_ifval([$2], [_AT_TWEAK_PRO_FILE([CONFIG], [$2])]) + +m4_ifval([$3], +[ # Add the extra-settings the user wants to set in the .pro + echo "$3" >>"$pro_file" +]) + + echo "$as_me:$LINENO: Invoking $QMAKE on $pro_file" >&AS_MESSAGE_LOG_FD + sed 's/^/| /' "$pro_file" >&AS_MESSAGE_LOG_FD + if $QMAKE; then :; else AC_MSG_ERROR([Calling $QMAKE failed.]) fi - # Try to compile a simple Qt app. AC_CACHE_CHECK([whether we can build a simple Qt app], [at_cv_qt_build], [at_cv_qt_build=ko @@ -155,8 +203,10 @@ _ASEOF at_cv_qt_build=ok else at_cv_qt_build=ko - echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD - cat conftest.cpp | sed 's/^/| /' >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: failed program was:" >&AS_MESSAGE_LOG_FD + sed 's/^/| /' conftest.h >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: failed program was:" >&AS_MESSAGE_LOG_FD + sed 's/^/| /' conftest.cpp >&AS_MESSAGE_LOG_FD fi ])dnl end: AC_CACHE_CHECK(at_cv_qt_build) @@ -209,3 +259,28 @@ _ASEOF cd .. rm -rf conftest.dir ]) + +# _AT_TWEAK_PRO_FILE(QT_VAR, VALUE) +# --------------------------- +# @internal. Tweak the variable QT_VAR in the .pro. +# VALUE is an IFS-separated list of value and each value is rewritten +# as follows: +# +value => QT_VAR += value +# -value => QT_VAR -= value +# value => QT_VAR += value +AC_DEFUN([_AT_TWEAK_PRO_FILE], +[ # Tweak the value of $1 in the .pro file for $2. + + qt_conf='' + for at_mod in $2; do + at_mod=`echo "$at_mod" | sed 's/^-//; tough + s/^+//; beef + :ough + s/^/$1 -= /;n + :eef + s/^/$1 += /'` + qt_conf="$qt_conf +$at_mod" + done + echo "$qt_conf" | sed 1d >>"$pro_file" +]) -- 2.11.4.GIT