image: debian:unstable

stages:
  - build
  - document
  - publish

before_script:
  - echo 'deb-src http://deb.debian.org/debian unstable main' >> /etc/apt/sources.list
  - apt-get update
  - apt-get build-dep --yes --no-install-recommends poppler
  - apt-get install --yes --no-install-recommends ninja-build libcurl4-openssl-dev git ca-certificates locales libgtk-3-dev libbrotli-dev libboost-container-dev qt6-base-dev
  - echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
  - locale-gen

variables:
  LANG: en_US.UTF-8
  LANGUAGE: en_US:en
  LC_ALL: en_US.UTF-8
  DEBIAN_FRONTEND: noninteractive
  TEST_DATA_URL: https://gitlab.freedesktop.org/${CI_PROJECT_NAMESPACE}/test.git
  UPSTREAM_TEST_DATA_URL: https://gitlab.freedesktop.org/poppler/test.git

cache:
  key: "$CI_JOB_NAME"
  paths:
    - build/

clang_format:
  stage: build
  before_script:
  - apt-get update
  - apt-get install --yes --no-install-recommends git clang-format-21
  script:
    - find . \( -name "*.cpp" -or -name "*.h"  -or -name "*.c"  -or -name "*.cc" \) -exec clang-format-21 -i {} \;
    - git diff --exit-code

build:
  stage: build
  script:
    - apt-get update
    - bash do-the-gnupg-2.4-dance.sh $PWD/build/gnupg/
    - git clone --branch ${CI_COMMIT_REF_NAME} --depth 1 ${TEST_DATA_URL} test-data || git clone --depth 1 ${UPSTREAM_TEST_DATA_URL} test-data
    - mkdir -p build && cd build
    - cmake -G Ninja -DTESTDATADIR=$PWD/../test-data -DCMAKE_PREFIX_PATH=$PWD/gnupg -DENABLE_UNSTABLE_API_ABI_HEADERS=ON -DVERIFY_PUBLIC_PRIVATE_HEADERS=true ..
    - ninja -j ${FDO_CI_CONCURRENT}
    - ninja -j ${FDO_CI_CONCURRENT} all_verify_interface_header_sets
    - ctest --output-on-failure

build_clang17_libcpp_cmake328:
  stage: build
  image: debian:trixie
  script:
    - echo "This is to simulate xcode 16.2 that is the minimum macos version we support"
    - git clone --branch ${CI_COMMIT_REF_NAME} --depth 1 ${TEST_DATA_URL} test-data || git clone --depth 1 ${UPSTREAM_TEST_DATA_URL} test-data
    - apt-get install --yes --no-install-recommends libclang-17-dev llvm-17-dev libc++-17-dev libc++abi-17-dev clang-17 clang-tools-17 libunwind-17-dev gperf jq
    - mkdir -p build && cd build
    - echo "We disable Qt6 tests since Qt6 exposes std::string in its ABI which makes it not build in this CI since we're using libc++ but Qt6 in debian is build with libstdc++"
    - CC=clang-17 CXX=clang++-17 cmake -G Ninja -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Werror -Wno-deprecated-declarations -Wno-error=unused-command-line-argument" -DTESTDATADIR=$PWD/../test-data -DBUILD_QT6_TESTS=OFF -DENABLE_GPGME=OFF ..
    - ninja -j ${FDO_CI_CONCURRENT}
    - ctest --output-on-failure

build_clang22_libcpp:
  stage: build
  script:
    - echo "We pretend not to have gettext so the GooString::format calls with _( in pdfsig don't complain we're giving it a non literal"
    - sed -i -e "s@#ifdef HAVE_GETTEXT@#if false@g" utils/pdfsig.cc
    - git clone --branch ${CI_COMMIT_REF_NAME} --depth 1 ${TEST_DATA_URL} test-data || git clone --depth 1 ${UPSTREAM_TEST_DATA_URL} test-data
    - apt-get install --yes --no-install-recommends libclang-22-dev llvm-22-dev libc++-22-dev libc++abi-22-dev clang-tidy-22 clang-22 libunwind-22-dev gperf jq
    - srcdir=`pwd` && mkdir -p /tmp/poppler_build && cd /tmp/poppler_build
    - clang++-22 -fPIC -shared -o goostring-format-checker.so $srcdir/test/goostring-format-checker/goostring-format-checker.cc -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -I /usr/lib/llvm-22/include/
    - echo "We disable Qt6 tests since Qt6 exposes std::string in its ABI which makes it not build in this CI since we're using libc++ but Qt6 in debian is build with libstdc++"
    - CC=clang-22 CXX=clang++-22 cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++ -Xclang -load -Xclang $PWD/goostring-format-checker.so -Xclang -add-plugin -Xclang goostring-format-checker -Werror -Wno-deprecated-declarations -Wno-error=unused-command-line-argument -Wno-error=c2y-extensions" -DTESTDATADIR=$srcdir/test-data -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_QT6_TESTS=OFF -DENABLE_GPGME=OFF $srcdir
    - make -j ${FDO_CI_CONCURRENT}
    - ctest --output-on-failure
    - echo "This is a complex way of not running clang-tidy over autogenerated files, unfortunately -DCMAKE_CXX_CLANG_TIDY doesn't support that https://gitlab.kitware.com/cmake/cmake/-/issues/19772"
    - cat compile_commands.json | jq  '[.[] | select(.file | contains("'"$srcdir"'"))]' > compile_commands.aux.json
    - cat compile_commands.aux.json | jq  '[.[] | select(.file | contains("pregenerated")| not)]' > compile_commands.json
    - echo "Cheat a bit and remove the moc includes so that we don't lint autogenerated code"
    - echo "Maybe we can replace this with NOLINTBEGIN in the future https://github.com/llvm/llvm-project/issues/56983"
    - find $srcdir/qt* -name *.cpp -exec sed -E -i '/#include .*moc"$/d' {} \;
    - cp "$srcdir/.clang-tidy" .
    - run-clang-tidy-22

