From fbd24c9f5aeefa8d554eb60768722cff933d58fd Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 8 Oct 2025 02:59:36 -0400 Subject: [PATCH 01/23] Add argument parsing --- build_release_vs2022.bat | 257 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 246 insertions(+), 11 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index b9c377488f..d8ed5efefc 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -1,9 +1,134 @@ @REM OrcaSlicer build script for Windows @echo off + +:: Unset errorlevel variable +:: If errorlevel is manually set, it is not updated upon program calls +set errorlevel= + +:: Create a local scope for the script +setlocal enableDelayedExpansion + set WP=%CD% +:: Arg definition count +set argdefn=0 + +:: Error check macro +set "error_check=if not ^!errorlevel^! == 0 echo Exiting script with code ^!errorlevel^! & exit /b ^!errorlevel^!" + +:: Define arguments +call :add_arg pack_deps bool p pack +call :add_arg build_deps bool d deps +call :add_arg build_slicer bool s slicer +call :add_arg build_debug bool b debug +call :add_arg build_debuginfo bool e debuginfo + +:: handle arguments from input +:handle_args_loop + if "%1" == "" goto :handle_args_loop_end + + setlocal + set arg=%1 + set finalize_cmd= + + call :debug_msg Begin handling arg "%arg%" + + if not "%arg:~0,2%" == "--" goto :HAL_check_short + + ::IF long arg + call :debug_msg Processing long arg + + call :find_arg long %arg:~2% + %error_check% + set idx=%ret% + + call :get_arg_type %idx% + %error_check% + set type=%ret% + + if /I "%type%" == "string" ( + set string_val=%2 + :: Ensure there is a string value + if "!string_val!" == "" ( + echo Error in handle_args_loop: The option "%arg:~2%" requires a value + exit /b 1 + ) + :: Ensure the string value isn't another argument + if "!string_val:~0,1!" == "-" ( + echo Error in handle_args_loop: The option "%arg:~2%" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. + exit /b 1 + ) + shift + ) + + call :set_arg %idx% %string_val% + %error_check% + goto :handle_args_loop_reset + + :HAL_check_short + if not "%arg:~0,1%" == "-" ( + :: IF invalid arg + echo Unknown argument: %arg% + exit /b 1 + ) + + :: IF short arg + call :debug_msg processing short args + set /A charidx=1 + :short_arg_loop + if "!arg:~%charidx%,1!" == "" goto :handle_args_loop_reset + + call :find_arg short !arg:~%charidx%,1! + %error_check% + set idx=%ret% + + call :get_arg_type %idx% + %error_check% + set type=%ret% + + set /A start_idx = %charidx% + 1 + if /I "%type%" == "string" ( + :: Check if there are additional characters after the found string argument + set remaining=!arg:~%start_idx%! + if defined remaining ( + :: If there are remaining characters, use them as the string value + set string_val=!remaining! + ) else ( + :: Otherwise, use the next argument + set string_val=%2 + shift + ) + :: Ensure there is a string value + if "!string_val!" == "" ( + echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value + exit /b 1 + ) + :: Ensure the string value isn't another argument + if "!string_val:~1!" == "-" ( + echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. + exit /b 1 + ) + call :set_arg !idx! !string_val! + %error_check% + goto :handle_args_loop_reset + ) + + call :set_arg %idx% + %error_check% + set /A charidx+=1 + goto :short_arg_loop + + :handle_args_loop_reset + :: End local scope for this loop and use finalize_cmd to set global variables from the set_arg function + endlocal %finalize_cmd% + shift + goto :handle_args_loop + +:handle_args_loop_end + + @REM Pack deps -if "%1"=="pack" ( +if "%pack_deps%"=="ON" ( setlocal ENABLEDELAYEDEXPANSION cd %WP%/deps/build for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set build_date=%%c%%b%%a @@ -13,17 +138,11 @@ if "%1"=="pack" ( exit /b 0 ) -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" ( +if "%build_debug%"=="ON" ( set build_type=Debug set build_dir=build-dbg ) else ( - if "%debuginfo%"=="ON" ( + if "%build_debuginfo%"=="ON" ( set build_type=RelWithDebInfo set build_dir=build-dbginfo ) else ( @@ -41,7 +160,7 @@ set DEPS=%CD%/OrcaSlicer_dep set "SIG_FLAG=" if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%" -if "%1"=="slicer" ( +if "%build_slicer%"=="ON" ( GOTO :slicer ) echo "building deps.." @@ -51,7 +170,7 @@ cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYP cmake --build . --config %build_type% --target deps -- -m @echo off -if "%1"=="deps" exit /b 0 +if "%build_deps%"=="ON" exit /b 0 :slicer echo "building Orca Slicer..." @@ -67,3 +186,119 @@ cd .. call scripts/run_gettext.bat cd %build_dir% cmake --build . --target install --config %build_type% + +:: End of script +exit /b 0 + + + +:: --------------------------------------------- +:: BEGIN FUNCTION DEFINITIONS +:: --------------------------------------------- + +:debug_msg + if "%debugscript%" == "ON" echo %* + exit /b 0 + +:: add_arg [] +:add_arg + call :debug_msg starting function: add_arg "%~1" "%~2" "%~3" "%~4" + + set argdefs[%argdefn%].VARIABLE_NAME=%~1 + set argdefs[%argdefn%].TYPE=%~2 + set argdefs[%argdefn%].SHORT_FLAG=%~3 + set argdefs[%argdefn%].LONG_FLAG=%~4 + + :: ensure variable is not set + set %~1= + + call :debug_msg VARIABLE_NAME: !argdefs[%argdefn%].VARIABLE_NAME! + call :debug_msg TYPE: !argdefs[%argdefn%].TYPE! + call :debug_msg SHORT_FLAG: !argdefs[%argdefn%].SHORT_FLAG! + call :debug_msg LONG_FLAG: !argdefs[%argdefn%].LONG_FLAG! + + :: Increment argument + set /A argdefn+=1 + + exit /b 0 + + +:: find_arg +:find_arg + setlocal + call :debug_msg starting function: find_arg "%~1" "%~2" + + set type= + if /I "%~1" == "short" set type=SHORT + if /I "%~1" == "long" set type=LONG + if not defined type ( + endlocal + set ret= + exit /b 1 + ) + + call :debug_msg find_arg type=%type% + set /A range_end = %argdefn% - 1 + for /L %%i in (0, 1, %range_end%) do ( + if "!argdefs[%%i].%type%_FLAG!" == "%~2" ( + set idx=%%i + goto :find_arg_cont + ) + ) + + echo Error in find_arg: Failed to find arg "%~2" + + endlocal + set ret= + exit /b 1 + + :find_arg_cont + call :debug_msg find_arg: found at %idx% + endlocal & ( + set ret=%idx% + ) + exit /b 0 + + +:: set_arg [] +:set_arg + call :debug_msg starting function: set_arg "%~1" "%~2" + + if "%~1" == "" ( + echo Error in set_arg: no index provided + exit /b 1 + ) + + setlocal + if /I "!argdefs[%~1].TYPE!" == "bool" ( + call :debug_msg set_arg: setting bool type to ON + set val=ON + ) else ( + set val=%~2 + set quote_char=" + if "!val:~0,1!" == "!quote_char!" ( + if "!val:~-1,1!" == "!quote_char!" ( + set val=%val:~1,-1% + ) + ) + call :debug_msg set_arg: setting string type to %~2 + ) + set var_name=!argdefs[%~1].VARIABLE_NAME! + + endlocal & ( + :: Set variable in parent scope + set %var_name%=%val% + :: Add variable to finalize command + set "finalize_cmd=%finalize_cmd% & set "%var_name%=%val%"" + ) + + exit /b 0 + + +:: get_arg_type +:get_arg_type + call :debug_msg starting function get_arg_type "%~1" + setlocal + set type=!argdefs[%~1].TYPE! + endlocal & set ret=%type% + exit /b 0 From aee958ec56efa19e1acae8e2b36220015ef4aac4 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 8 Oct 2025 10:22:42 -0400 Subject: [PATCH 02/23] Improve script layout - Use if statements instead of goto statements - Move pack deps to after build deps to allow chaining the commands - Pass paths to cmake instead of using mkdir/cd --- build_release_vs2022.bat | 59 +++++++++++++++------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index d8ed5efefc..b681bf1569 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -127,17 +127,6 @@ call :add_arg build_debuginfo bool e debuginfo :handle_args_loop_end -@REM Pack deps -if "%pack_deps%"=="ON" ( - 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!_vs2022.zip - - %WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs2022.zip OrcaSlicer_dep - exit /b 0 -) - if "%build_debug%"=="ON" ( set build_type=Debug set build_dir=build-dbg @@ -152,40 +141,36 @@ if "%build_debug%"=="ON" ( ) echo build type set to %build_type% -setlocal DISABLEDELAYEDEXPANSION -cd deps -mkdir %build_dir% -cd %build_dir% -set DEPS=%CD%/OrcaSlicer_dep set "SIG_FLAG=" if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%" -if "%build_slicer%"=="ON" ( - GOTO :slicer +set DEPS=%WP%\deps\%build_dir%\OrcaSlicer_dep +if "%build_deps%" == "ON" ( + echo building deps... + + cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% + cmake --build deps/%build_dir% --config %build_type% --target deps -- -m ) -echo "building deps.." -echo on -cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake --build . --config %build_type% --target deps -- -m -@echo off +@REM Pack deps +if "%pack_deps%" == "ON" ( + 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!_vs2022.zip -if "%build_deps%"=="ON" exit /b 0 + %WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs2022.zip OrcaSlicer_dep + endlocal +) -:slicer -echo "building Orca Slicer..." -cd %WP% -mkdir %build_dir% -cd %build_dir% +if "%build_slicer%" == "ON" ( + echo building Orca Slicer... -echo on -cmake .. -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" -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% + cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" + cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m + call scripts/run_gettext.bat + cmake --build %build_dir% --target install --config %build_type% +) :: End of script exit /b 0 From b6568bfbd93b01612efc06119ec4c1887c0fabc0 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 8 Oct 2025 10:25:58 -0400 Subject: [PATCH 03/23] Exit script upon failed cmake command --- build_release_vs2022.bat | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index b681bf1569..97c2ad9d36 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -149,7 +149,10 @@ if "%build_deps%" == "ON" ( echo building deps... cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% + %error_check% + cmake --build deps/%build_dir% --config %build_type% --target deps -- -m + %error_check% ) @REM Pack deps @@ -160,6 +163,7 @@ if "%pack_deps%" == "ON" ( echo packing deps: OrcaSlicer_dep_win64_!build_date!_vs2022.zip %WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs2022.zip OrcaSlicer_dep + %error_check% endlocal ) @@ -167,9 +171,15 @@ if "%build_slicer%" == "ON" ( echo building Orca Slicer... cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" + %error_check% + cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m + %error_check% + call scripts/run_gettext.bat + cmake --build %build_dir% --target install --config %build_type% + %error_check% ) :: End of script From 93076e766ec4a4474ad7e96732a8be558d60c6d9 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Thu, 9 Oct 2025 10:54:54 -0400 Subject: [PATCH 04/23] Add print_and_run --- build_release_vs2022.bat | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 97c2ad9d36..0e853da913 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -22,6 +22,7 @@ call :add_arg build_deps bool d deps call :add_arg build_slicer bool s slicer call :add_arg build_debug bool b debug call :add_arg build_debuginfo bool e debuginfo +call :add_arg dry_run bool D dry-run :: handle arguments from input :handle_args_loop @@ -148,10 +149,10 @@ set DEPS=%WP%\deps\%build_dir%\OrcaSlicer_dep if "%build_deps%" == "ON" ( echo building deps... - cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% + call :print_and_run cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% %error_check% - cmake --build deps/%build_dir% --config %build_type% --target deps -- -m + call :print_and_run cmake --build deps/%build_dir% --config %build_type% --target deps -- -m %error_check% ) @@ -162,7 +163,7 @@ if "%pack_deps%" == "ON" ( 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!_vs2022.zip - %WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs2022.zip OrcaSlicer_dep + call :print_and_run %WP%/tools/7z.exe a OrcaSlicer_dep_win64_!build_date!_vs2022.zip OrcaSlicer_dep %error_check% endlocal ) @@ -170,15 +171,15 @@ if "%pack_deps%" == "ON" ( if "%build_slicer%" == "ON" ( echo building Orca Slicer... - cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" + call :print_and_run cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" %error_check% - cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m + call :print_and_run cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m %error_check% - call scripts/run_gettext.bat + call :print_and_run call scripts/run_gettext.bat - cmake --build %build_dir% --target install --config %build_type% + call :print_and_run cmake --build %build_dir% --target install --config %build_type% %error_check% ) @@ -297,3 +298,13 @@ exit /b 0 set type=!argdefs[%~1].TYPE! endlocal & set ret=%type% exit /b 0 + + +:: print_and_run +:print_and_run + echo + %* + if not "%dry_run%" == "ON" ( + %* + exit /b !errorlevel! + ) + exit /b 0 From 849d93d89cac218ea08d761417861048c0ff8801 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Thu, 9 Oct 2025 10:55:29 -0400 Subject: [PATCH 05/23] Echo all variables in script debug mode --- build_release_vs2022.bat | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 0e853da913..ba73cac123 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -127,6 +127,13 @@ call :add_arg dry_run bool D dry-run :handle_args_loop_end +if "%debugscript%" == "ON" ( + set /A range_end = %argdefn% - 1 + for /L %%i in (0, 1, !range_end!) do ( + call :echo_var !argdefs[%%i].VARIABLE_NAME! + ) +) + if "%build_debug%"=="ON" ( set build_type=Debug @@ -300,6 +307,12 @@ exit /b 0 exit /b 0 +:: echo_var +:echo_var + echo %~1=!%~1! + exit /b 0 + + :: print_and_run :print_and_run echo + %* From de0c7e0b7c23934944bb3c99731e25462295b5f3 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Tue, 14 Oct 2025 07:14:45 -0400 Subject: [PATCH 06/23] Move handle_args to a function --- build_release_vs2022.bat | 206 ++++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 101 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index ba73cac123..68cbedcc66 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -14,6 +14,7 @@ set WP=%CD% set argdefn=0 :: Error check macro +set "repeat_error=if not ^!errorlevel^! == 0 exit /b ^!errorlevel^!" set "error_check=if not ^!errorlevel^! == 0 echo Exiting script with code ^!errorlevel^! & exit /b ^!errorlevel^!" :: Define arguments @@ -25,107 +26,8 @@ call :add_arg build_debuginfo bool e debuginfo call :add_arg dry_run bool D dry-run :: handle arguments from input -:handle_args_loop - if "%1" == "" goto :handle_args_loop_end - - setlocal - set arg=%1 - set finalize_cmd= - - call :debug_msg Begin handling arg "%arg%" - - if not "%arg:~0,2%" == "--" goto :HAL_check_short - - ::IF long arg - call :debug_msg Processing long arg - - call :find_arg long %arg:~2% - %error_check% - set idx=%ret% - - call :get_arg_type %idx% - %error_check% - set type=%ret% - - if /I "%type%" == "string" ( - set string_val=%2 - :: Ensure there is a string value - if "!string_val!" == "" ( - echo Error in handle_args_loop: The option "%arg:~2%" requires a value - exit /b 1 - ) - :: Ensure the string value isn't another argument - if "!string_val:~0,1!" == "-" ( - echo Error in handle_args_loop: The option "%arg:~2%" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. - exit /b 1 - ) - shift - ) - - call :set_arg %idx% %string_val% - %error_check% - goto :handle_args_loop_reset - - :HAL_check_short - if not "%arg:~0,1%" == "-" ( - :: IF invalid arg - echo Unknown argument: %arg% - exit /b 1 - ) - - :: IF short arg - call :debug_msg processing short args - set /A charidx=1 - :short_arg_loop - if "!arg:~%charidx%,1!" == "" goto :handle_args_loop_reset - - call :find_arg short !arg:~%charidx%,1! - %error_check% - set idx=%ret% - - call :get_arg_type %idx% - %error_check% - set type=%ret% - - set /A start_idx = %charidx% + 1 - if /I "%type%" == "string" ( - :: Check if there are additional characters after the found string argument - set remaining=!arg:~%start_idx%! - if defined remaining ( - :: If there are remaining characters, use them as the string value - set string_val=!remaining! - ) else ( - :: Otherwise, use the next argument - set string_val=%2 - shift - ) - :: Ensure there is a string value - if "!string_val!" == "" ( - echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value - exit /b 1 - ) - :: Ensure the string value isn't another argument - if "!string_val:~1!" == "-" ( - echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. - exit /b 1 - ) - call :set_arg !idx! !string_val! - %error_check% - goto :handle_args_loop_reset - ) - - call :set_arg %idx% - %error_check% - set /A charidx+=1 - goto :short_arg_loop - - :handle_args_loop_reset - :: End local scope for this loop and use finalize_cmd to set global variables from the set_arg function - endlocal %finalize_cmd% - shift - goto :handle_args_loop - -:handle_args_loop_end +call :handle_args %* +%error_check% if "%debugscript%" == "ON" ( set /A range_end = %argdefn% - 1 @@ -321,3 +223,105 @@ exit /b 0 exit /b !errorlevel! ) exit /b 0 + +::handle_args +:handle_args + call :debug_msg starting function handle_args "%*" + if "%~1" == "" exit /b 0 + + setlocal + set arg=%~1 + set finalize_cmd= + + call :debug_msg Begin handling arg "%arg%" + + if not "%arg:~0,2%" == "--" goto :HAL_check_short + + ::IF long arg + call :debug_msg Processing long arg + + call :find_arg long %arg:~2% + %repeat_error% + set idx=%ret% + + call :get_arg_type %idx% + %repeat_error% + set type=%ret% + + if /I "%type%" == "string" ( + set string_val=%2 + :: Ensure there is a string value + if "!string_val!" == "" ( + echo Error in handle_args_loop: The option "%arg:~2%" requires a value + exit /b 1 + ) + :: Ensure the string value isn't another argument + if "!string_val:~0,1!" == "-" ( + echo Error in handle_args_loop: The option "%arg:~2%" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. + exit /b 1 + ) + shift + ) + + call :set_arg %idx% %string_val% + %repeat_error% + goto :handle_args_loop_reset + + :HAL_check_short + if not "%arg:~0,1%" == "-" ( + :: IF invalid arg + echo Unknown argument: %arg% + exit /b 1 + ) + + :: IF short arg + call :debug_msg processing short args + set /A charidx=1 + :short_arg_loop + if "!arg:~%charidx%,1!" == "" goto :handle_args_loop_reset + + call :find_arg short !arg:~%charidx%,1! + %repeat_error% + set idx=%ret% + + call :get_arg_type %idx% + %repeat_error% + set type=%ret% + + set /A start_idx = %charidx% + 1 + if /I "%type%" == "string" ( + :: Check if there are additional characters after the found string argument + set remaining=!arg:~%start_idx%! + if defined remaining ( + :: If there are remaining characters, use them as the string value + set string_val=!remaining! + ) else ( + :: Otherwise, use the next argument + set string_val=%2 + shift + ) + :: Ensure there is a string value + if "!string_val!" == "" ( + echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value + exit /b 1 + ) + :: Ensure the string value isn't another argument + if "!string_val:~1!" == "-" ( + echo Error in handle_args_loop: The option "!arg:~%charidx%,1!" requires a value. "!string_val!" is invalid as it may be another argument. Enclose the value with double quotes to override this. + exit /b 1 + ) + call :set_arg !idx! !string_val! + %repeat_error% + goto :handle_args_loop_reset + ) + + call :set_arg %idx% + %repeat_error% + set /A charidx+=1 + goto :short_arg_loop + + :handle_args_loop_reset + :: End local scope for this loop and use finalize_cmd to set global variables from the set_arg function + endlocal %finalize_cmd% + shift + goto :handle_args From fd436285752d19b65bfb8a7289b47fef42408eb5 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Tue, 14 Oct 2025 08:51:49 -0400 Subject: [PATCH 07/23] Add clean arg --- build_release_vs2022.bat | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 68cbedcc66..0606fceb64 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -24,6 +24,7 @@ call :add_arg build_slicer bool s slicer call :add_arg build_debug bool b debug call :add_arg build_debuginfo bool e debuginfo call :add_arg dry_run bool D dry-run +call :add_arg clean bool c clean :: handle arguments from input call :handle_args %* @@ -58,6 +59,11 @@ set DEPS=%WP%\deps\%build_dir%\OrcaSlicer_dep if "%build_deps%" == "ON" ( echo building deps... + if "%clean%" == "ON" ( + call :print_and_run rmdir /S /Q deps\%build_dir% + %error_check% + ) + call :print_and_run cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% %error_check% @@ -80,6 +86,11 @@ if "%pack_deps%" == "ON" ( if "%build_slicer%" == "ON" ( echo building Orca Slicer... + if "%clean%" == "ON" ( + call :print_and_run rmdir /S /Q %build_dir% + %error_check% + ) + call :print_and_run cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" %error_check% From e618682a3c32f770b67362afb56e93592ab6a297 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 15 Oct 2025 20:21:32 -0400 Subject: [PATCH 08/23] Add install deps via winget --- build_release_vs2022.bat | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 0606fceb64..66132b3b05 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -25,6 +25,7 @@ call :add_arg build_debug bool b debug call :add_arg build_debuginfo bool e debuginfo call :add_arg dry_run bool D dry-run call :add_arg clean bool c clean +call :add_arg install_deps bool u install-deps :: handle arguments from input call :handle_args %* @@ -37,6 +38,20 @@ if "%debugscript%" == "ON" ( ) ) +if "%install_deps%" == "ON" ( + where winget >nul 2>nul + if not !errorlevel! == 0 ( + echo WinGet was not found + exit /b 1 + ) + set "winget_args=-e --source=winget" + call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.2022.BuildTools --custom "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.26100" + call :print_and_run winget install !winget_args! --id=Kitware.CMake -v "3.31.8" + call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl + call :print_and_run winget install !winget_args! --id=Git.Git + echo System dependencies have been installed. Restart the shell to reload the environment. + exit /b 0 +) if "%build_debug%"=="ON" ( set build_type=Debug From c05ad09f77d52a2c1f0e683e36c685888787ff92 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 15 Oct 2025 20:51:27 -0400 Subject: [PATCH 09/23] Add help message --- build_release_vs2022.bat | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 66132b3b05..d503951f52 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -9,6 +9,7 @@ set errorlevel= setlocal enableDelayedExpansion set WP=%CD% +set script_name=%~nx0 :: Arg definition count set argdefn=0 @@ -18,14 +19,15 @@ set "repeat_error=if not ^!errorlevel^! == 0 exit /b ^!errorlevel^!" set "error_check=if not ^!errorlevel^! == 0 echo Exiting script with code ^!errorlevel^! & exit /b ^!errorlevel^!" :: Define arguments -call :add_arg pack_deps bool p pack -call :add_arg build_deps bool d deps -call :add_arg build_slicer bool s slicer -call :add_arg build_debug bool b debug -call :add_arg build_debuginfo bool e debuginfo -call :add_arg dry_run bool D dry-run -call :add_arg clean bool c clean -call :add_arg install_deps bool u install-deps +call :add_arg pack_deps bool p pack "bundle build deps into a zip file" +call :add_arg build_deps bool d deps "download and build dependencies in ./deps/ (build prerequisite)" +call :add_arg build_slicer bool s slicer "build OrcaSlicer" +call :add_arg build_debug bool b debug "build in Debug mode" +call :add_arg build_debuginfo bool e debuginfo "build in RelWithDebInfo mode" +call :add_arg dry_run bool D dry-run "perform a dry run of the script" +call :add_arg clean bool c clean "force a clean build" +call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" +call :add_arg print_help bool h help "print this help message" :: handle arguments from input call :handle_args %* @@ -38,6 +40,12 @@ if "%debugscript%" == "ON" ( ) ) +if "%print_help%" == "ON" ( + call :print_help_msg + exit /b 0 +) + + if "%install_deps%" == "ON" ( where winget >nul 2>nul if not !errorlevel! == 0 ( @@ -131,14 +139,41 @@ exit /b 0 if "%debugscript%" == "ON" echo %* exit /b 0 -:: add_arg [] +:: print_help_msg +:print_help_msg + echo OrcaSlicer build script for Windows + set /A range_end = %argdefn% - 1 + for /L %%i in (0, 1, !range_end!) do ( + set str_placeholder= + if "!argdefs[%%i].TYPE!" == "string" ( + set "str_placeholder= " + ) + set "line=" + if not "!argdefs[%%i].SHORT_FLAG!" == "" ( + set "line=-!argdefs[%%i].SHORT_FLAG!!str_placeholder!" + ) + + if not "!argdefs[%%i].LONG_FLAG!" == "" ( + if not "!line!" == "" ( + set "line=!line!, " + ) + set "line=!line!--!argdefs[%%i].LONG_FLAG!!str_placeholder!" + ) + echo !line!: !argdefs[%%i].HELP_TEXT! + ) + echo For a first use, use './%script_name% -u' + echo and then './%script_name% -ds' + exit /b 0 + +:: add_arg :add_arg - call :debug_msg starting function: add_arg "%~1" "%~2" "%~3" "%~4" + call :debug_msg starting function: add_arg "%~1" "%~2" "%~3" "%~4" "%~5" set argdefs[%argdefn%].VARIABLE_NAME=%~1 set argdefs[%argdefn%].TYPE=%~2 set argdefs[%argdefn%].SHORT_FLAG=%~3 set argdefs[%argdefn%].LONG_FLAG=%~4 + set argdefs[%argdefn%].HELP_TEXT=%~5 :: ensure variable is not set set %~1= @@ -147,6 +182,7 @@ exit /b 0 call :debug_msg TYPE: !argdefs[%argdefn%].TYPE! call :debug_msg SHORT_FLAG: !argdefs[%argdefn%].SHORT_FLAG! call :debug_msg LONG_FLAG: !argdefs[%argdefn%].LONG_FLAG! + call :debug_msg HELP_TEXT: !argdefs[%argdefn%].HELP_TEXT! :: Increment argument set /A argdefn+=1 From c2ece76340ca9c391799f9b73d8a76eafc66e2f8 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 15 Oct 2025 20:52:29 -0400 Subject: [PATCH 10/23] Organize argument definitions --- build_release_vs2022.bat | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index d503951f52..f0752b6118 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -19,15 +19,15 @@ set "repeat_error=if not ^!errorlevel^! == 0 exit /b ^!errorlevel^!" set "error_check=if not ^!errorlevel^! == 0 echo Exiting script with code ^!errorlevel^! & exit /b ^!errorlevel^!" :: Define arguments -call :add_arg pack_deps bool p pack "bundle build deps into a zip file" -call :add_arg build_deps bool d deps "download and build dependencies in ./deps/ (build prerequisite)" -call :add_arg build_slicer bool s slicer "build OrcaSlicer" call :add_arg build_debug bool b debug "build in Debug mode" -call :add_arg build_debuginfo bool e debuginfo "build in RelWithDebInfo mode" -call :add_arg dry_run bool D dry-run "perform a dry run of the script" call :add_arg clean bool c clean "force a clean build" -call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" +call :add_arg build_deps bool d deps "download and build dependencies in ./deps/ (build prerequisite)" +call :add_arg dry_run bool D dry-run "perform a dry run of the script" +call :add_arg build_debuginfo bool e debuginfo "build in RelWithDebInfo mode" call :add_arg print_help bool h help "print this help message" +call :add_arg pack_deps bool p pack "bundle build deps into a zip file" +call :add_arg build_slicer bool s slicer "build OrcaSlicer" +call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" :: handle arguments from input call :handle_args %* From c9eef438d14ef24e79d91a74e99c34da5ec61303 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 15 Oct 2025 20:54:46 -0400 Subject: [PATCH 11/23] Print help if args are empty --- build_release_vs2022.bat | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index f0752b6118..f3793830e1 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -40,6 +40,10 @@ if "%debugscript%" == "ON" ( ) ) +if "%*" == "" ( + set print_help=ON +) + if "%print_help%" == "ON" ( call :print_help_msg exit /b 0 From 4244fc12be2e4ae6fa441d9b891d32fedc7c8b5f Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Thu, 16 Oct 2025 11:41:56 -0400 Subject: [PATCH 12/23] Print help on unknown argument --- build_release_vs2022.bat | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index f3793830e1..c7f950de76 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -218,6 +218,7 @@ exit /b 0 ) echo Error in find_arg: Failed to find arg "%~2" + call :print_help_msg endlocal set ret= @@ -337,6 +338,7 @@ exit /b 0 if not "%arg:~0,1%" == "-" ( :: IF invalid arg echo Unknown argument: %arg% + call :print_help_msg exit /b 1 ) From 707947a04107de281efd1b6e44d15b6b22ec5b07 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Thu, 16 Oct 2025 18:19:47 -0400 Subject: [PATCH 13/23] Add padding between flags and help description --- build_release_vs2022.bat | 60 ++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index c7f950de76..ec97ed0fc3 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -143,30 +143,74 @@ exit /b 0 if "%debugscript%" == "ON" echo %* exit /b 0 +::get_str_len +:get_str_len + setlocal + set in=%~1 + for /L %%i in (0, 1, 100) do ( + if "!in:~%%i,1!" == "" ( + set out=%%i + goto :break_str_len + ) + ) + + echo error in get_str_len: string is too long + endlocal + exit /b 1 + + :break_str_len + endlocal & set ret=%out% + exit /b 0 + :: print_help_msg :print_help_msg - echo OrcaSlicer build script for Windows + setlocal + ::get longest string length + set flags= + set max_len=0 set /A range_end = %argdefn% - 1 - for /L %%i in (0, 1, !range_end!) do ( + for /L %%i in (0, 1, %range_end%) do ( set str_placeholder= if "!argdefs[%%i].TYPE!" == "string" ( set "str_placeholder= " ) - set "line=" + + set "flag_str=" if not "!argdefs[%%i].SHORT_FLAG!" == "" ( - set "line=-!argdefs[%%i].SHORT_FLAG!!str_placeholder!" + set "flag_str=-!argdefs[%%i].SHORT_FLAG!!str_placeholder!" ) if not "!argdefs[%%i].LONG_FLAG!" == "" ( - if not "!line!" == "" ( - set "line=!line!, " + if "!flag_str!" == "" ( + :: add 4 spaces of padding so long flags are always aligned + set "flag_str= " + ) else ( + set "flag_str=!flag_str!, " ) - set "line=!line!--!argdefs[%%i].LONG_FLAG!!str_placeholder!" + set "flag_str=!flag_str!--!argdefs[%%i].LONG_FLAG!!str_placeholder!" ) - echo !line!: !argdefs[%%i].HELP_TEXT! + set "flag_str=!flag_str! " + set "flags[%%i]=!flag_str!" + call :get_str_len "!flag_str!" + if !ret! GTR !max_len! ( + set max_len=!ret! + ) + ) + + :: create a padding string + set padding= + for /L %%i in (0, 1, %max_len%) do set "padding=!padding! " + + :: begin printing help message + echo OrcaSlicer build script for Windows + set /A range_end = %argdefn% - 1 + for /L %%i in (0, 1, !range_end!) do ( + set "flag=!flags[%%i]!%padding%" + echo !flag:~0,%max_len%!!argdefs[%%i].HELP_TEXT! ) echo For a first use, use './%script_name% -u' echo and then './%script_name% -ds' + endlocal exit /b 0 :: add_arg From de8642e30a81efd44cb052a2833d32ba83e773dc Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Fri, 17 Oct 2025 11:35:58 -0400 Subject: [PATCH 14/23] Merge vs2019 and vs2022 build scripts --- build_release.bat | 52 ----------------------- build_release_vs2022.bat => build_win.bat | 8 +++- 2 files changed, 6 insertions(+), 54 deletions(-) delete mode 100644 build_release.bat rename build_release_vs2022.bat => build_win.bat (94%) diff --git a/build_release.bat b/build_release.bat deleted file mode 100644 index 6317e277c9..0000000000 --- a/build_release.bat +++ /dev/null @@ -1,52 +0,0 @@ -set WP=%CD% - -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% - -cd deps -mkdir %build_dir% -cd %build_dir% -set DEPS=%CD%/OrcaSlicer_dep -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 cmake ../ -G "Visual Studio 16 2019" -A x64 -DDESTDIR="%CD%/OrcaSlicer_dep" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake ../ -G "Visual Studio 16 2019" -A x64 -DDESTDIR="%CD%/OrcaSlicer_dep" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake --build . --config %build_type% --target deps -- -m - -if "%1"=="deps" exit /b 0 - -:slicer -echo "building Orca Slicer..." -cd %WP% -mkdir %build_dir% -cd %build_dir% - -echo cmake .. -G "Visual Studio 16 2019" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -cmake .. -G "Visual Studio 16 2019" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0" -cmake --build . --config %build_type% --target ALL_BUILD -- -m -cd .. -call scripts/run_gettext.bat -cd %build_dir% -cmake --build . --target install --config %build_type% diff --git a/build_release_vs2022.bat b/build_win.bat similarity index 94% rename from build_release_vs2022.bat rename to build_win.bat index ec97ed0fc3..43fdea4beb 100644 --- a/build_release_vs2022.bat +++ b/build_win.bat @@ -28,6 +28,7 @@ call :add_arg print_help bool h help "print this help message" call :add_arg pack_deps bool p pack "bundle build deps into a zip file" call :add_arg build_slicer bool s slicer "build OrcaSlicer" call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" +call :add_arg use_vs2019 bool "" vs2019 "Use Visual Studio 16 2019 as the generator. Can be used with '-u'. (Default: Visual Studio 17 2022)" :: handle arguments from input call :handle_args %* @@ -79,6 +80,9 @@ if "%build_debug%"=="ON" ( ) echo build type set to %build_type% +set "generator=Visual Studio 17 2022" +if "%use_vs2019%" == "ON" set "generator=Visual Studio 16 2019" + set "SIG_FLAG=" if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%" @@ -91,7 +95,7 @@ if "%build_deps%" == "ON" ( %error_check% ) - call :print_and_run cmake -S deps -B deps/%build_dir% -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% + call :print_and_run cmake -S deps -B deps/%build_dir% -G "%generator%" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% %error_check% call :print_and_run cmake --build deps/%build_dir% --config %build_type% --target deps -- -m @@ -118,7 +122,7 @@ if "%build_slicer%" == "ON" ( %error_check% ) - call :print_and_run cmake -B %build_dir% -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" + call :print_and_run cmake -B %build_dir% -G "%generator%" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" %error_check% call :print_and_run cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m From 784a55c481b34d7fc0fcaf5440503945df2a3dd3 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Fri, 17 Oct 2025 11:47:50 -0400 Subject: [PATCH 15/23] Handle installing vs2019 --- build_win.bat | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_win.bat b/build_win.bat index 43fdea4beb..13b69ad549 100644 --- a/build_win.bat +++ b/build_win.bat @@ -58,7 +58,14 @@ if "%install_deps%" == "ON" ( exit /b 1 ) set "winget_args=-e --source=winget" - call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.2022.BuildTools --custom "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.26100" + if not "%bypass_vs_install%" == "ON" ( + if "%use_vs2019%" == "ON" ( + set vs_year=2019 + ) else ( + set vs_year=2022 + ) + call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.BuildTools --custom "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" + ) call :print_and_run winget install !winget_args! --id=Kitware.CMake -v "3.31.8" call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl call :print_and_run winget install !winget_args! --id=Git.Git From ad736618ec9c6dd4db277c7b8ef5c7617345c891 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Fri, 17 Oct 2025 11:53:15 -0400 Subject: [PATCH 16/23] Add the option to install the full Visual Studio IDE --- build_win.bat | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/build_win.bat b/build_win.bat index 13b69ad549..471e621aa4 100644 --- a/build_win.bat +++ b/build_win.bat @@ -29,6 +29,8 @@ call :add_arg pack_deps bool p pack "bundle build deps into a zip file" call :add_arg build_slicer bool s slicer "build OrcaSlicer" call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" call :add_arg use_vs2019 bool "" vs2019 "Use Visual Studio 16 2019 as the generator. Can be used with '-u'. (Default: Visual Studio 17 2022)" +call :add_arg install_ide bool "" install-ide "Install the full Visual Studio IDE instead of only the build tools. Use with '-u'" +call :add_arg bypass_vs_install bool "" no-vs "Skip installing Visual Studio. Select this option if you are providing your own installation. Use with '-u'" :: handle arguments from input call :handle_args %* @@ -59,12 +61,26 @@ if "%install_deps%" == "ON" ( ) set "winget_args=-e --source=winget" if not "%bypass_vs_install%" == "ON" ( + set ide_component_flag= + set vs_edition=BuildTools if "%use_vs2019%" == "ON" ( + if "%install_ide%" == "ON" ( + echo The community edition of Visual Studio 16 2019 is no longer available. + echo Resolve this issue by doing one of the following: + echo 1^) Manually install your own copy of Visual Studio 16 2019 Professional/Enterprise ^(run '%script_name% -u --no-vs' to install the remaining dependencies^) + echo 2^) Install Visual Studio 16 2019 Build Tools ^(no '--install-ide'^) + echo 3^) Install Visual Studio 17 2022 Community edition ^(no '--vs2019'^) + exit /b 1 + ) set vs_year=2019 ) else ( + if "%install_ide%" == "ON" ( + set vs_edition=Community + set ide_component_flag=Microsoft.VisualStudio.Component.VC.CoreIde + ) set vs_year=2022 ) - call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.BuildTools --custom "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" + call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.!vs_edition! --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" ) call :print_and_run winget install !winget_args! --id=Kitware.CMake -v "3.31.8" call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl From b13bd9a7ec4147f7332dc4ae866e97e2782fa0ab Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Fri, 17 Oct 2025 20:16:05 -0400 Subject: [PATCH 17/23] Add --force to Visual Studio install Always run the VS installer to ensure all components are installed and up to date --- build_win.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_win.bat b/build_win.bat index 471e621aa4..185b163924 100644 --- a/build_win.bat +++ b/build_win.bat @@ -80,7 +80,7 @@ if "%install_deps%" == "ON" ( ) set vs_year=2022 ) - call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.!vs_edition! --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" + call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.!vs_edition! --force --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" ) call :print_and_run winget install !winget_args! --id=Kitware.CMake -v "3.31.8" call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl From 296303d166dad7c2c1d917fce6391c46204933e9 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Fri, 17 Oct 2025 20:20:24 -0400 Subject: [PATCH 18/23] Add check for cmake --- build_win.bat | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build_win.bat b/build_win.bat index 185b163924..47c7481802 100644 --- a/build_win.bat +++ b/build_win.bat @@ -89,6 +89,12 @@ if "%install_deps%" == "ON" ( exit /b 0 ) +where cmake >nul 2>nul +if not !errorlevel! == 0 ( + echo CMake was not found. Have you installed the system dependencies? + exit /b 1 +) + if "%build_debug%"=="ON" ( set build_type=Debug set build_dir=build-dbg From 007e1ca8885c6afaffe9a9f4b520345cd43f2dc4 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Sat, 18 Oct 2025 20:56:41 -0400 Subject: [PATCH 19/23] Update workflows --- .github/workflows/build_all.yml | 2 +- .github/workflows/build_deps.yml | 3 +-- .github/workflows/build_orca.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index db95d67040..1d5bec60ed 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -26,7 +26,7 @@ on: - 'version.inc' - ".github/workflows/build_*.yml" - 'build_linux.sh' - - 'build_release_vs2022.bat' + - 'build_win.bat' - 'build_release_macos.sh' - 'scripts/flatpak/**' diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index 629fdde2e7..4fdd332201 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -69,8 +69,7 @@ jobs: working-directory: ${{ github.workspace }} run: | choco install strawberryperl - .\build_release_vs2022.bat deps - .\build_release_vs2022.bat pack + .\build_win.bat -dp cd ${{ github.workspace }}/deps/build - name: Build on Mac ${{ inputs.arch }} diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 29984fab2e..18f55f9742 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -233,7 +233,7 @@ jobs: env: WindowsSdkDir: 'C:\Program Files (x86)\Windows Kits\10\' WindowsSDKVersion: '10.0.26100.0\' - run: .\build_release_vs2022.bat slicer + run: .\build_win.bat -s - name: Create installer Win if: inputs.os == 'windows-latest' From c67582f30bac5c6e9caa336b03ab9eae36c6a4c5 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Mon, 20 Oct 2025 22:11:58 -0400 Subject: [PATCH 20/23] Fix install prefix --- build_win.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_win.bat b/build_win.bat index 47c7481802..f963392891 100644 --- a/build_win.bat +++ b/build_win.bat @@ -151,7 +151,7 @@ if "%build_slicer%" == "ON" ( %error_check% ) - call :print_and_run cmake -B %build_dir% -G "%generator%" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" + call :print_and_run cmake -B %build_dir% -G "%generator%" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="%build_dir%/OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" %error_check% call :print_and_run cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m From a5e261a9fe717eb0a85053e663db634f58739ca8 Mon Sep 17 00:00:00 2001 From: Rodrigo <162915171+rf47@users.noreply.github.com> Date: Tue, 21 Oct 2025 13:06:35 -0400 Subject: [PATCH 21/23] CMake 4.x. windows (#10820) --- CMakeLists.txt | 6 +++--- build_win.bat | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd575188d..847549d101 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.13) -# Verify that your CMake version is exactly 3.31.x series or lower on windows -if ( ((MSVC) OR (WIN32)) AND (${CMAKE_VERSION} VERSION_GREATER_EQUAL "4.0") ) - message(FATAL_ERROR "Only cmake versions between 3.13.x and 3.31.x is supported on windows. Detected version: ${CMAKE_VERSION}") +# Verify that your CMake version is exactly 3.5 series or higher on windows +if ( (MSVC OR WIN32) AND (${CMAKE_VERSION} VERSION_LESS "3.5") ) + message(FATAL_ERROR "CMake current version ${CMAKE_VERSION} is too old. Minimum required is 3.5.") endif() if (WIN32) diff --git a/build_win.bat b/build_win.bat index f963392891..7f146f0a50 100644 --- a/build_win.bat +++ b/build_win.bat @@ -115,6 +115,9 @@ if "%use_vs2019%" == "ON" set "generator=Visual Studio 16 2019" set "SIG_FLAG=" if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%" +REM Set minimum CMake policy to avoid <3.5 errors +set CMAKE_POLICY_VERSION_MINIMUM=3.5 + set DEPS=%WP%\deps\%build_dir%\OrcaSlicer_dep if "%build_deps%" == "ON" ( echo building deps... From 87f7f8c09b98accf583de881d18a01983dea0007 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Tue, 21 Oct 2025 13:13:34 -0400 Subject: [PATCH 22/23] Install the latest CMake version --- build_win.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_win.bat b/build_win.bat index 7f146f0a50..233e02a50d 100644 --- a/build_win.bat +++ b/build_win.bat @@ -82,7 +82,7 @@ if "%install_deps%" == "ON" ( ) call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.!vs_edition! --force --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" ) - call :print_and_run winget install !winget_args! --id=Kitware.CMake -v "3.31.8" + call :print_and_run winget install !winget_args! --id=Kitware.CMake call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl call :print_and_run winget install !winget_args! --id=Git.Git echo System dependencies have been installed. Restart the shell to reload the environment. From 47449a099e3c356a0d1c7697df1608bd153cbd5d Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Mon, 22 Dec 2025 12:00:27 -0500 Subject: [PATCH 23/23] Merge VS auto detection and VS 2026 support --- build_release_vs.bat | 119 ------------------------------------------- build_win.bat | 76 ++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 125 deletions(-) delete mode 100644 build_release_vs.bat diff --git a/build_release_vs.bat b/build_release_vs.bat deleted file mode 100644 index d2832450b3..0000000000 --- a/build_release_vs.bat +++ /dev/null @@ -1,119 +0,0 @@ -@REM OrcaSlicer build script for Windows with VS auto-detect -@echo off -set WP=%CD% - -@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% - -@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 - exit /b 0 -) - -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 -cmake ../ -G %CMAKE_GENERATOR% -A x64 -DCMAKE_BUILD_TYPE=%build_type% -cmake --build . --config %build_type% --target deps -- -m -@echo off - -if "%1"=="deps" exit /b 0 - -:slicer -echo "building Orca Slicer..." -cd %WP% -mkdir %build_dir% -cd %build_dir% - -echo on -set CMAKE_POLICY_VERSION_MINIMUM=3.5 -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% diff --git a/build_win.bat b/build_win.bat index 8a2f9b56f2..a2246a1dcf 100644 --- a/build_win.bat +++ b/build_win.bat @@ -28,7 +28,8 @@ call :add_arg print_help bool h help "print this help message" call :add_arg pack_deps bool p pack "bundle build deps into a zip file" call :add_arg build_slicer bool s slicer "build OrcaSlicer" call :add_arg install_deps bool u install-deps "download and install system dependencies using WinGet (build prerequisite)" -call :add_arg use_vs2019 bool "" vs2019 "Use Visual Studio 16 2019 as the generator. Can be used with '-u'. (Default: Visual Studio 17 2022)" +call :add_arg use_vs2019 bool "" vs2019 "Use Visual Studio 16 2019 as the generator. Can be used with '-u'. (Default: Autodetect or Visual Studio 18 2026)" +call :add_arg use_vs2022 bool "" vs2022 "Use Visual Studio 17 2022 as the generator. Can be used with '-u'. (Default: Autodetect or Visual Studio 18 2026)" call :add_arg install_ide bool "" install-ide "Install the full Visual Studio IDE instead of only the build tools. Use with '-u'" call :add_arg bypass_vs_install bool "" no-vs "Skip installing Visual Studio. Select this option if you are providing your own installation. Use with '-u'" @@ -52,6 +53,8 @@ if "%print_help%" == "ON" ( exit /b 0 ) +call :autodetect_vs +%error_check% if "%install_deps%" == "ON" ( where winget >nul 2>nul @@ -72,15 +75,17 @@ if "%install_deps%" == "ON" ( echo 3^) Install Visual Studio 17 2022 Community edition ^(no '--vs2019'^) exit /b 1 ) - set vs_year=2019 + set vs_year=.2019 ) else ( + if "%use_vs2022%" == "ON" ( + set vs_year=.2022 + ) if "%install_ide%" == "ON" ( set vs_edition=Community set ide_component_flag=Microsoft.VisualStudio.Component.VC.CoreIde ) - set vs_year=2022 ) - call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio.!vs_year!.!vs_edition! --force --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" + call :print_and_run winget install !winget_args! --id=Microsoft.VisualStudio!vs_year!.!vs_edition! --force --custom "--add !ide_component_flag! Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.Windows11SDK.22621" ) call :print_and_run winget install !winget_args! --id=Kitware.CMake call :print_and_run winget install !winget_args! --id=StrawberryPerl.StrawberryPerl @@ -109,8 +114,14 @@ if "%build_debug%"=="ON" ( ) echo build type set to %build_type% -set "generator=Visual Studio 17 2022" -if "%use_vs2019%" == "ON" set "generator=Visual Studio 16 2019" +set "generator=Visual Studio 18 2026" +if "%use_vs2019%" == "ON" ( + set "generator=Visual Studio 16 2019" +) else ( + if "%use_vs2022%" == "ON" ( + set "generator=Visual Studio 17 2022" + ) +) set "SIG_FLAG=" if defined ORCA_UPDATER_SIG_KEY set "SIG_FLAG=-DORCA_UPDATER_SIG_KEY=%ORCA_UPDATER_SIG_KEY%" @@ -361,6 +372,59 @@ exit /b 0 echo %~1=!%~1! exit /b 0 +:: autodetect_vs +:autodetect_vs + :: skip autodetect if manual selection + if "%use_vs2019%" == "ON" exit /b 0 + if "%use_vs2022%" == "ON" exit /b 0 + + where msbuild >nul 2>nul + if not !errorlevel! == 0 ( + :: msbuild could not be found, use default + exit /b 0 + ) + + setlocal + :: Detect Visual Studio version using msbuild + echo Detecting Visual Studio version using msbuild... + + :: 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 + ) + + :: 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 Detected Visual Studio %VS_VERSION% (version %VS_MAJOR%) + + if "%VS_MAJOR%"=="16" ( + endlocal + set use_vs2019=ON + ) else if "%VS_MAJOR%"=="17" ( + endlocal + set use_vs2022=ON + ) else if "%VS_MAJOR%"=="18" ( + :: VS 2026 is the default, do nothing + endlocal + ) else ( + echo Error: Unsupported Visual Studio version: %VS_MAJOR% + echo Supported versions: VS2019 (16.x^), VS2022 (17.x^), VS2026 (18.x^) + endlocal + exit /b 1 + ) + + exit /b 0 :: print_and_run :print_and_run