1 # Detect Qt5 headers and libraries and set flag variables
3 AC_ARG_VAR([MOCCMD], [QT 5 moc command (autodetected it if not set)])
7 if test "x$fc_qt5_usable" = "x" ; then
9 darwin*) FC_QT5_DARWIN;;
16 AC_DEFUN([FC_QT5_GENERIC],
20 AC_MSG_CHECKING([Qt5 headers])
22 AC_ARG_WITH([qt5-includes],
23 AS_HELP_STRING([--with-qt5-includes], [path to Qt5 includes]),
24 [FC_QT5_COMPILETEST([$withval])],
25 [POTENTIAL_PATHS="/usr/include /usr/include/qt5 /usr/include/qt"
27 # search multiarch paths too (if the multiarch tuple can be found)
29 AS_IF(test "x$MULTIARCH_TUPLE" != "x",
30 POTENTIAL_PATHS="$POTENTIAL_PATHS /usr/include/$MULTIARCH_TUPLE/qt5")
32 dnl First test without any additional include paths to see if it works already
34 for TEST_PATH in $POTENTIAL_PATHS
36 if test "x$qt5_headers" != "xyes" ; then
37 FC_QT5_COMPILETEST($TEST_PATH)
41 if test "x$qt5_headers" = "xyes" ; then
42 AC_MSG_RESULT([found])
44 AC_MSG_CHECKING([Qt5 libraries])
45 AC_ARG_WITH([qt5-libs],
46 AS_HELP_STRING([--with-qt5-libs], [path to Qt5 libraries]),
47 [FC_QT5_LINKTEST([$withval])],
48 [POTENTIAL_PATHS="/usr/lib/qt5 /usr/lib/qt"
50 # search multiarch paths too (if the multiarch tuple can be found)
52 AS_IF(test "x$MULTIARCH_TUPLE" != "x",
53 POTENTIAL_PATHS="$POTENTIAL_PATHS /usr/lib/$MULTIARCH_TUPLE/qt5")
55 dnl First test without any additional library paths to see if it works already
57 for TEST_PATH in $POTENTIAL_PATHS
59 if test "x$qt5_libs" != "xyes" ; then
60 FC_QT5_LINKTEST($TEST_PATH)
65 if test "x$qt5_libs" = "xyes" ; then
66 AC_MSG_RESULT([found])
67 AC_MSG_CHECKING([for Qt >= 5.2])
72 if test "x$fc_qt52" = "xyes" ; then
74 FC_QT5_VALIDATE_MOC([fc_qt5_usable=true], [fc_qt5_usable=false])
76 AC_MSG_RESULT([not found])
81 dnl Test if Qt headers are found from given path
82 AC_DEFUN([FC_QT5_COMPILETEST],
84 if test "x$1" != "x" ; then
85 CPPFADD=" -I$1 -I$1/QtCore -I$1/QtGui -I$1/QtWidgets"
90 CPPFLAGS_SAVE="$CPPFLAGS"
91 CPPFLAGS="${CPPFLAGS}${CPPFADD}"
92 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <QApplication>]],
93 [[int a; QApplication app(a, 0);]])],
95 FC_QT5_CPPFLAGS="${FC_QT5_CPPFLAGS}${CPPFADD}"],
96 [CXXFLAGS_SAVE="${CXXFLAGS}"
97 CXXFLAGS="${CXXFLAGS} -fPIC"
98 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <QApplication>]],
99 [[int a; QApplication app(a, 0);]])],
101 FC_QT5_CPPFLAGS="${FC_QT5_CPPFLAGS}${CPPFADD}"
102 FC_QT5_CXXFLAGS="${FC_QT5_CXXFLAGS} -fPIC"])
103 CXXFLAGS="${CXXFLAGS_SAVE}"])
105 CPPFLAGS="$CPPFLAGS_SAVE"
108 dnl Check if the included version of Qt is at least Qt5.2
109 dnl Output: fc_qt52=yes|no
110 AC_DEFUN([FC_QT52_CHECK],
112 CPPFLAGS_SAVE="$CPPFLAGS"
113 CPPFLAGS="$CPPFLAGS $FC_QT5_CPPFLAGS"
114 CXXFLAGS_SAVE="$CXXFLAGS"
115 CXXFLAGS="$CXXFLAGS $FC_QT5_CXXFLAGS"
117 LIBS="${LIBS}${LIBSADD}"
118 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
119 [[#include <QtCore>]],[[
120 #if QT_VERSION < 0x050200
127 CPPFLAGS="${CPPFLAGS_SAVE}"
128 CXXFLAGS="${CXXFLAGS_SAVE}"
132 dnl Test Qt application linking with current flags
133 AC_DEFUN([FC_QT5_LINKTEST],
135 if test "x$1" != "x" ; then
136 LIBSADD=" -L$1 -lQt5Gui -lQt5Core -lQt5Widgets"
138 LIBSADD=" -lQt5Gui -lQt5Core -lQt5Widgets"
141 CPPFLAGS_SAVE="$CPPFLAGS"
142 CPPFLAGS="$CPPFLAGS $FC_QT5_CPPFLAGS"
143 CXXFLAGS_SAVE="$CXXFLAGS"
144 CXXFLAGS="$CXXFLAGS $FC_QT5_CXXFLAGS"
146 LIBS="${LIBS}${LIBSADD}"
147 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <QApplication>]],
148 [[int a; QApplication app(a, 0);]])],
150 FC_QT5_LIBS="${FC_QT5_LIBS}${LIBSADD}"])
152 CPPFLAGS="${CPPFLAGS_SAVE}"
153 CXXFLAGS="${CXXFLAGS_SAVE}"
156 dnl If $1 is Qt 5's moc command then $2 else $3
157 AC_DEFUN([FC_QT5_IF_QT5_MOC],
158 AS_IF([test "`$1 -v 2<&1 | grep -o 'Qt [[[0-9]]]\+'`" = "Qt 5" ||
159 test "`$1 -v 2<&1 | grep -o 'moc [[[0-9]]]\+'`" = "moc 5" ],
162 dnl Set MOCCMD to $1 if it is the Qt 5 "moc". If not run $2 parameter.
163 AC_DEFUN([FC_QT5_TRY_MOC],
164 [FC_QT5_IF_QT5_MOC([$1], [MOCCMD="$1"], [$2])])
167 dnl If a usable moc command is found do $1 else do $2
168 AC_DEFUN([FC_QT5_VALIDATE_MOC], [
169 AC_MSG_CHECKING([the Qt 5 moc command])
171 dnl Try to find a Qt 5 'moc' if MOCCMD isn't set.
172 dnl Test that the supplied MOCCMD is a Qt 5 'moc' if it is set.
173 AS_IF([test "x$MOCCMD" = "x"],
174 [FC_QT5_TRY_MOC([moc],
175 [FC_QT5_TRY_MOC([qtchooser -run-tool=moc -qt=5],
177 [FC_QT5_TRY_MOC([$MOCCMD],
178 AC_MSG_ERROR(["MOCCMD set to a bad value ($MOCCMD)"]))])
180 dnl If no Qt 5 'moc' was found do $2, else do $1
181 AS_IF([test "x$MOCCMD" = "x"],
182 [AC_MSG_RESULT([not found]); $2],
183 [AC_MSG_RESULT([$MOCCMD]); $1])])
185 dnl Put the multiarch tuple of the host architecture in $MULTIARCH_TUPLE if it
187 AC_DEFUN([FC_MULTIARCH_TUPLE], [
188 # GCC has the --print-multiarch option
189 AS_IF(test "x$GCC" = "xyes", [
190 # unless it is an old version
191 AS_IF(($CC --print-multiarch >/dev/null 2>/dev/null),
192 [MULTIARCH_TUPLE=`$CC --print-multiarch`],
193 [MULTIARCH_TUPLE="$host_cpu-$host_os"])],
194 [MULTIARCH_TUPLE="$host_cpu-$host_os"])])