#!/bin/sh

set -x

BUILD_TYPE=$1

JOBS=4

cmake \
    -S tlRender/etc/SuperBuild \
    -B sbuild-$BUILD_TYPE \
    -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
    -DCMAKE_INSTALL_PREFIX=$PWD/install-$BUILD_TYPE \
    -DCMAKE_PREFIX_PATH=$PWD/install-$BUILD_TYPE \
    -Dftk_API=$FTK_API \
    -DTLRENDER_NET=$TLRENDER_NET \
    -DTLRENDER_OCIO=$TLRENDER_OCIO \
    -DTLRENDER_JPEG=$TLRENDER_JPEG \
    -DTLRENDER_TIFF=$TLRENDER_TIFF \
    -DTLRENDER_STB=$TLRENDER_STB \
    -DTLRENDER_EXR=$TLRENDER_EXR \
    -DTLRENDER_FFMPEG=$TLRENDER_FFMPEG \
    -DTLRENDER_FFMPEG_MINIMAL=$TLRENDER_FFMPEG_MINIMAL \
    -DTLRENDER_USD=$TLRENDER_USD \
    -DTLRENDER_BMD=$TLRENDER_BMD \
    -DTLRENDER_BMD_SDK=$TLRENDER_BMD_SDK \
    -DTLRENDER_QT6=$TLRENDER_QT6 \
    -DTLRENDER_QT5=$TLRENDER_QT5 \
    -DTLRENDER_GCOV=$TLRENDER_GCOV
cmake --build sbuild-$BUILD_TYPE -j $JOBS --config $BUILD_TYPE

cmake \
    -S tlRender \
    -B build-$BUILD_TYPE \
    -DCMAKE_INSTALL_PREFIX=$PWD/install-$BUILD_TYPE \
    -DCMAKE_PREFIX_PATH=$PWD/install-$BUILD_TYPE \
    -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
    -Dftk_API=$FTK_API \
    -DTLRENDER_NET=$TLRENDER_NET \
    -DTLRENDER_OCIO=$TLRENDER_OCIO \
    -DTLRENDER_JPEG=$TLRENDER_JPEG \
    -DTLRENDER_TIFF=$TLRENDER_TIFF \
    -DTLRENDER_STB=$TLRENDER_STB \
    -DTLRENDER_EXR=$TLRENDER_EXR \
    -DTLRENDER_FFMPEG=$TLRENDER_FFMPEG \
    -DTLRENDER_USD=$TLRENDER_USD \
    -DTLRENDER_BMD=$TLRENDER_BMD \
    -DTLRENDER_BMD_SDK=$TLRENDER_BMD_SDK \
    -DTLRENDER_QT6=$TLRENDER_QT6 \
    -DTLRENDER_QT5=$TLRENDER_QT5 \
    -DTLRENDER_PROGRAMS=$TLRENDER_PROGRAMS \
    -DTLRENDER_EXAMPLES=$TLRENDER_EXAMPLES \
    -DTLRENDER_TESTS=$TLRENDER_TESTS \
    -DTLRENDER_GCOV=$TLRENDER_GCOV
cmake --build build-$BUILD_TYPE -j $JOBS --config $BUILD_TYPE
cmake --build build-$BUILD_TYPE --config $BUILD_TYPE --target install
