From: Matthew Fernandez Date: Sat, 31 Dec 2022 22:12:39 +0000 (-0800) Subject: Autotools: look for Qt6 in preference to Qt5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4969fa197ede68d521fadc8591760f0335d40b5;p=graphviz Autotools: look for Qt6 in preference to Qt5 This is the equivalent of 743aed2fea0206827294c9efa6ab117a2ba8dceb, but for the Autotools build system. Qt6 no longer ships with pkg-config (.pc) file(s). So we need to do manual discovery of the necessary information ourselves. QMake is called `qtmake6` in Qt6 and the `qtmake` that ships with it is a symlink to the former. So this change preferences Qt6 if both Qt5 and Qt6 are installed. Some notable warts: 1. Discovery uses `AC_CHECK_FILE` rather than `AC_CHECK_HEADER`/`AC_CHECK_HEADERS`. The latter seems to exclusively call the C compiler rather than the C++ compiler, and thus cannot be used for C++ header discovery.¹ A consequence of this choice is that discovery checks existence only, not whether the headers are usable. 2. Library discovery also uses `AC_CHECK_FILE` rather than `AC_CHECK_LIB`. Given the above restriction, if we cannot call the C++ compiler, there is little point in attempting a link check. But this does mean that discovery here also only checks existence, not whether the libraries are usable. 3. There seems to be no pkg-config-like mechanism for discovering that e.g. Qt6Widgets and Qt6PrintSupport depend on Qt6Gui and thus `-lQt6Gui.so` must also be included in the link line. Qt6 has migrated to a CMake-based build system and their answer to most of these such problems appears to be “move to CMake.”² This change just hard codes the link lines under the assumption these will be stable across the Qt6 series. 4. Qt6 requires C++17,³ so we need to switch from C++11 to C++17 mode when `--with-qt=yes`. The CMake discovery apparently does this automatically. 5. The `QT_SELECT` environment variable does nothing in Qt6. The line using it in cmd/gvedit/Makefile.am has been left unchanged in this commit. When using Qt5 it still avoids accidentally picking up Qt4 and when using Qt6 it is a no-op. Gitlab: closes #2233 ¹ If accurate, this would also explain the difficulty I had in https://gitlab.com/graphviz/graphviz/-/issues/1835#note_794857735. ² https://www.qt.io/blog/qt-6-build-system https://doc.qt.io/qt-6/qt6-buildsystem.html ³ https://www.qt.io/blog/2019/08/07/technical-vision-qt-6 https://www.qt.io/blog/qt-6.0-released --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 075c03563..8c216049f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The Autotools build system no longer looks for `python` binaries. The Python interpreter is unconditionally assumed to be `python3`. The configure option `--enable-python` is now an alias for `--enable-python3`. -- The CMake build system, when building `gvedit`, will now look for and use Qt6 - in preference over Qt5. #2233 +- The Autotools and CMake build systems, when building `gvedit`, will now look + for and use Qt6 in preference over Qt5. #2233 - Reserved stack size on Windows for the `dot.exe` binary has been increased from ~3.8MB to 32MB. #1710 - Reserved stack size on macOS for the `dot` binary when built with CMake has diff --git a/configure.ac b/configure.ac index 2439de5e7..49e027fcd 100644 --- a/configure.ac +++ b/configure.ac @@ -1969,21 +1969,56 @@ AC_ARG_WITH([qt], [AS_HELP_STRING([--with-qt=yes], [Qt features])]) AS_IF([test "x$with_qt" != "xno"], [ - # required for linking with QT5 + # required for linking with QT CXXFLAGS="${CXXFLAGS} -fPIE -fPIC" - AC_CHECK_PROGS([QMAKE], [qmake-qt5 qmake5 qmake], [false]) - AS_IF([test "$QMAKE" != "false"], [ - PKG_CHECK_MODULES([QTCORE], [Qt5Core], [ - PKG_CHECK_MODULES([QTGUI], [Qt5Widgets Qt5PrintSupport], [ - use_qt="Yes" + AC_CHECK_PROGS([QMAKE], [qmake6 qmake-qt5 qmake5 qmake], [false]) + AS_IF([test "$QMAKE" == "qmake6"], [ + # Qt6 + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_HEADERS)/QtCore/QtCore, [ + QTCORE_CFLAGS="-I$(${QMAKE} -query QT_INSTALL_HEADERS) -I$(${QMAKE} -query QT_INSTALL_HEADERS)/QtCore" + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_LIBS)/libQt6Core.so, [ + QTCORE_LIBS="-L$(${QMAKE} -query QT_INSTALL_LIBS) -lQt6Core" + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_HEADERS)/QtWidgets/QtWidgets, [ + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_HEADERS)/QtPrintSupport/QtPrintSupport, [ + QTGUI_CFLAGS="-I$(${QMAKE} -query QT_INSTALL_HEADERS) -I$(${QMAKE} -query QT_INSTALL_HEADERS)/QtWidgets -I$(${QMAKE} -query QT_INSTALL_HEADERS)/QtPrintSupport -I$(${QMAKE} -query QT_INSTALL_HEADERS)/QtGui" + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_LIBS)/libQt6Widgets.so, [ + AC_CHECK_FILE($(${QMAKE} -query QT_INSTALL_LIBS)/libQt6PrintSupport.so, [ + QTGUI_LIBS="-L$(${QMAKE} -query QT_INSTALL_LIBS) -lQt6Widgets -lQt6PrintSupport -lQt6Gui -lQt6Core" + AX_CXX_COMPILE_STDCXX_17(noext,mandatory) + use_qt="Yes" + ], [ + use_qt="No (Qt6PrintSupport library not available)" + ]) + ], [ + use_qt="No (Qt6Widgets library not available)" + ]) + ], [ + use_qt="No (Qt6PrintSupport header not available)" + ]) + ], [ + use_qt="No (Qt6Widgets header not available)" + ]) ], [ - use_qt="No (QtGui not available)" + use_qt="No (Qt6Core library not available)" ]) ], [ - use_qt="No (QtCore not available)" + use_qt="No (Qt6Core header not available)" ]) ], [ - use_qt="No (qmake not found)" + # Qt5 + AS_IF([test "$QMAKE" != "false"], [ + PKG_CHECK_MODULES([QTCORE], [Qt5Core], [ + PKG_CHECK_MODULES([QTGUI], [Qt5Widgets Qt5PrintSupport], [ + use_qt="Yes" + ], [ + use_qt="No (QtGui not available)" + ]) + ], [ + use_qt="No (QtCore not available)" + ]) + ], [ + use_qt="No (qmake not found)" + ]) ]) AS_IF([test "x$with_qt" = "xyes" && test "x$use_qt" != "xYes"], [