build_ubuntu_24_04:
  stage: build
  image: ubuntu:24.04
  before_script:
    - sed -i s/http/ftp/ /etc/apt/sources.list
    - echo 'Dir::Bin::Methods::ftp "ftp";' > /etc/apt/apt.conf.d/99local-ftp
    - apt-get update
    - apt-get install --yes --no-install-recommends build-essential cmake ninja-build libjpeg-dev libopenjp2-7-dev qtbase5-dev gobject-introspection libglib2.0-dev libgtk-3-dev libgirepository1.0-dev libnss3-dev ca-certificates libcurl4-openssl-dev liblcms2-dev libboost-container-dev libtiff-dev wget p7zip-full git qt6-base-dev clang clang-tools libc++-dev libc++abi-dev libnghttp2-dev libidn2-dev librtmp-dev libssh-dev libpsl-dev libkrb5-dev libldap2-dev libzstd-dev libwebp-dev
  script:
    - git clone --branch ${CI_COMMIT_REF_NAME} --depth 1 ${TEST_DATA_URL} test-data || git clone --depth 1 ${UPSTREAM_TEST_DATA_URL} test-data
    - mkdir -p build && cd build
    - cmake -G Ninja -DENABLE_GPGME=OFF -DTESTDATADIR=$PWD/../test-data ..
    - ninja
    - ctest --output-on-failure
    - cd .. && mkdir -p build_clang && cd build_clang
    - echo "We disable Qt6 tests since Qt6 exposes std::string in its ABI which makes it not build in this CI since we're using libc++ but Qt6 in debian is build with libstdc++"
    - CC=clang CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++ -fexperimental-library" -G Ninja -DENABLE_GPGME=OFF -DBUILD_QT6_TESTS=OFF -DTESTDATADIR=$PWD/../test-data ..
    - ninja
    - ctest --output-on-failure
    - cd .. && mkdir -p build_nondefault_options && cd build_nondefault_options
    - cmake -G Ninja -DENABLE_LIBOPENJPEG=OFF -DENABLE_LIBJPEG=OFF -DENABLE_LCMS=OFF -DENABLE_LIBCURL=OFF -DENABLE_LIBTIFF=OFF -DENABLE_NSS3=OFF -DENABLE_GPGME=OFF -DENABLE_ZLIB_UNCOMPRESS=ON -DENABLE_BOOST=OFF -DTESTDATADIR=$PWD/../test-data ..
    - ninja
    - cd .. && mkdir -p build_static && cd build_static
    - cmake -G Ninja -DENABLE_GPGME=OFF -DTESTDATADIR=$PWD/../test-data -DBUILD_SHARED_LIBS=OFF ..
    - ninja install
    - cd ../test/pkgconfig_test && mkdir -p build && cd build
    - PKG_CONFIG="$(which pkg-config) --static" cmake -G Ninja ..
    - ninja

build_mingw64_fedora44:
  stage: build
  image: fedora:44
  before_script:
    - dnf install -y 'dnf-command(builddep)'
    - dnf builddep -y mingw64-poppler
    - dnf -y install glibc-langpack-en make ninja-build mingw64-boost mingw64-curl mingw64-qt6-qtbase mingw64-gcc-c++ cmake-rpm-macros
  script:
    - mkdir -p build && cd build
    - mingw64-cmake -DENABLE_NSS3=OFF -DENABLE_GPGME=OFF -DENABLE_BOOST=OFF -G Ninja ..
    - ninja

build_clazy_fedora44_clang22:
  stage: build
  image: fedora:44
  before_script:
    - dnf install -y 'dnf-command(builddep)'
    - dnf builddep -y poppler
    - dnf -y install clazy ninja-build glibc-langpack-en
  script:
    - mkdir -p build && cd build
    - CC=clang-22 CXX=clazy CXXFLAGS="-Werror -Wno-deprecated-declarations -Wno-error=c2y-extensions" cmake -G Ninja ..
    - CLAZY_CHECKS="level0,level1,level2,isempty-vs-count,qhash-with-char-pointer-key,tr-non-literal,no-non-pod-global-static" ninja -j ${FDO_CI_CONCURRENT}

