:: Generated by vinca http://github.com/RoboStack/vinca.
:: DO NOT EDIT!

setlocal
:: Rattler-build will not set the SRC_DIR anymore so we set it through templating
set "SRC_DIR=@SRC_DIR@"

set "PYTHONPATH=%LIBRARY_PREFIX%\lib\site-packages;%SP_DIR%"

:: MSVC is preferred.
set CC=cl.exe
set CXX=cl.exe

:: ROS_BUILD_SHARED_LIBS is always defined in CMake by catkin
:: if ROS (1) is build as shared library . However, some packages are not
:: passing compilation flags from CMake to other build systems (such as qmake),
:: so we enable it explicitly via the CL environment variable, see
:: https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170
set CL=/DROS_BUILD_SHARED_LIBS=1 /DNOGDI=1

set "CATKIN_BUILD_BINARY_PACKAGE_ARGS=-DCATKIN_BUILD_BINARY_PACKAGE=1"
if "%PKG_NAME%" == "ros-@DISTRO@-catkin" (
    :: create catkin cookie to make it is a catkin workspace
    type NUL > %LIBRARY_PREFIX%\.catkin
    :: keep the workspace activation scripts (e.g., local_setup.bat)
    set CATKIN_BUILD_BINARY_PACKAGE_ARGS=
)

rd /s /q build
mkdir build
pushd build

:: TODO: setup testing logic
set SKIP_TESTING=true

cmake ^
    -G "Ninja" ^
    --compile-no-warning-as-error ^
    -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=ON ^
    -DBUILD_SHARED_LIBS=ON ^
    -DPYTHON_EXECUTABLE=%PYTHON% ^
    -DPython_EXECUTABLE=%PYTHON% ^
    -DPython3_EXECUTABLE=%PYTHON% ^
    -DSETUPTOOLS_DEB_LAYOUT=OFF ^
    -DBoost_USE_STATIC_LIBS=OFF ^
    %CATKIN_BUILD_BINARY_PACKAGE_ARGS% ^
    -DCATKIN_SKIP_TESTING=%SKIP_TESTING% ^
    %SRC_DIR%
if errorlevel 1 exit 1

if "%PKG_NAME%" == "ros-@DISTRO@-eigenpy" (
    cmake --build . --config Release --target all --parallel 1
    if errorlevel 1 exit 1
) else (
    cmake --build . --config Release --target all
    if errorlevel 1 exit 1
)

if "%SKIP_TESTING%" == "OFF" (
    cmake --build . --config Release --target run_tests
    if errorlevel 1 exit 1
)

cmake --build . --config Release --target install
if errorlevel 1 exit 1

if "%PKG_NAME%" == "ros-@DISTRO@-catkin" (
    :: Copy the [de]activate scripts to %PREFIX%\etc\conda\[de]activate.d.
    :: This will allow them to be run on environment activation.
    for %%F in (activate deactivate) DO (
        if not exist %PREFIX%\etc\conda\%%F.d mkdir %PREFIX%\etc\conda\%%F.d
        copy %RECIPE_DIR%\%%F.bat %PREFIX%\etc\conda\%%F.d\%PKG_NAME%_%%F.bat
    )
)

if "%PKG_NAME%" == "ros-@DISTRO@-ros-workspace" (
    :: Copy the [de]activate scripts to %PREFIX%\etc\conda\[de]activate.d.
    :: This will allow them to be run on environment activation.
    for %%F in (activate deactivate) DO (
        if not exist %PREFIX%\etc\conda\%%F.d mkdir %PREFIX%\etc\conda\%%F.d
        copy %RECIPE_DIR%\%%F.bat %PREFIX%\etc\conda\%%F.d\%PKG_NAME%_%%F.bat
        copy %RECIPE_DIR%\%%F.ps1 %PREFIX%\etc\conda\%%F.d\%PKG_NAME%_%%F.ps1
    )
)
