1# =========================================================================== 2# http://www.gnu.org/software/autoconf-archive/ax_have_qt.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_HAVE_QT 8# 9# DESCRIPTION 10# 11# Searches $PATH and queries qmake for Qt include files, libraries and Qt 12# binary utilities. The macro only supports Qt5 or later. 13# 14# The following shell variable is set to either "yes" or "no": 15# 16# have_qt 17# 18# Additionally, the following variables are exported: 19# 20# QT_CXXFLAGS 21# QT_LIBS 22# QT_MOC 23# QT_UIC 24# QT_LRELEASE 25# QT_LUPDATE 26# QT_DIR 27# 28# which respectively contain an "-I" flag pointing to the Qt include 29# directory, link flags necessary to link with Qt and X, the full path to 30# the meta object compiler and the user interface compiler both, and 31# finally the variable QTDIR as Qt likes to see it defined. 32# 33# Also the usually unneeded var 34# 35# QT_QMAKE 36# 37# to qmake is defined. 38# 39# Example lines for Makefile.in: 40# 41# CXXFLAGS = @QT_CXXFLAGS@ 42# MOC = @QT_MOC@ 43# 44# After the variables have been set, a trial compile and link is performed 45# to check the correct functioning of the meta object compiler. This test 46# may fail when the different detected elements stem from different 47# releases of the Qt framework. In that case, an error message is emitted 48# and configure stops. 49# 50# No common variables such as $LIBS or $CFLAGS are polluted. 51# 52# LICENSE 53# 54# Copyright (c) 2008 Bastiaan Veelo <Bastiaan@Veelo.net> 55# Copyright (c) 2014 Alex Henrie <alexhenrie24@gmail.com> 56# 57# Copying and distribution of this file, with or without modification, are 58# permitted in any medium without royalty provided the copyright notice 59# and this notice are preserved. This file is offered as-is, without any 60# warranty. 61 62#serial 12 63 64AU_ALIAS([BNV_HAVE_QT], [AX_HAVE_QT]) 65AC_DEFUN([AX_HAVE_QT], 66[ 67 AC_REQUIRE([AC_PROG_CXX]) 68 AC_REQUIRE([AC_PATH_X]) 69 AC_REQUIRE([AC_PATH_XTRA]) 70 71 AC_ARG_WITH(qt5-qmake, 72 [ --with-qt5-qmake=FILE uses given qmake], 73 [QT_QMAKE="$withval"], 74 [QT_QMAKE="qmake"] 75 ) 76 77 AC_MSG_CHECKING(for Qt) 78 # If we have Qt5 or later in the path, we're golden 79 ver=`$QT_QMAKE --version | grep -o "Qt version ."` 80 if test "$ver" ">" "Qt version 4"; then 81 have_qt=yes 82 # This pro file dumps qmake's variables, but it only works on Qt 5 or later 83 am_have_qt_pro=`mktemp` 84 am_have_qt_makefile=`mktemp` 85 # http://qt-project.org/doc/qt-5/qmake-variable-reference.html#qt 86 cat > $am_have_qt_pro << EOF 87win32 { 88 CONFIG -= debug_and_release 89 CONFIG += release 90} 91qtHaveModule(core): QT += core 92qtHaveModule(gui): QT += gui 93qtHaveModule(widgets): QT += widgets 94percent.target = % 95percent.commands = @echo -n "\$(\$(@))\ " 96QMAKE_EXTRA_TARGETS += percent 97EOF 98 $QT_QMAKE $am_have_qt_pro -o $am_have_qt_makefile 99 QT_CXXFLAGS=`make -s -f $am_have_qt_makefile CXXFLAGS INCPATH` 100 QT_LIBS=`make -s -f $am_have_qt_makefile LIBS` 101 rm $am_have_qt_pro $am_have_qt_makefile 102 103 # Look for specific tools in $PATH 104 AC_ARG_WITH(qt5-moc, 105 [ --with-qt5-moc=FILE uses given qt moc], 106 [QT_MOC="$withval"], 107 [QT_MOC=`which moc`] 108 ) 109 110 AC_ARG_WITH(qt5-uic, 111 [ --with-qt5-uic=FILE uses given qt uic], 112 [QT_UIC="$withval"], 113 [QT_UIC=`which uic`] 114 ) 115 116 QT_LRELEASE=`which lrelease` 117 QT_LUPDATE=`which lupdate` 118 119 # Get Qt version from qmake 120 QT_DIR=`$QT_QMAKE --version | grep -o -E /.+` 121 122 # All variables are defined, report the result 123 AC_MSG_RESULT([$have_qt: 124 QT_CXXFLAGS=$QT_CXXFLAGS 125 QT_DIR=$QT_DIR 126 QT_LIBS=$QT_LIBS 127 QT_UIC=$QT_UIC 128 QT_MOC=$QT_MOC 129 QT_LRELEASE=$QT_LRELEASE 130 QT_LUPDATE=$QT_LUPDATE]) 131 else 132 # Qt was not found 133 have_qt=no 134 QT_CXXFLAGS= 135 QT_DIR= 136 QT_LIBS= 137 QT_UIC= 138 QT_MOC= 139 QT_LRELEASE= 140 QT_LUPDATE= 141 AC_MSG_RESULT($have_qt) 142 fi 143 AC_SUBST(QT_CXXFLAGS) 144 AC_SUBST(QT_DIR) 145 AC_SUBST(QT_LIBS) 146 AC_SUBST(QT_UIC) 147 AC_SUBST(QT_MOC) 148 AC_SUBST(QT_LRELEASE) 149 AC_SUBST(QT_LUPDATE) 150 151 #### Being paranoid: 152 if test x"$have_qt" = xyes; then 153 AC_MSG_CHECKING(correct functioning of Qt installation) 154 AC_CACHE_VAL(ax_cv_qt_test_result, 155 [ 156 cat > ax_qt_test.h << EOF 157#include <qobject.h> 158class Test : public QObject 159{ 160Q_OBJECT 161public: 162 Test() {} 163 ~Test() {} 164public slots: 165 void receive() {} 166signals: 167 void send(); 168}; 169EOF 170 171 cat > ax_qt_main.$ac_ext << EOF 172#include "ax_qt_test.h" 173#include <qapplication.h> 174int main( int argc, char **argv ) 175{ 176 QApplication app( argc, argv ); 177 Test t; 178 QObject::connect( &t, SIGNAL(send()), &t, SLOT(receive()) ); 179} 180EOF 181 182 ax_cv_qt_test_result="failure" 183 ax_try_1="$QT_MOC ax_qt_test.h -o moc_ax_qt_test.$ac_ext >/dev/null 2>/dev/null" 184 AC_TRY_EVAL(ax_try_1) 185 if test x"$ac_status" != x0; then 186 echo "$ax_err_1" >&AS_MESSAGE_LOG_FD 187 echo "configure: could not run $QT_MOC on:" >&AS_MESSAGE_LOG_FD 188 cat ax_qt_test.h >&AS_MESSAGE_LOG_FD 189 else 190 ax_try_2="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o moc_ax_qt_test.o moc_ax_qt_test.$ac_ext >/dev/null 2>/dev/null" 191 AC_TRY_EVAL(ax_try_2) 192 if test x"$ac_status" != x0; then 193 echo "$ax_err_2" >&AS_MESSAGE_LOG_FD 194 echo "configure: could not compile:" >&AS_MESSAGE_LOG_FD 195 cat moc_ax_qt_test.$ac_ext >&AS_MESSAGE_LOG_FD 196 else 197 ax_try_3="$CXX $QT_CXXFLAGS -c $CXXFLAGS -o ax_qt_main.o ax_qt_main.$ac_ext >/dev/null 2>/dev/null" 198 AC_TRY_EVAL(ax_try_3) 199 if test x"$ac_status" != x0; then 200 echo "$ax_err_3" >&AS_MESSAGE_LOG_FD 201 echo "configure: could not compile:" >&AS_MESSAGE_LOG_FD 202 cat ax_qt_main.$ac_ext >&AS_MESSAGE_LOG_FD 203 else 204 ax_try_4="$CXX -o ax_qt_main ax_qt_main.o moc_ax_qt_test.o $QT_LIBS $LIBS >/dev/null 2>/dev/null" 205 AC_TRY_EVAL(ax_try_4) 206 if test x"$ac_status" != x0; then 207 echo "$ax_err_4" >&AS_MESSAGE_LOG_FD 208 else 209 ax_cv_qt_test_result="success" 210 fi 211 fi 212 fi 213 fi 214 ])dnl AC_CACHE_VAL ax_cv_qt_test_result 215 AC_MSG_RESULT([$ax_cv_qt_test_result]) 216 if test x"$ax_cv_qt_test_result" = "xfailure"; then 217 AC_MSG_ERROR([Failed to find matching components of a complete 218 Qt installation. Try using more options, 219 see ./configure --help.]) 220 fi 221 222 rm -f ax_qt_test.h moc_ax_qt_test.$ac_ext moc_ax_qt_test.o \ 223 ax_qt_main.$ac_ext ax_qt_main.o ax_qt_main 224 fi 225]) 226