From 8cf8251d6b309f202d7964a9f5b7e35a69c45db8 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 24 May 2021 21:08:22 +0200 Subject: [PATCH] Qt 6 detection: try compiling & linking a test program Prevents using the system qmake6 in cross-compilation situations. Also cleans up the paths to `lconvert`, `moc`, `rcc` and `uic` from the Qt 6 detection so that Qt 5 can detect their own version. Part of the implementation of #3115. --- ac/qt5.m4 | 8 ++++---- ac/qt6.m4 | 57 ++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/ac/qt5.m4 b/ac/qt5.m4 index cdd6a508f..e08923290 100644 --- a/ac/qt5.m4 +++ b/ac/qt5.m4 @@ -113,7 +113,7 @@ check_qt5() { dnl compile test program AC_LANG_PUSH(C++) - AC_CACHE_VAL(am_cv_qt_compilation, [ + AC_CACHE_VAL(am_cv_qt5_compilation, [ run_qt_test=1 while true; do ac_save_CXXFLAGS="$CXXFLAGS" @@ -136,12 +136,12 @@ int ai = 0; char **ac = 0; Config app(ai,ac); return 0; - ], [ am_cv_qt_compilation=1 ], [ am_cv_qt_compilation=0 ]) + ], [ am_cv_qt5_compilation=1 ], [ am_cv_qt5_compilation=0 ]) CXXFLAGS="$ac_save_CXXFLAGS" LIBS="$ac_save_LIBS" - if test x"$am_cv_qt_compilation" = x1; then + if test x"$am_cv_qt5_compilation" = x1; then break elif test x"$run_qt_test" = "x1"; then @@ -158,7 +158,7 @@ return 0; rm -f src/mkvtoolnix-gui/static_plugins.cpp - if ! test x"$am_cv_qt_compilation" = x1; then + if ! test x"$am_cv_qt5_compilation" = x1; then AC_MSG_CHECKING(for Qt 5) AC_MSG_RESULT(no: test program could not be compiled) return diff --git a/ac/qt6.m4 b/ac/qt6.m4 index 6cfeb2a56..0e4b5fb6b 100644 --- a/ac/qt6.m4 +++ b/ac/qt6.m4 @@ -110,23 +110,62 @@ EOT AC_PATH_PROG(RCC, rcc,, [$qt_searchpath]) AC_PATH_PROG(UIC, uic,, [$qt_searchpath]) - AC_MSG_CHECKING(for Qt 6) - if test x"$MOC" = x; then + AC_MSG_CHECKING(for Qt 6) AC_MSG_RESULT(no: could not find the moc executable) + return elif test x"$RCC" = x; then + AC_MSG_CHECKING(for Qt 6) AC_MSG_RESULT(no: could not find the rcc executable) + return elif test x"$UIC" = x; then + AC_MSG_CHECKING(for Qt 6) AC_MSG_RESULT(no: could not find the uic executable) - - else - AC_DEFINE(HAVE_QT, 1, [Define if Qt is present]) - AC_MSG_RESULT(yes) - have_qt6=yes - USE_QT=yes + return fi + + dnl compile test program + AC_LANG_PUSH(C++) + AC_CACHE_VAL(am_cv_qt6_compilation, [ + ac_save_CXXFLAGS="$CXXFLAGS" + ac_save_LIBS="$LIBS" + CXXFLAGS="$STD_CXX $CXXFLAGS $QT_CFLAGS -fPIC" + LIBS="$LDFLAGS $QT_LIBS" + unset ac_cv_qt_compilation + + AC_TRY_LINK([ +#include +#include +class Config : public QCoreApplication { +public: +Config(int &argc, char **argv); +}; +Config::Config(int &argc, char **argv) +: QCoreApplication(argc,argv) {setApplicationName("config");} + ], [ +int ai = 0; +char **ac = 0; +Config app(ai,ac); +return 0; + ], [ am_cv_qt6_compilation=1 ], [ am_cv_qt6_compilation=0 ]) + + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + ]) + AC_LANG_POP() + + if test x"$am_cv_qt6_compilation" != x1; then + AC_MSG_CHECKING(for Qt 6) + AC_MSG_RESULT(no: could not compile a test program) + return + fi + + AC_DEFINE(HAVE_QT, 1, [Define if Qt is present]) + AC_MSG_RESULT(yes) + have_qt6=yes + USE_QT=yes } AC_ARG_ENABLE([qt6], @@ -145,7 +184,7 @@ else unset qmake_dir qt_bindir qt_libdir qt_searchpath if test $have_qt6 != yes; then - unset QT_CFLAGS QT_LIBS + unset QT_CFLAGS QT_LIBS LCONVERT MOC RCC UIC ac_cv_path_LCONVERT ac_cv_path_MOC ac_cv_path_RCC ac_cv_path_UIC fi fi