#!/bin/bash

# Generated by cmake - rerun to reconfigure

dry_run_flag=false

# Parse arguments
while [[ $# -gt 0 ]]; do
    case "$1" in
        -n|--dry-run)
            dry_run_flag=true
            ;;
        --)
            break;
            ;;
        *)
            echo "error: xo-reconfigure: unexpected argument [$1]"
            echo "usage: xo-reconfigure"
            echo "       xo-reconfigure [-n] -- CMAKE_ARGS"
            exit 1
    esac

    shift
done

# Build the cmake command
CMAKE_CMD=(
    cmake
    -B @CMAKE_BINARY_DIR@
    -S @CMAKE_SOURCE_DIR@
    -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@
    -DCMAKE_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@
    -DCMAKE_INSTALL_DOCDIR=@CMAKE_INSTALL_DOCDIR@
    -DCMAKE_MODULE_PATH=@CMAKE_MODULE_PATH@
    -DCMAKE_PREFIX_PATH=@CMAKE_PREFIX_PATH@
    -DCMAKE_CXX_STANDARD=@CMAKE_CXX_STANDARD@
    -DXO_CMAKE_CONFIG_EXECUTABLE=@XO_CMAKE_CONFIG_EXECUTABLE@
    -DENABLE_TESTING=@ENABLE_TESTING@
    -DXO_ENABLE_DOCS=@XO_ENABLE_DOCS@
    -DXO_ENABLE_ASM=@XO_ENABLE_ASM@
    -DXO_ENABLE_EXAMPLES=@XO_ENABLE_EXAMPLES@
    -DXO_ENABLE_VULKAN=@XO_ENABLE_VULKAN@
    -DXO_ENABLE_OPENGL=@XO_ENABLE_OPENGL@

    "${@}"
)

if [[ ${dry_run_flag} = true ]]; then
    # Print the command with proper quoting for copy-paste
    printf '%q ' "${CMAKE_CMD[@]}" | sed -e 's: -D: \\\n    -D:g'
    printf '\n'
else
    # Execute the command
    "${CMAKE_CMD[@]}"
fi
