## Build daq_viewer for CODAC Core OS 7.3 (RHEL 8.5 / UBI8)
##
## Usage:
##   docker build -f Dockerfile.ubi8 -t daq-builder .
##   cid=$(docker create daq-builder)
##   docker cp $cid:/build/daq_viewer .
##   docker rm $cid
##   scp daq_viewer codac-host:/opt/daq/

FROM redhat/ubi8:8.5 AS builder

RUN dnf install -y \
    gcc-toolset-10-gcc-c++ \
    cmake \
    make \
    qt5-qtbase-devel \
    libX11-devel \
    mesa-libGL-devel \
    mesa-libEGL-devel \
    && dnf clean all

# Enable GCC 10 (C++17 support)
SHELL ["/usr/bin/bash", "-c", "source /opt/rh/gcc-toolset-10/enable && exec /usr/bin/bash -c \"$@\"", "--"]
ENV PATH="/opt/rh/gcc-toolset-10/root/usr/bin:$PATH"

WORKDIR /src
COPY . /src/Client/NativeUI-Qt
COPY Client/NativeUI/src /src/Client/NativeUI/src

WORKDIR /build
RUN cmake /src/Client/NativeUI-Qt \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++" \
    && cmake --build . --parallel $(nproc)
