From 27c850b2ea3d004b380921de6664c50e6d54d4f5 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 19 Apr 2022 22:03:37 +0200 Subject: Fix determining ZXING_CFLAGS for --with-system-zxing While at least Linux distros typically provide the zxing include files in a dedicated ZXing sub-directory (i.e., /usr/include/ZXing/), the bundled external/zxing does not (it rather provides them in workdir/UnpackedTarball/zxing/core/src/, cf. RepositoryExternal.mk). Therefore, source files like cui/source/dialogs/QrCodeGenDialog.cxx #include etc. rather than #include etc., and for --with-system-zxing ad92c7dfa64c9e08aa2bcf612a9a4a68e9deae22 "fix system zxing build" simply hardcoded ZXING_CFLAGS=-I/usr/include/ZXing (i.e., the typical location for these include files). However, for e.g. a Fedora Flatpak-from-RPM build of --with-system-zxing LibreOffice, the include files will be in /app/include/ZXing/ rather than in /usr/include/ZXing/. (And which AC_CHECK_HEADER would find via CPLUS_INCLUDE_PATH containing /app/include for such a build. But the hardcoded ZXING_CFLAGS then caused compiling e.g. cui/source/dialogs/QrCodeGenDialog.cxx to fail because it didn't find BarcodeFormat.h etc. in the hardcoded /usr/include/ZXing/.) So when checking for the sample zxing include file (MultiFormatWriter.h), try any $CPLUS_INCLUDE_PATH paths one by one (and with a fallback to /usr/include). (The explicit unset ac_cv_header_MultiFormatWriter_h is needed so that the second and later iterations of the for loop don't erroneously reuse a cached "no" result.) Change-Id: Id85f9960ffd3759c7960ef3a81982b85bc3c04c1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133189 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- configure.ac | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 1d432bc77a7b..a43d6bddd344 100644 --- a/configure.ac +++ b/configure.ac @@ -11143,10 +11143,32 @@ else if test "$with_system_zxing" = "yes"; then AC_MSG_RESULT([external]) SYSTEM_ZXING=TRUE + ZXING_CFLAGS= AC_LANG_PUSH([C++]) - AC_CHECK_HEADER(ZXing/MultiFormatWriter.h, [], - [AC_MSG_ERROR(zxing headers not found.)], [#include ]) - ZXING_CFLAGS=-I/usr/include/ZXing + save_CXXFLAGS=$CXXFLAGS + save_IFS=$IFS + IFS=$P_SEP + for i in $CPLUS_INCLUDE_PATH /usr/include; do + dnl Reset IFS as soon as possible, to avoid unexpected side effects (and the + dnl "/usr/include" fallback makes sure we get here at least once; resetting rather than + dnl unsetting follows the advice at "Add recommendation on (not) + dnl unsetting IFS."): + IFS=$save_IFS + dnl TODO: GCC and Clang treat empty paths in CPLUS_INCLUDE_PATH like ".", but we simply + dnl ignore them here: + if test -z "$i"; then + continue + fi + dnl TODO: White space in $i would cause problems: + CXXFLAGS="$save_CXXFLAGS -I$i/ZXing" + AC_CHECK_HEADER(MultiFormatWriter.h, [ZXING_CFLAGS=-I$i/ZXing; break], + [unset ac_cv_header_MultiFormatWriter_h], [#include ]) + done + CXXFLAGS=$save_CXXFLAGS + if test -z "$ZXING_CFLAGS"; then + AC_MSG_ERROR(zxing headers not found.) + fi AC_CHECK_LIB([ZXing], [main], [ZXING_LIBS=-lZXing], [ AC_CHECK_LIB([ZXingCore], [main], [ZXING_LIBS=-lZXingCore], [ AC_MSG_ERROR(zxing C++ library not found.) ])], []) -- cgit