if has nix; then
    use flake
fi

shopt -s globstar
watch_file plugin/**/*.cpp
watch_file plugin/**/*.hpp
watch_file plugin/**/*.qml
watch_file plugin/**/*.vert
watch_file plugin/**/*.frag
watch_file **/CMakeLists.txt

if ! cmake --build build --target help &> /dev/null; then
    args=()
    if has clazy; then
        args+=(-DCMAKE_CXX_COMPILER=clazy)
    else
        args+=(-DCMAKE_CXX_COMPILER=clang++)
    fi
    if has ccache; then
        args+=(-DCMAKE_CXX_COMPILER_LAUNCHER=ccache)
    fi

    cmake -B build -G Ninja \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
        -DDISTRIBUTOR=direnv \
        "${args[@]}"
fi
cmake --build build

export CAELESTIA_LIB_DIR="$PWD/build/lib"
export QML2_IMPORT_PATH="$PWD/build/qml:${QML2_IMPORT_PATH:-}"
