changeset 289:3dbf01233fec

autoconf: add a check for some weird Qt PIC requirements
author Paper <paper@paper.us.eu.org>
date Wed, 08 May 2024 17:27:13 -0400
parents 8b9db17d1e5f
children 9347e2eaf6e5
files configure.ac
diffstat 1 files changed, 28 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed May 08 16:47:25 2024 -0400
+++ b/configure.ac	Wed May 08 17:27:13 2024 -0400
@@ -11,9 +11,9 @@
 
 dnl need C compiler for utf8proc
 AC_PROG_CC
+AC_LANG([C++])
 
 dnl Do we have a C++17 compiler
-: ${CXXFLAGS=""}
 AC_PROG_CXX
 AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
 
@@ -23,21 +23,35 @@
 
 
 dnl Qt?
-AS_IF([test "${enable_qt}" != "no"], [
-	PKG_CHECK_MODULES([QT], [Qt5Core >= 5.7.0 Qt5Widgets Qt5Gui], [
-		QT_PATH="$(eval $PKG_CONFIG --variable=exec_prefix Qt5Core)"
-		QT_HOST_PATH="$(eval $PKG_CONFIG --variable=host_bins Qt5Core)"
-		QT_VERSION="$(eval $PKG_CONFIG --modversion Qt5Gui)"
-		AC_PATH_PROGS(QT_MOC,      [moc-qt5 moc],           moc,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
-		AC_PATH_PROGS(QT_RCC,      [rcc-qt5 rcc],           rcc,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
-		AC_PATH_PROGS(QT_UIC,      [uic-qt5 uic],           uic,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
-		AC_PATH_PROGS(QT_LRELEASE, [lrelease-qt5 lrelease], lrelease, ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
-		AC_PATH_PROGS(QT_LUPDATE,  [lupdate-qt5 lupdate],   lupdate,  ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
-	], [
-		AC_MSG_ERROR([${QT_PKG_ERRORS}])
-	])
+PKG_CHECK_MODULES([QT], [Qt5Core >= 5.7.0 Qt5Widgets Qt5Gui], [
+	QT_PATH="$(eval $PKG_CONFIG --variable=exec_prefix Qt5Core)"
+	QT_HOST_PATH="$(eval $PKG_CONFIG --variable=host_bins Qt5Core)"
+	QT_VERSION="$(eval $PKG_CONFIG --modversion Qt5Gui)"
+	AC_PATH_PROGS(QT_MOC,      [moc-qt5 moc],           moc,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
+	AC_PATH_PROGS(QT_RCC,      [rcc-qt5 rcc],           rcc,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
+	AC_PATH_PROGS(QT_UIC,      [uic-qt5 uic],           uic,      ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
+	AC_PATH_PROGS(QT_LRELEASE, [lrelease-qt5 lrelease], lrelease, ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
+	AC_PATH_PROGS(QT_LUPDATE,  [lupdate-qt5 lupdate],   lupdate,  ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
+], [
+	AC_MSG_ERROR([${QT_PKG_ERRORS}.])
 ])
 
+dnl On some platforms (see: Debian), Qt is built with
+dnl `-reduce-relocations`, which requires applications
+dnl to be built with position-independent code.
+dnl
+dnl Unfortunately there's no way to check for this
+dnl without using qmake (bleugh), so we use this check
+dnl to see if qglobal.h can be included without PIC.
+
+saved_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CXXFLAGS $QT_CFLAGS"
+AC_COMPILE_IFELSE(
+	[AC_LANG_PROGRAM([#include <qglobal.h>], [])],
+	[CXXFLAGS="$saved_CXXFLAGS"],
+	[CXXFLAGS="$saved_CXXFLAGS -fPIC"]
+)
+
 dnl need this for moc
 AC_PROG_MKDIR_P
 AC_SUBST([MKDIR_P])