# Generated by vinca http://github.com/RoboStack/vinca.
# DO NOT EDIT!
set -eo pipefail

BUILD_DIR=@BUILD_DIR@

if [ ! -d "$BUILD_DIR" ]; then
    mkdir -p "$BUILD_DIR"
fi
pushd $BUILD_DIR

BUILD_TYPE=@BUILD_TYPE@

# necessary for correctly linking SIP files (from python_qt_bindings)
export LINK=$CXX

if [[ $CONDA_BUILD_CROSS_COMPILATION != "1" ]]; then
    PYTHON_EXECUTABLE=$PREFIX/bin/python
    PKG_CONFIG_EXECUTABLE=$PREFIX/bin/pkg-config
    export QT_HOST_PATH="$PREFIX"
else
    PYTHON_EXECUTABLE=$BUILD_PREFIX/bin/python
    PKG_CONFIG_EXECUTABLE=$BUILD_PREFIX/bin/pkg-config
    export QT_HOST_PATH="$BUILD_PREFIX"
fi

# Only support 11.0+ for now
OSX_DEPLOYMENT_TARGET="11.0"

# Added to help make portable builds when using <inttypes.h> in C++ code.
if [[ $target_platform =~ linux.* ]]; then
    export CFLAGS="${CFLAGS} -D__STDC_FORMAT_MACROS=1"
    export CXXFLAGS="${CXXFLAGS} -D__STDC_FORMAT_MACROS=1"
fi

echo "USING PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
echo "USING PKG_CONFIG_EXECUTABLE=${PKG_CONFIG_EXECUTABLE}"
export ROS_PYTHON_VERSION=3
echo "Using Python ${ROS_PYTHON_VERSION}"
echo "Using PREFIX: $PREFIX"
echo "Using SP_DIR: $SP_DIR"
echo "Using CONDA_BUILD: $CONDA_BUILD"
echo "Using CPU_COUNT: $CPU_COUNT"
export PY_VER=${ROS_PYTHON_VERSION}
echo "Using PY_VER: $PY_VER"
echo "Using PYTHON: $PYTHON"
echo "Using STDLIB_DIR: $STDLIB_DIR"
echo "Using ROS_PYTHON_VERSION: $ROS_PYTHON_VERSION"
echo "Using SRC_DIR: $SRC_DIR"
export PYTHON_INSTALL_DIR=$(realpath --relative-to="$PREFIX" "$SP_DIR")
echo "Using PYTHON_INSTALL_DIR: $PYTHON_INSTALL_DIR"

if [ ! -f "build.ninja" ]; then
    cmake \
        -G "Ninja" \
        -S @SRC_DIR@ \
        -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
        -DCMAKE_INSTALL_PREFIX=$PREFIX \
        -DCMAKE_PREFIX_PATH=$PREFIX \
        -DAMENT_PREFIX_PATH=$PREFIX \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
        -DPython_EXECUTABLE=$PYTHON_EXECUTABLE \
        -DPython3_EXECUTABLE=$PYTHON_EXECUTABLE \
        -DPython3_FIND_STRATEGY=LOCATION \
        -DPKG_CONFIG_EXECUTABLE=$PKG_CONFIG_EXECUTABLE \
        -DPYTHON_INSTALL_DIR=$PYTHON_INSTALL_DIR \
        -DSETUPTOOLS_DEB_LAYOUT=OFF \
        -DCATKIN_SKIP_TESTING=$SKIP_TESTING \
        -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=True \
        -DBUILD_SHARED_LIBS=ON \
        -DBUILD_TESTING=OFF \
        -DCMAKE_IGNORE_PREFIX_PATH="/opt/homebrew;/usr/local/homebrew" \
        -DCMAKE_OSX_DEPLOYMENT_TARGET=$OSX_DEPLOYMENT_TARGET \
        --compile-no-warning-as-error \
        $EXTRA_CMAKE_ARGS \
        .
fi

cmake --build . --config $BUILD_TYPE --target install
