mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-04-06 00:32:05 +02:00
159 lines
4.5 KiB
Batchfile
159 lines
4.5 KiB
Batchfile
@REM OrcaSlicer build script for Windows with VS auto-detect
|
|
@echo off
|
|
set WP=%CD%
|
|
set _START_TIME=%TIME%
|
|
|
|
@REM Check for Ninja Multi-Config option (-x)
|
|
set USE_NINJA=0
|
|
for %%a in (%*) do (
|
|
if "%%a"=="-x" set USE_NINJA=1
|
|
)
|
|
|
|
if "%USE_NINJA%"=="1" (
|
|
echo Using Ninja Multi-Config generator
|
|
set CMAKE_GENERATOR="Ninja Multi-Config"
|
|
set VS_VERSION=Ninja
|
|
goto :generator_ready
|
|
)
|
|
|
|
@REM Detect Visual Studio version using msbuild
|
|
echo Detecting Visual Studio version using msbuild...
|
|
|
|
@REM Try to get MSBuild version - the output format varies by VS version
|
|
set VS_MAJOR=
|
|
for /f "tokens=*" %%i in ('msbuild -version 2^>^&1 ^| findstr /r "^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"') do (
|
|
for /f "tokens=1 delims=." %%a in ("%%i") do set VS_MAJOR=%%a
|
|
set MSBUILD_OUTPUT=%%i
|
|
goto :version_found
|
|
)
|
|
|
|
@REM Alternative method for newer MSBuild versions
|
|
if "%VS_MAJOR%"=="" (
|
|
for /f "tokens=*" %%i in ('msbuild -version 2^>^&1 ^| findstr /r "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"') do (
|
|
for /f "tokens=1 delims=." %%a in ("%%i") do set VS_MAJOR=%%a
|
|
set MSBUILD_OUTPUT=%%i
|
|
goto :version_found
|
|
)
|
|
)
|
|
|
|
:version_found
|
|
echo MSBuild version detected: %MSBUILD_OUTPUT%
|
|
echo Major version: %VS_MAJOR%
|
|
|
|
if "%VS_MAJOR%"=="" (
|
|
echo Error: Could not determine Visual Studio version from msbuild
|
|
echo Please ensure Visual Studio and MSBuild are properly installed
|
|
exit /b 1
|
|
)
|
|
|
|
if "%VS_MAJOR%"=="16" (
|
|
set VS_VERSION=2019
|
|
set CMAKE_GENERATOR="Visual Studio 16 2019"
|
|
) else if "%VS_MAJOR%"=="17" (
|
|
set VS_VERSION=2022
|
|
set CMAKE_GENERATOR="Visual Studio 17 2022"
|
|
) else if "%VS_MAJOR%"=="18" (
|
|
set VS_VERSION=2026
|
|
set CMAKE_GENERATOR="Visual Studio 18 2026"
|
|
) else (
|
|
echo Error: Unsupported Visual Studio version: %VS_MAJOR%
|
|
echo Supported versions: VS2019 (16.x^), VS2022 (17.x^), VS2026 (18.x^)
|
|
exit /b 1
|
|
)
|
|
|
|
echo Detected Visual Studio %VS_VERSION% (version %VS_MAJOR%)
|
|
echo Using CMake generator: %CMAKE_GENERATOR%
|
|
|
|
:generator_ready
|
|
|
|
@REM Pack deps
|
|
if "%1"=="pack" (
|
|
setlocal ENABLEDELAYEDEXPANSION
|
|
cd %WP%/deps/build
|
|
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set build_date=%%c%%b%%a
|
|
echo packing deps: OrcaSlicer_dep_win64_!build_date!_vs!VS_VERSION!.zip
|
|
|
|
%WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs!VS_VERSION!.zip OrcaSlicer_dep
|
|
goto :done
|
|
)
|
|
|
|
set debug=OFF
|
|
set debuginfo=OFF
|
|
if "%1"=="debug" set debug=ON
|
|
if "%2"=="debug" set debug=ON
|
|
if "%1"=="debuginfo" set debuginfo=ON
|
|
if "%2"=="debuginfo" set debuginfo=ON
|
|
if "%debug%"=="ON" (
|
|
set build_type=Debug
|
|
set build_dir=build-dbg
|
|
) else (
|
|
if "%debuginfo%"=="ON" (
|
|
set build_type=RelWithDebInfo
|
|
set build_dir=build-dbginfo
|
|
) else (
|
|
set build_type=Release
|
|
set build_dir=build
|
|
)
|
|
)
|
|
echo build type set to %build_type%
|
|
|
|
setlocal DISABLEDELAYEDEXPANSION
|
|
cd deps
|
|
mkdir %build_dir%
|
|
cd %build_dir%
|
|
set "SIG_FLAG="
|
|
if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%"
|
|
|
|
if "%1"=="slicer" (
|
|
GOTO :slicer
|
|
)
|
|
echo "building deps.."
|
|
|
|
echo on
|
|
REM Set minimum CMake policy to avoid <3.5 errors
|
|
set CMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
if "%USE_NINJA%"=="1" (
|
|
cmake ../ -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=%build_type%
|
|
cmake --build . --config %build_type% --target deps
|
|
) else (
|
|
cmake ../ -G %CMAKE_GENERATOR% -A x64 -DCMAKE_BUILD_TYPE=%build_type%
|
|
cmake --build . --config %build_type% --target deps -- -m
|
|
)
|
|
@echo off
|
|
|
|
if "%1"=="deps" goto :done
|
|
|
|
:slicer
|
|
echo "building Orca Slicer..."
|
|
cd %WP%
|
|
mkdir %build_dir%
|
|
cd %build_dir%
|
|
|
|
echo on
|
|
set CMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
if "%USE_NINJA%"=="1" (
|
|
cmake .. -G %CMAKE_GENERATOR% -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_BUILD_TYPE=%build_type%
|
|
cmake --build . --config %build_type% --target ALL_BUILD
|
|
) else (
|
|
cmake .. -G %CMAKE_GENERATOR% -A x64 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_BUILD_TYPE=%build_type%
|
|
cmake --build . --config %build_type% --target ALL_BUILD -- -m
|
|
)
|
|
@echo off
|
|
cd ..
|
|
call scripts/run_gettext.bat
|
|
cd %build_dir%
|
|
cmake --build . --target install --config %build_type%
|
|
|
|
:done
|
|
@echo off
|
|
for /f "tokens=1-3 delims=:.," %%a in ("%_START_TIME: =0%") do set /a "_start_s=%%a*3600+%%b*60+%%c"
|
|
for /f "tokens=1-3 delims=:.," %%a in ("%TIME: =0%") do set /a "_end_s=%%a*3600+%%b*60+%%c"
|
|
set /a "_elapsed=_end_s - _start_s"
|
|
if %_elapsed% lss 0 set /a "_elapsed+=86400"
|
|
set /a "_hours=_elapsed / 3600"
|
|
set /a "_remainder=_elapsed - _hours * 3600"
|
|
set /a "_mins=_remainder / 60"
|
|
set /a "_secs=_remainder - _mins * 60"
|
|
echo.
|
|
echo Build completed in %_hours%h %_mins%m %_secs%s
|