# Prebuilt build image for the Release 2 scope
# (Ubuntu 26.04 + Qt 6.10.2 + all dependencies for the legatus release 2 build).
#
# This is the single source of truth for the image recipe:
# new_docker_build.sh builds the image from this file when the image is
# missing (--use-prebuilt-image, the default) or must be rebuilt
# (--no-prebuilt-image).
#
# Note: libbz2-dev (BZip2) is required by Z/src/nglcompression.
# libpoppler-qt6-dev provides the poppler-qt6 pkg-config module: without it
# nglwidgets builds without PDF support (HAVE_POPPLER_QT6=OFF) and the
# test_nglpdfwidget target does not exist.

FROM ubuntu:26.04

ENV DEBIAN_FRONTEND=noninteractive

ARG QT_VERSION=6.10.2
ARG QT_ARCH=linux_gcc_64
ARG QT_BASE_DIR=/opt/Qt

RUN apt-get update -qq && \
    apt-get install -y -qq \
      build-essential \
      cmake \
      ninja-build \
      git \
      python3-pip \
      libboost-dev \
      libbz2-dev \
      libgl1-mesa-dev \
      libpoppler-qt6-dev \
      pkg-config \
      libkf6texttemplate-dev \
      libgtest-dev \
      libgmock-dev \
      libpq-dev \
      postgresql-server-dev-all \
      libvlc-dev \
      vlc-plugin-base \
      libssl-dev \
      libxml2-dev \
      libxerces-c-dev \
      lcov \
      && \
    rm -rf /var/lib/apt/lists/*

# Install Qt6 packages via aqtinstall
RUN pip3 install --break-system-packages --quiet aqtinstall && \
    aqt install-qt linux desktop ${QT_VERSION} ${QT_ARCH} \
      -m qtmultimedia qtserialport qtimageformats qtwebsockets qtwebengine \
         qtpdf qtwebview qt5compat qtwebchannel qtpositioning qtlocation qtsensors \
      --outputdir ${QT_BASE_DIR} && \
    rm -rf /root/.cache/Aqt

# Install KDReports from source (no apt package on Ubuntu 26.04)
RUN git clone --depth 1 https://github.com/KDAB/KDReports.git /tmp/KDReports && \
    cd /tmp/KDReports && \
    mkdir build && cd build && \
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=${QT_BASE_DIR} .. && \
    make -j$(nproc) && \
    make install && \
    cd / && rm -rf /tmp/KDReports

# Legacy sources include <KDReports/...>
RUN ln -sfn KDReports-qt6 /usr/local/include/KDReports

ENV PATH="${QT_BASE_DIR}/${QT_VERSION}/gcc_64/bin:${PATH}"
ENV CMAKE_PREFIX_PATH="${QT_BASE_DIR}/${QT_VERSION}/gcc_64"

CMD ["/bin/bash"]