build_qt611_android:
  stage: build
  image: invent-registry.kde.org/sysadmin/ci-images/android-qt611-ci
  before_script:
    - echo "workaround for ECM Android toolchain wanting all binaries to be shared libraries"
    - sed -i -e 's/<LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>/<LINK_FLAGS>/g' /opt/nativetooling/share/ECM/toolchain/Android.cmake
    - sudo apt install --yes wget
  script:
    - wget https://download.savannah.gnu.org/releases/freetype/freetype-2.13.3.tar.xz
    - tar xvfh freetype-2.13.3.tar.xz
    - cd freetype-2.13.3
    - mkdir -p build && cd build
    - 'ANDROID_ARCH_ABI=arm64-v8a cmake -G Ninja ..
                         -DCMAKE_ANDROID_API=29
                         -DCMAKE_BUILD_TYPE=debug
                         -DCMAKE_POSITION_INDEPENDENT_CODE=OFF
                         -DCMAKE_TOOLCHAIN_FILE=/home/user/android-arm64-clang/lib/cmake/Qt6/qt.toolchain.cmake
                         -DQT_CHAINLOAD_TOOLCHAIN_FILE=/opt/nativetooling/share/ECM/toolchain/Android.cmake
                         -DCMAKE_INSTALL_PREFIX=/home/user/android-arm-clang
                         -DBUILD_SHARED_LIBS=ON'
    - ninja -j ${FDO_CI_CONCURRENT} install
    - cd ../..
    - mkdir -p build && cd build
    - 'ANDROID_ARCH_ABI=arm64-v8a cmake -G Ninja ..
                         -DCMAKE_ANDROID_API=29
                         -DCMAKE_PREFIX_PATH="/home/user/android-arm-clang"
                         -DCMAKE_BUILD_TYPE=debug
                         -DCMAKE_POSITION_INDEPENDENT_CODE=OFF
                         -DENABLE_LIBJPEG=OFF
                         -DENABLE_LIBOPENJPEG=OFF
                         -DENABLE_BOOST=OFF
                         -DENABLE_LCMS=OFF
                         -DENABLE_LIBCURL=OFF
                         -DENABLE_LIBTIFF=OFF
                         -DENABLE_QT5=OFF
                         -DENABLE_NSS3=OFF
                         -DENABLE_GPGME=OFF
                         -DCMAKE_CXX_FLAGS="-Werror -Wno-deprecated-declarations"
                         -DCMAKE_TOOLCHAIN_FILE=/home/user/android-arm64-clang/lib/cmake/Qt6/qt.toolchain.cmake
                         -DQT_CHAINLOAD_TOOLCHAIN_FILE=/opt/nativetooling/share/ECM/toolchain/Android.cmake'
    - ninja -j ${FDO_CI_CONCURRENT}

qt5_docs:
  only:
    - master
  stage: document
  variables:
    QT_SELECT: qt5
  script:
    - apt-get install --yes --no-install-recommends doxygen graphviz qtchooser qttools5-dev-tools
    - cd qt5/src
    - doxygen
  cache: {}
  artifacts:
    paths:
      - qt5/src/APIDOCS-html

qt6_docs:
  only:
    - master
  stage: document
  script:
    - apt-get install --yes --no-install-recommends doxygen graphviz qt6-documentation-tools
    - cd qt6/src
    - ( cat Doxyfile ; echo "QHG_LOCATION=/usr/lib/qt6/bin/qhelpgenerator" ) | doxygen -
  cache: {}
  artifacts:
    paths:
      - qt6/src/APIDOCS-html

cpp_docs:
  only:
    - master
  stage: document
  script:
    - apt-get install --yes --no-install-recommends doxygen graphviz
    - cd cpp
    - doxygen
  cache: {}
  artifacts:
    paths:
      - cpp/APIDOCS-html

glib_docs:
  only:
    - master
  stage: document
  script:
    - apt-get install --yes --no-install-recommends gtk-doc-tools
    - mkdir -p build && cd build
    - cmake -G Ninja -DENABLE_GTK_DOC=YES -DENABLE_GPGME=OFF ..
    - ninja -j ${FDO_CI_CONCURRENT} glib-docs
  cache: {}
  artifacts:
    paths:
      - build/glib/reference/html

trigger_pages:
  only:
    - master
  stage: publish
  image: alpine:latest
  before_script:
    - apk --update upgrade
    - apk add curl ca-certificates
  script:
    - 'curl --request POST --form "token=$WEB_PAGE_TRIGGER" --form ref=master https://gitlab.freedesktop.org/api/v4/projects/poppler%2Fpoppler-web-page/trigger/pipeline'
  cache: {}
