1 # Build Qt apps with the autotools (Autoconf/Automake).
3 # This file is part of AutoTroll.
4 # Copyright (C) 2006 Benoit Sigoure <benoit.sigoure@lrde.epita.fr>
6 # AutoTroll is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 # Disclaimer: Never tested with anything else than Qt 4.2! Feedback welcome.
26 # Simply invoke AT_WITH_QT in your configure.ac. AT_WITH_QT can take
27 # arguments which are documented in depth below. The default arguments are
28 # equivalent to the default .pro file generated by qmake.
30 # Invoking AT_WITH_QT will do the following:
31 # - Add a --with-qt option to your configure
32 # - Find qmake, moc and uic and save them in the make variables $(QMAKE),
34 # - Save the path to Qt in $(QT_PATH)
35 # - Find the flags to use Qt, that is:
36 # * $(QT_DEFINES): -D's defined by qmake.
37 # * $(QT_CFLAGS): CFLAGS as defined by qmake (C?!)
38 # * $(QT_CXXFLAGS): CXXFLAGS as defined by qmake.
39 # * $(QT_INCPATH): -I's defined by qmake.
40 # * $(QT_CPPFLAGS): Same as $(QT_DEFINES) + $(QT_INCPATH)
41 # * $(QT_LFLAGS): LFLAGS defined by qmake.
42 # * $(QT_LDFLAGS): Same thing as $(QT_LFLAGS).
43 # * $(QT_LIBS): LIBS defined by qmake.
45 # You *MUST* invoke $(MOC) and/or $(UIC) where necessary. AutoTroll provides
46 # you with Makerules to ease this, here is a sample Makefile.am to use with
47 # AutoTroll which builds the code given in the chapter 7 of the Qt Tutorial:
48 # http://doc.trolltech.com/4.2/tutorial-t7.html
50 # -------------------------------------------------------------------------
51 # include $(top_srcdir)/build-aux/autotroll.mk
53 # ACLOCAL_AMFLAGS = -I build-aux
55 # bin_PROGRAMS = lcdrange
56 # lcdrange_SOURCES = lcdrange.cpp lcdrange.moc.cpp lcdrange.h main.cpp
57 # lcdrange_CXXFLAGS = $(AM_CXXFLAGS) $(QT_CXXFLAGS)
58 # lcdrange_CPPFLAGS = $(AM_CPPFLAGS) $(QT_CPPFLAGS)
59 # lcdrange_LDFLAGS = $(QT_LDFLAGS) $(LDFLAGS)
60 # lcdrange_LDADD = $(QT_LIBS) $(LDADD)
62 # BUILT_SOURCES = lcdrange.moc.cpp
63 # -------------------------------------------------------------------------
65 m4_pattern_forbid([^AT_])dnl
66 m4_pattern_forbid([^_AT_])dnl
68 # AT_WITH_QT([QT_modules], [QT_config], [QT_misc])
69 # ------------------------------------------------
70 # Enable Qt support and add an option --with-qt to the configure script.
72 # The QT_modules argument is optional and defines extra modules to enable or
73 # disable (it's equivalent to the QT variable in .pro files). Modules can be
74 # specified as follows:
76 # AT_WITH_QT => No argument -> No QT value.
77 # Qmake sets it to "core gui" by default.
78 # AT_WITH_QT([xml]) => QT += xml
79 # AT_WITH_QT([+xml]) => QT += xml
80 # AT_WITH_QT([-gui]) => QT -= gui
81 # AT_WITH_QT([xml -gui +sql svg]) => QT += xml sql svg
84 # The QT_config argument is also optional and follows the same convention as
85 # QT_modules. Instead of changing the QT variable, it changes the CONFIG
86 # variable, which is used to tweak configuration and compiler options.
88 # The last argument, QT_misc (also optional) will be copied as-is the .pro
89 # file used to guess how to compile Qt apps. You may use it to further tweak
90 # the build process of Qt apps if tweaking the QT or CONFIG variables isn't
92 AC_DEFUN([AT_WITH_QT],
93 [ AC_REQUIRE([AC_CANONICAL_HOST])
94 AC_REQUIRE([AC_CANONICAL_BUILD])
95 AC_REQUIRE([AC_PROG_CXX])
97 test x"$TROLL" != x && echo 'ViM rox emacs.'
99 dnl Memo: AC_ARG_WITH(package, help-string, [if-given], [if-not-given])
101 [AS_HELP_STRING([--with-qt],
102 [Path to Qt @<:@Look in PATH and /usr/local/Trolltech@:>@])],
103 [QT_PATH=$withval], [QT_PATH=])
106 if test -d /usr/local/Trolltech; then
107 # Try to find the latest version.
108 tmp_qt_paths=`echo /usr/local/Trolltech/*/bin | tr ' ' '\n' | sort -nr \
109 | xargs | sed 's/ */:/g'`
113 AC_PATH_PROGS([QMAKE], [qmake], [missing], [$QT_DIR:$QT_PATH:$PATH:$tmp_qt_paths])
114 if test x"$QMAKE" = xmissing; then
115 AC_MSG_ERROR([Cannot find qmake in your PATH. Try using --with-qt.])
118 # Find moc (Meta Object Compiler).
119 AC_PATH_PROGS([MOC], [moc], [missing], [$QT_PATH:$PATH:$tmp_qt_paths])
120 if test x"$MOC" = xmissing; then
121 AC_MSG_ERROR([Cannot find moc (Meta Object Compiler) in your PATH. Try using --with-qt.])
124 # Find uic (User Interface Compiler).
125 AC_PATH_PROGS([UIC], [uic], [missing], [$QT_PATH:$PATH:$tmp_qt_paths])
126 if test x"$UIC" = xmissing; then
127 AC_MSG_ERROR([Cannot find uic (User Interface Compiler) in your PATH. Try using --with-qt.])
130 # If we don't know the path to Qt, guess it from the path to qmake.
131 if test x"$QT_PATH" = x; then
132 QT_PATH=`dirname "$QMAKE"`
134 if test x"$QT_PATH" = x; then
135 AC_MSG_ERROR([Cannot find the path to your Qt install. Use --with-qt.])
139 # Get ready to build a test-app with Qt.
142 cat >conftest.h <<_ASEOF
145 class Foo: public QObject
152 void setValue(int value);
154 void valueChanged(int newValue);
160 cat >conftest.cpp <<_ASEOF
161 #include "conftest.h"
165 connect(this, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
168 void Foo::setValue(int value)
178 if $QMAKE -project; then :; else
179 AC_MSG_ERROR([Calling $QMAKE -project failed.])
182 # Find the .pro file generated by qmake.
183 pro_file='conftest.dir.pro'
184 test -f $pro_file || pro_file=`echo *.pro`
185 if test -f "$pro_file"; then :; else
186 AC_MSG_ERROR([Can't find the .pro file generated by Qmake.])
189 dnl Tweak the value of QT in the .pro if have been the 1st arg.
190 m4_ifval([$1], [_AT_TWEAK_PRO_FILE([QT], [$1])])
192 dnl Tweak the value of CONFIG in the .pro if have been given a 2nd arg.
193 m4_ifval([$2], [_AT_TWEAK_PRO_FILE([CONFIG], [$2])])
196 [ # Add the extra-settings the user wants to set in the .pro
197 echo "$3" >>"$pro_file"
200 echo "$as_me:$LINENO: Invoking $QMAKE on $pro_file" >&AS_MESSAGE_LOG_FD
201 sed 's/^/| /' "$pro_file" >&AS_MESSAGE_LOG_FD
203 if $QMAKE; then :; else
204 AC_MSG_ERROR([Calling $QMAKE failed.])
206 # Try to compile a simple Qt app.
207 AC_CACHE_CHECK([whether we can build a simple Qt app], [at_cv_qt_build],
211 if $MAKE >&AS_MESSAGE_LOG_FD 2>&1; then
212 at_cv_qt_build='ok, looks like Qt 4'
214 echo "$as_me:$LINENO: Build failed, trying to #include <qobject.h> \
215 instead" >&AS_MESSAGE_LOG_FD
216 sed 's/<QObject>/<qobject.h>/' conftest.h > tmp.h
218 if $MAKE >&AS_MESSAGE_LOG_FD 2>&1; then
219 at_cv_qt_build='ok, looks like Qt 3'
222 echo "$as_me:$LINENO: failed program was:" >&AS_MESSAGE_LOG_FD
223 sed 's/^/| /' conftest.h >&AS_MESSAGE_LOG_FD
224 echo "$as_me:$LINENO: failed program was:" >&AS_MESSAGE_LOG_FD
225 sed 's/^/| /' conftest.cpp >&AS_MESSAGE_LOG_FD
228 ])dnl end: AC_CACHE_CHECK(at_cv_qt_build)
230 if test x"$at_cv_qt_build" = xko; then
231 AC_MSG_ERROR([Cannot build a test Qt program])
233 QT_VERSION_MAJOR=`echo "$at_cv_qt_build" | sed 's/^[^0-9]*//'`
234 AC_SUBST([QT_VERSION_MAJOR])
236 # This sed filter is applied after an expression of the form: /^FOO.*=/!d;
237 # It starts by removing the beginning of the line, removing references to
238 # SUBLIBS, removing unnecessary whitespaces at the beginning, and prefixes
239 # all variable uses by QT_.
243 s/\$(\(@<:@A-Z_@:>@@<:@A-Z_@:>@*\))/$(QT_\1)/g'
245 # Find the DEFINES of Qt (should have been named CPPFLAGS).
246 AC_CACHE_CHECK([for the DEFINES to use with Qt], [at_cv_env_QT_DEFINES],
247 [at_cv_env_QT_DEFINES=`sed "/^DEFINES@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`])
248 AC_SUBST([QT_DEFINES], [$at_cv_env_QT_DEFINES])
250 # Find the CFLAGS of Qt (We can use Qt in C?!)
251 AC_CACHE_CHECK([for the CFLAGS to use with Qt], [at_cv_env_QT_CFLAGS],
252 [at_cv_env_QT_CFLAGS=`sed "/^CFLAGS@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`])
253 AC_SUBST([QT_CFLAGS], [$at_cv_env_QT_CFLAGS])
255 # Find the CXXFLAGS of Qt.
256 AC_CACHE_CHECK([for the CXXFLAGS to use with Qt], [at_cv_env_QT_CXXFLAGS],
257 [at_cv_env_QT_CXXFLAGS=`sed "/^CXXFLAGS@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`])
258 AC_SUBST([QT_CXXFLAGS], [$at_cv_env_QT_CXXFLAGS])
260 # Find the INCPATH of Qt.
261 AC_CACHE_CHECK([for the INCPATH to use with Qt], [at_cv_env_QT_INCPATH],
262 [at_cv_env_QT_INCPATH=`sed "/^INCPATH@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`])
263 AC_SUBST([QT_INCPATH], [$at_cv_env_QT_INCPATH])
265 AC_SUBST([QT_CPPFLAGS], ["$at_cv_env_QT_DEFINES $at_cv_env_QT_INCPATH"])
267 # Find the LFLAGS of Qt (Should have been named LDFLAGS)
268 AC_CACHE_CHECK([for the LDFLAGS to use with Qt], [at_cv_env_QT_LDFLAGS],
269 [at_cv_env_QT_LDFLAGS=`sed "/^LFLAGS@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`])
270 AC_SUBST([QT_LFLAGS], [$at_cv_env_QT_LDFLAGS])
271 AC_SUBST([QT_LDFLAGS], [$at_cv_env_QT_LDFLAGS])
273 AC_MSG_CHECKING([whether host operating system is Darwin])
280 AC_MSG_RESULT([$at_darwin])
282 # Find the LIBS of Qt.
283 AC_CACHE_CHECK([for the LIBS to use with Qt], [at_cv_env_QT_LIBS],
284 [at_cv_env_QT_LIBS=`sed "/^LIBS@<:@^A-Z@:>@*=/!d;$qt_sed_filter" Makefile`
285 if test x$at_darwin = xyes; then
286 # Fix QT_LIBS: as of today Libtool (GNU Libtool 1.5.23a) doesn't handle
287 # -F properly. The "bug" has been fixed on 22 October 2006
288 # by Peter O'Gorman but we provide backward compatibility here.
289 at_cv_env_QT_LIBS=`echo "$at_cv_env_QT_LIBS" \
290 | sed 's/^-F/-Wl,-F/;s/ -F/ -Wl,-F/g'`
293 AC_SUBST([QT_LIBS], [$at_cv_env_QT_LIBS])
299 # _AT_TWEAK_PRO_FILE(QT_VAR, VALUE)
300 # ---------------------------
301 # @internal. Tweak the variable QT_VAR in the .pro.
302 # VALUE is an IFS-separated list of value and each value is rewritten
304 # +value => QT_VAR += value
305 # -value => QT_VAR -= value
306 # value => QT_VAR += value
307 AC_DEFUN([_AT_TWEAK_PRO_FILE],
308 [ # Tweak the value of $1 in the .pro file for $2.
312 at_mod=`echo "$at_mod" | sed 's/^-//; tough
321 echo "$qt_conf" | sed 1d >>"$pro_file"