configure.ac |   28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

New commits:
commit 320b5de4f005ce317ab5873625be55c19f32b807
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Tue Apr 19 22:03:37 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Apr 29 13:02:53 2022 +0200

    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 <BarcodeFormat.h>
    
    etc. rather than
    
      #include <ZXing/BarcodeFormat.h>
    
    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 <sberg...@redhat.com>
    (cherry picked from commit 27c850b2ea3d004b380921de6664c50e6d54d4f5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133484
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/configure.ac b/configure.ac
index dab4326616b0..0be3513046e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11131,10 +11131,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 <stdexcept>])
-        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 
<http://git.savannah.gnu.org/gitweb/?p=autoconf.git;
+            dnl a=commit;h=e51c9919f2cf70185b7916ac040bc0bbfd0f743b> "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 
<stdexcept>])
+        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.) ])], [])

Reply via email to