build,qt: Check whether building with -fPIC is needed

m4/qt6.m4: Use build test to check whether -fPIC is needed for building
a Qt application.
--
This commit is contained in:
Ingo Klöcker 2022-10-14 14:16:47 +02:00
parent 1792db5834
commit 2ff09f474f
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9

View File

@ -60,14 +60,13 @@ AC_DEFUN([FIND_QT6],
dnl we check here that we can actually compile / link a qt application dnl we check here that we can actually compile / link a qt application
dnl for host. dnl for host.
OLDCPPFLAGS=$CPPFLAGS OLDCPPFLAGS=$CPPFLAGS
CPPFLAGS=$GPGME_QT6_CFLAGS
if ! test "$have_w32_system" = yes; then
CPPFLAGS="$CPPFLAGS -fpic"
fi
OLDLIBS=$LIBS OLDLIBS=$LIBS
# try building without -fPIC
CPPFLAGS=$GPGME_QT6_CFLAGS
LIBS=$GPGME_QT6_LIBS LIBS=$GPGME_QT6_LIBS
AC_LANG_PUSH(C++) AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether a simple qt program can be built]) AC_MSG_CHECKING([whether a simple qt program can be built without -fPIC])
AC_LINK_IFELSE([AC_LANG_SOURCE([ AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <QCoreApplication> #include <QCoreApplication>
int main (int argc, char **argv) { int main (int argc, char **argv) {
@ -76,6 +75,26 @@ AC_DEFUN([FIND_QT6],
}])], [have_qt6_libs='yes'], [have_qt6_libs='no']) }])], [have_qt6_libs='yes'], [have_qt6_libs='no'])
AC_MSG_RESULT([$have_qt6_libs]) AC_MSG_RESULT([$have_qt6_libs])
AC_LANG_POP() AC_LANG_POP()
if test "$have_qt6_libs" = "no" -a "$have_w32_system" != yes; then
# try building with -fPIC
CPPFLAGS="$GPGME_QT6_CFLAGS -fPIC"
LIBS=$GPGME_QT6_LIBS
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether a simple qt program can be built with -fPIC])
AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <QCoreApplication>
int main (int argc, char **argv) {
QCoreApplication app(argc, argv);
app.exec();
}])], [
have_qt6_libs='yes'
GPGME_QT6_CFLAGS="$GPGME_QT6_CFLAGS -fPIC"
], [have_qt6_libs='no'])
AC_MSG_RESULT([$have_qt6_libs])
AC_LANG_POP()
fi
CPPFLAGS=$OLDCPPFLAGS CPPFLAGS=$OLDCPPFLAGS
LIBS=$OLDLIBS LIBS=$OLDLIBS
fi fi