1 dnl check a particular libname
2 AC_DEFUN([QT_TRY_LINK],
6 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
10 QString s("mangle_failure");
11 #if (QT_VERSION < 400)
14 ]])],[qt_cv_libname=$1],[])
18 dnl check we can do a compile
19 AC_DEFUN([QT_CHECK_COMPILE],
21 AC_MSG_CHECKING([for Qt library name])
23 AC_CACHE_VAL(qt_cv_libname,
25 SAVE_CXXFLAGS=$CXXFLAGS
26 CXXFLAGS="$CXXFLAGS $QT_INCLUDES $QT_LDFLAGS"
27 qt_corelibs="-lQtCore -lQtCore4"
28 qt_guilibs="'-lQtCore -lQtGui' '-lQtCore4 -lQtGui4'"
29 if test $USE_QT6 = "yes" ; then
30 qt_corelibs="-lQt6Core"
31 qt_guilibs="-lQt6Core -lQt6Concurrent -lQt6Gui -lQt6Svg -lQt6Widgets"
33 qt_corelibs="-lQt5Core"
34 qt_guilibs="-lQt5Core -lQt5Concurrent -lQt5Gui -lQt5Svg -lQt5Widgets"
36 for libname in $qt_corelibs '-framework QtCore'
39 if test -n "$qt_cv_libname"; then
40 QT_CORE_LIB="$qt_cv_libname"
45 for libname in $qt_guilibs \
46 '-framework QtCore -framework QtConcurrent -framework QtSvg -framework QtWidgets -framework QtMacExtras -framework QtGui'\
47 '-framework QtCore -framework QtConcurrent -framework QtSvg -framework QtSvgWidgets -framework QtWidgets -framework QtGui'\
48 '-framework QtCore -framework QtGui'
51 if test -n "$qt_cv_libname"; then
55 CXXFLAGS=$SAVE_CXXFLAGS
58 if test -z "$qt_cv_libname"; then
59 if test x$USE_QT6 = xyes ; then
60 AC_MSG_RESULT([failed, retrying with Qt5])
62 AC_MSG_RESULT([failed])
63 AC_MSG_ERROR([cannot compile a simple Qt executable. Check you have the right \$QTDIR.])
66 AC_MSG_RESULT([$qt_cv_libname])
71 AC_DEFUN([QT_FIND_TOOL],
75 if test "x$USE_QT6" != "xno" ; then
80 if test -n "$qt_cv_libexec" ; then
81 AC_PATH_PROGS($1, [$2], [], $qt_cv_libexec)
82 elif test -n "$qt_cv_bin" ; then
83 AC_PATH_PROGS($1, [$2], [], $qt_cv_bin)
84 elif qtchooser -l 2>/dev/null | grep -q ^$qt_ext\$ >/dev/null ; then
85 AC_PATH_PROG(qtc_path, qtchooser, [], [$PATH])
86 AC_PATH_PROG($2_path, $2, [], [$PATH])
87 qtc_path=`dirname "$qtc_path"`
88 $2_path=`dirname "$$2_path"`
89 if test "$qtc_path" = "$$2_path" ; then
90 AC_CHECK_PROG($1, $2, [$2 -qt=$qt_ext],, [$PATH])
93 if test -z "$$1"; then
94 AC_CHECK_PROGS($1, [$2-$qt_ext $2$qt_major $2],[],$PATH)
96 if test -z "$$1"; then
97 AC_MSG_ERROR([cannot find $2 binary.])
102 dnl get Qt version we're using
103 AC_DEFUN([QT_GET_VERSION],
105 AC_CACHE_CHECK([Qt version],lyx_cv_qtversion,
107 SAVE_CPPFLAGS=$CPPFLAGS
108 CPPFLAGS="$CPPFLAGS $QT_INCLUDES"
110 cat > conftest.$ac_ext <<EOF
111 #line __oline__ "configure"
112 #include "confdefs.h"
114 "%%%"QT_VERSION_STR"%%%"
116 lyx_cv_qtversion=`(eval "$ac_cpp conftest.$ac_ext") 2>&5 | \
117 grep '^"%%%"' 2>/dev/null | \
118 sed -e 's/"%%%"//g' -e 's/"//g'`
119 rm -f conftest.$ac_ext
120 CPPFLAGS=$SAVE_CPPFLAGS
123 QTLIB_VERSION=$lyx_cv_qtversion
124 AC_SUBST(QTLIB_VERSION)
128 AC_DEFUN([QT_DO_IT_ALL],
130 dnl this variable is precious
131 AC_ARG_VAR(QTDIR, [the place where the Qt files are, e.g. /usr/lib/qt5])
133 AC_ARG_WITH(qt-dir, [AS_HELP_STRING([--with-qt-dir], [where the root of Qt is installed])],
134 [ qt_cv_dir=`eval echo "$withval"/` ])
136 AC_ARG_WITH(qt-includes, [AS_HELP_STRING([--with-qt-includes], [where the Qt includes are])],
137 [ qt_cv_includes=`eval echo "$withval"` ])
139 AC_ARG_WITH(qt-libraries, [AS_HELP_STRING([--with-qt-libraries], [where the Qt library is installed])],
140 [ qt_cv_libraries=`eval echo "$withval"` ])
142 dnl pay attention to $QTDIR unless overridden
143 if test -z "$qt_cv_dir"; then
147 dnl derive inc/lib if needed
148 if test -n "$qt_cv_dir"; then
149 if test -z "$qt_cv_includes"; then
150 qt_cv_includes=$qt_cv_dir/include
152 if test -z "$qt_cv_libraries"; then
153 qt_cv_libraries=$qt_cv_dir/lib
157 dnl compute the binary dir too
158 if test -n "$qt_cv_dir"; then
159 qt_cv_bin=$qt_cv_dir/bin
162 dnl Preprocessor flags
163 QT_CPPFLAGS="-DQT_NO_STL -DQT_NO_KEYWORDS"
165 *mingw*) QT_CPPFLAGS="-DQT_DLL $QT_CPPFLAGS";;
167 AC_SUBST(QT_CPPFLAGS)
169 dnl Check if it possible to do a pkg-config (for later)
173 QT_QMAKE_CONFIG([$USE_QT6])
174 if test -z "$QT_LIB"; then
175 dnl pkg-config does not work with Qt6 (QTBUG-86080)
176 if test x$USE_QT6 = xno ; then
177 if test -n "$PKG_CONFIG" ; then
182 dnl last chance: old-style configuration
183 if test -z "$QT_LIB"; then
187 if test -z "$QT_LIB"; then
188 dnl Try again with Qt5 if configuring for Qt6 failed
189 dnl this is mostly the same logic as above
190 if test x$USE_QT6 = xyes ; then
192 QT_QMAKE_CONFIG([$USE_QT6])
193 if test -z "$QT_LIB"; then
194 if test -n "$PKG_CONFIG" ; then
198 if test -z "$QT_LIB"; then
204 if test -z "$QT_LIB"; then
205 AC_MSG_ERROR([Cannot find Qt libraries.])
209 AS_VERSION_COMPARE($QTLIB_VERSION, $1,
210 [AC_MSG_ERROR([LyX requires at least version $1 of Qt. Only version $QTLIB_VERSION has been found.])
213 case $QTLIB_VERSION in
214 6.*) if test $enable_stdlib_debug = "yes" ; then
215 LYX_WARNING([Compiling LyX with stdlib-debug and Qt6 library may lead to
216 crashes. Consider dropping --enable-stdlib-debug.])
221 save_CPPFLAGS=$CPPFLAGS
222 CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES"
223 AC_CHECK_HEADER(QtGui/qtgui-config.h,
224 [lyx_qt_config=QtGui/qtgui-config.h],
225 [lyx_qt_config=qconfig.h])
226 AC_MSG_CHECKING([whether Qt uses the X Window system])
227 if test x$USE_QT6 = xyes ; then
228 dnl FIXME: Check whether defining QPA_XCB makes sense with Qt6
229 AC_PREPROC_IFELSE([AC_LANG_SOURCE([
230 [#include <$lyx_qt_config>]
231 [#if !defined(QT_FEATURE_xcb) || QT_FEATURE_xcb < 0]
235 AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])],
239 [#include <$lyx_qt_config>
240 QT_QPA_DEFAULT_PLATFORM_NAME],
242 AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])],
245 CPPFLAGS=$save_CPPFLAGS
247 QT_FIND_TOOL([QT_MOC], [moc])
248 QT_FIND_TOOL([QT_UIC], [uic])
249 QT_FIND_TOOL([QT_RCC], [rcc])
252 mocqtver=`$QT_MOC -v 2>&1 | sed -e 's/.*\([[0-9]]\.[[0-9]]*\.[[0-9]]*\).*/\1/'`
253 if test "x$mocqtver" != "x$QTLIB_VERSION"; then
254 LYX_WARNING([The found moc compiler is for Qt $mocqtver but the Qt library version is $QTLIB_VERSION.])
258 AC_DEFUN([QT_DO_PKG_CONFIG],
260 dnl tell pkg-config to look also in $qt_cv_dir/lib.
261 save_PKG_CONFIG_PATH=$PKG_CONFIG_PATH
262 if test -n "$qt_cv_dir" ; then
263 PKG_CONFIG_PATH=$qt_cv_dir/lib:$qt_cv_dir/lib/pkgconfig:$PKG_CONFIG_PATH
264 export PKG_CONFIG_PATH
266 qt_corelibs="Qt5Core"
267 qt_guilibs="Qt5Core Qt5Concurrent Qt5Gui Qt5Svg Qt5Widgets"
268 lyx_use_x11extras=false
269 PKG_CHECK_EXISTS(Qt5X11Extras, [lyx_use_x11extras=true], [])
270 if $lyx_use_x11extras; then
271 qt_guilibs="$qt_guilibs Qt5X11Extras xcb"
272 AC_DEFINE(HAVE_QT5_X11_EXTRAS, 1,
273 [Define if you have the Qt5X11Extras module])
275 lyx_use_winextras=false
276 PKG_CHECK_EXISTS(Qt5WinExtras, [lyx_use_winextras=true], [])
277 if $lyx_use_winextras; then
278 qt_guilibs="$qt_guilibs Qt5WinExtras"
280 lyx_use_macextras=false
281 PKG_CHECK_EXISTS(Qt5MacExtras, [lyx_use_macextras=true], [])
282 if $lyx_use_macextras; then
283 qt_guilibs="$qt_guilibs Qt5MacExtras"
285 PKG_CHECK_MODULES(QT_CORE, $qt_corelibs,,[:])
286 if test "$pkg_failed" = "no" ; then
287 QT_CORE_INCLUDES=$QT_CORE_CFLAGS
288 AC_SUBST(QT_CORE_INCLUDES)
289 QT_CORE_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_corelibs`
290 AC_SUBST(QT_CORE_LDFLAGS)
291 QT_CORE_LIB=`$PKG_CONFIG --libs-only-l $qt_corelibs`
292 AC_SUBST(QT_CORE_LIB)
294 PKG_CHECK_MODULES(QT_FRONTEND, $qt_guilibs,,[:])
295 if test "$pkg_failed" = "no" ; then
296 QT_INCLUDES=$QT_FRONTEND_CFLAGS
297 dnl QT_LDFLAGS=$QT_FRONTEND_LIBS
298 QT_LDFLAGS=`$PKG_CONFIG --libs-only-L $qt_guilibs`
299 AC_SUBST(QT_INCLUDES)
301 QTLIB_VERSION=`$PKG_CONFIG --modversion $qt_corelibs`
302 AC_SUBST(QTLIB_VERSION)
303 QT_LIB=`$PKG_CONFIG --libs-only-l $qt_guilibs`
305 dnl LIBS="$LIBS `$PKG_CONFIG --libs-only-other $qt_guilibs`"
307 PKG_CONFIG_PATH=$save_PKG_CONFIG_PATH
308 dnl Actually, the values of QT_LIB and QT_CORE_LIB can be completely
309 dnl wrong on OS X, where everything goes to --libs-only-other.
310 dnl As a quick workaround, let us assign better values. A better patch
311 dnl exists for next cycle.
312 QT_CORE_LIB=$QT_CORE_LIBS
314 QT_LIB=$QT_FRONTEND_LIBS
318 AC_DEFUN([QT_DO_MANUAL_CONFIG],
320 dnl Check for X libraries
329 yes) LIBS="$X_PRE_LIBS $LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
330 CPPFLAGS="$CPPFLAGS $X_CFLAGS";;
331 no) AC_MSG_ERROR([cannot find X window libraries and/or headers.]);;
335 dnl flags for compilation
340 if test -n "$qt_cv_includes"; then
341 QT_INCLUDES="-I$qt_cv_includes"
342 for i in Qt QtCore QtGui QtWidgets QtSvg QtConcurrent QtSvgWidgets QtMacExtras; do
343 QT_INCLUDES="$QT_INCLUDES -I$qt_cv_includes/$i"
344 if test "$lyx_use_packaging" = "macosx" ; then
345 QT_INCLUDES="$QT_INCLUDES -I$qt_cv_libraries/${i}.framework/Headers"
348 QT_CORE_INCLUDES="-I$qt_cv_includes -I$qt_cv_includes/QtCore"
350 case "$qt_cv_libraries" in
354 if test "$lyx_use_packaging" = "macosx" ; then
355 QT_INCLUDES="$QT_INCLUDES -F$qt_cv_libraries"
356 QT_CORE_INCLUDES="$QT_CORE_INCLUDES -I$qt_cv_libraries/QtCore.framework/Headers -F$qt_cv_libraries"
357 QT_LDFLAGS="-F$qt_cv_libraries"
358 QT_CORE_LDFLAGS="-F$qt_cv_libraries"
360 QT_LDFLAGS="-L$qt_cv_libraries"
361 QT_CORE_LDFLAGS="-L$qt_cv_libraries"
365 AC_SUBST(QT_INCLUDES)
366 AC_SUBST(QT_CORE_INCLUDES)
368 AC_SUBST(QT_CORE_LDFLAGS)
372 QT_LIB=$qt_cv_libname;
374 AC_SUBST(QT_CORE_LIB)
376 if test -n "$qt_cv_libname"; then
381 dnl QT_QMAKE_CONFIG(USE_QT6)
383 AC_DEFUN([QT_QMAKE_CONFIG],
385 dnl Use first suitable qmake in PATH
386 if test $1 = "yes"; then
391 AC_CHECK_PROGS([QT_QMAKE], [qmake-qt$qt_major qmake$qt_major qmake], [], $PATH)
392 AC_MSG_CHECKING([for Qt$qt_major])
393 qtver=`$QT_QMAKE -v | grep -o "Qt version ."`
394 if test "$qtver" = "Qt version $qt_major"; then
395 qt_cv_libexec=`$QT_QMAKE -query QT_INSTALL_LIBEXECS`
396 dnl Use a .pro file for getting qmake's variables
397 lyx_test_qt_dir=`mktemp -d`
398 lyx_test_qt_pro="$lyx_test_qt_dir/test.pro"
399 lyx_test_qt_mak="$lyx_test_qt_dir/Makefile"
400 cat > $lyx_test_qt_pro << EOF1
401 qtHaveModule(core): QT += core
403 percent.commands = @echo -n "\$(\$(@))\ "
404 QMAKE_EXTRA_TARGETS += percent
405 QMAKE_PROJECT_DEPTH = 0
407 $QT_QMAKE $lyx_test_qt_pro -o $lyx_test_qt_mak 1>/dev/null 2>&1
408 QT_CORE_INCLUDES=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak INCPATH | sed 's/-I\. //g'`
409 qt_corelibs=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak LIBS`
410 QT_CORE_LDFLAGS=`echo $qt_corelibs | tr ' ' '\n' | grep -e "^-L" | tr '\n' ' '`
411 if test -z "$QT_CORE_LDFLAGS"; then
412 QT_CORE_LDFLAGS="-L`$QT_QMAKE -query QT_INSTALL_LIBS`"
413 QT_CORE_LIB="$qt_corelibs"
415 QT_CORE_LIB=`echo $qt_corelibs | tr ' ' '\n' | grep -e "^-l" | tr '\n' ' '`
417 if test -z "$QT_CORE_LIB"; then
420 AC_SUBST(QT_CORE_INCLUDES)
421 AC_SUBST(QT_CORE_LDFLAGS)
422 AC_SUBST(QT_CORE_LIB)
423 cat > $lyx_test_qt_pro << EOF2
424 QMAKE_EXTRA_VARIABLES = MISSING
426 percent.commands = @echo -n "\$(\$(@))\ "
427 QMAKE_EXTRA_TARGETS += percent
428 QMAKE_PROJECT_DEPTH = 0
429 qtHaveModule(core) {QT += core} else {MISSING += core}
430 qtHaveModule(concurrent) {QT += concurrent} else {MISSING += concurrent}
431 qtHaveModule(gui) {QT += gui} else {MISSING += gui}
432 qtHaveModule(gui-private) {QT += gui-private} else {MISSING += gui-private}
433 qtHaveModule(svg) {QT += svg} else {MISSING += svg}
434 qtHaveModule(widgets) {QT += widgets} else {MISSING += widgets}
436 if test "$qt_major" = 6; then
437 cat >> $lyx_test_qt_pro << EOF3
438 qtHaveModule(svgwidgets) {QT += svgwidgets} else {MISSING += svgwidgets}
441 cat >> $lyx_test_qt_pro << EOF4
442 qtHaveModule(x11extras) {QT += x11extras}
443 qtHaveModule(macextras) {QT += macextras}
444 qtHaveModule(winextras) {QT += winextras}
447 $QT_QMAKE $lyx_test_qt_pro -o $lyx_test_qt_mak 1>/dev/null 2>&1
448 QT_INCLUDES=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak INCPATH | sed 's/-I\. //g'`
449 qt_guilibs=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak LIBS`
450 QT_LDFLAGS=`echo $qt_guilibs | tr ' ' '\n' | grep -e "^-L" | tr '\n' ' '`
451 if test -z "$QT_LDFLAGS"; then
452 QT_LDFLAGS="-L`$QT_QMAKE -query QT_INSTALL_LIBS`"
455 QT_LIB=`echo $qt_guilibs | tr ' ' '\n' | grep -v "^-L" | tr '\n' ' '`
457 QTLIB_VERSION=`$QT_QMAKE -v | grep "Qt version" | sed -e 's/.*\([[0-9]]\.[[0-9]]*\.[[0-9]]*\).*/\1/'`
458 if test -z "$QT_LIB"; then
461 QT_MISSING=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak EXPORT_MISSING | sed 's/^ *//'`
462 if test -n "$QT_MISSING"; then
463 AC_MSG_ERROR([Qt$qt_major module(s) $QT_MISSING not found.])
465 QT5_X11_EXTRAS=`cd $lyx_test_qt_dir; make -s -f $lyx_test_qt_mak DEFINES | grep QT_X11EXTRAS_LIB`
466 if test -n "$QT5_X11_EXTRAS"; then
467 AC_DEFINE(HAVE_QT5_X11_EXTRAS, 1,
468 [Define if you have the Qt5X11Extras module])
470 AC_MSG_RESULT($QTLIB_VERSION)
471 AC_SUBST(QT_INCLUDES)
474 AC_SUBST(QTLIB_VERSION)
477 rm $lyx_test_qt_pro $lyx_test_qt_mak $lyx_test_qt_dir/.qmake.stash
478 rmdir $lyx_test_qt_dir
482 if test -z "$QT_LIB"; then
483 LYX_WARNING([Unable to configure Qt$qt_major with qmake. Please report.])