From 7f1aad8bc1009ce05383de03dbeb0623182c8cde Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 13 Nov 2025 23:11:56 +0800 Subject: [PATCH] Support Visual Studio 2026 (#11349) * Add script with VS version auto detection * Add msvc145 toolset support * Fix issue when build slicer only * Fix vs2026 OpenCV build * Set github action to use new build script * Get vs version from `msbuild --version` so it works for github action --- .github/workflows/build_deps.yml | 4 +- .github/workflows/build_orca.yml | 2 +- build_release_vs.bat | 119 ++++++++++++++++++ build_release_vs2022.bat | 1 + .../{0001-vs2022.patch => 0001-vs.patch} | 82 ++++++------ deps/OpenCV/OpenCV.cmake | 2 +- deps/deps-windows.cmake | 4 + 7 files changed, 170 insertions(+), 44 deletions(-) create mode 100644 build_release_vs.bat rename deps/OpenCV/{0001-vs2022.patch => 0001-vs.patch} (51%) diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index e4a985b77a..0267d22302 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -69,8 +69,8 @@ jobs: working-directory: ${{ github.workspace }} run: | choco install strawberryperl - .\build_release_vs2022.bat deps - .\build_release_vs2022.bat pack + .\build_release_vs.bat deps + .\build_release_vs.bat pack 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 9da7295565..2bb07ee2cf 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_release_vs.bat slicer - name: Create installer Win if: inputs.os == 'windows-latest' diff --git a/build_release_vs.bat b/build_release_vs.bat new file mode 100644 index 0000000000..d2832450b3 --- /dev/null +++ b/build_release_vs.bat @@ -0,0 +1,119 @@ +@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_release_vs2022.bat b/build_release_vs2022.bat index cde00008ff..4a5ae11277 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -61,6 +61,7 @@ mkdir %build_dir% cd %build_dir% echo on +set CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake .. -G "Visual Studio 17 2022" -A x64 -DORCA_TOOLS=ON %SIG_FLAG% -DCMAKE_BUILD_TYPE=%build_type% cmake --build . --config %build_type% --target ALL_BUILD -- -m @echo off diff --git a/deps/OpenCV/0001-vs2022.patch b/deps/OpenCV/0001-vs.patch similarity index 51% rename from deps/OpenCV/0001-vs2022.patch rename to deps/OpenCV/0001-vs.patch index 6e5aba84e8..5e6ac7785b 100644 --- a/deps/OpenCV/0001-vs2022.patch +++ b/deps/OpenCV/0001-vs.patch @@ -1,15 +1,21 @@ -From 6fb3f6333150a777e835fc7c48e49750591bf7fe Mon Sep 17 00:00:00 2001 -From: Benjamin Buch -Date: Thu, 23 May 2024 16:05:19 +0200 -Subject: [PATCH] Support VS 2022 17.1x.y - -With 17.10.0 the MSVC toolset was set to 19.40.x which breaks the compatibility test in the OpenCV's CMake Config files. ---- - cmake/templates/OpenCVConfig.root-WIN32.cmake.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - +diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake +index 7f229cde96..d8e20f8fe9 100644 +--- a/cmake/OpenCVDetectCXXCompiler.cmake ++++ b/cmake/OpenCVDetectCXXCompiler.cmake +@@ -171,8 +171,10 @@ elseif(MSVC) + set(OpenCV_RUNTIME vc15) + elseif(MSVC_VERSION MATCHES "^192[0-9]$") + set(OpenCV_RUNTIME vc16) +- elseif(MSVC_VERSION MATCHES "^193[0-9]$") ++ elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") + set(OpenCV_RUNTIME vc17) ++ elseif(MSVC_VERSION MATCHES "^195[0-9]$") ++ set(OpenCV_RUNTIME vc18) + else() + message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME") + endif() diff --git a/cmake/templates/OpenCVConfig.root-WIN32.cmake.in b/cmake/templates/OpenCVConfig.root-WIN32.cmake.in -index b0f254ebe8..62e36272f3 100644 +index b0f254ebe8..8f0178b0ae 100644 --- a/cmake/templates/OpenCVConfig.root-WIN32.cmake.in +++ b/cmake/templates/OpenCVConfig.root-WIN32.cmake.in @@ -137,7 +137,7 @@ elseif(MSVC) @@ -21,32 +27,28 @@ index b0f254ebe8..62e36272f3 100644 set(OpenCV_RUNTIME vc17) check_one_config(has_VS2022) if(NOT has_VS2022) --- -2.45.2.windows.1 - -From f85818ba6f9031c450475a7453dee0acce31a881 Mon Sep 17 00:00:00 2001 -From: Benjamin Buch -Date: Fri, 24 May 2024 11:10:09 +0200 -Subject: [PATCH] Support VS 2022 17.1x.y in OpenCVDetectCXXCompiler.cmake - -With 17.10.0 the MSVC toolset was set to 19.40.x which breaks the compatibility test in the OpenCV's CMake Config files. ---- - cmake/OpenCVDetectCXXCompiler.cmake | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake -index 1743aca11f..448afd46ea 100644 ---- a/cmake/OpenCVDetectCXXCompiler.cmake -+++ b/cmake/OpenCVDetectCXXCompiler.cmake -@@ -176,7 +176,7 @@ elseif(MSVC) - set(OpenCV_RUNTIME vc15) - elseif(MSVC_VERSION MATCHES "^192[0-9]$") - set(OpenCV_RUNTIME vc16) -- elseif(MSVC_VERSION MATCHES "^193[0-9]$") -+ elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") - set(OpenCV_RUNTIME vc17) - else() - message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME") --- -2.45.2.windows.1 - +@@ -151,6 +151,24 @@ elseif(MSVC) + endif() + endif() + endif() ++ elseif(MSVC_VERSION MATCHES "^195[0-9]$") ++ set(OpenCV_RUNTIME vc18) ++ check_one_config(has_VS2026) ++ if(NOT has_VS2026) ++ set(OpenCV_RUNTIME vc17) ++ check_one_config(has_VS2022) ++ if(NOT has_VS2022) ++ set(OpenCV_RUNTIME vc16) ++ check_one_config(has_VS2019) ++ if(NOT has_VS2019) ++ set(OpenCV_RUNTIME vc15) # selecting previous compatible runtime version ++ check_one_config(has_VS2017) ++ if(NOT has_VS2017) ++ set(OpenCV_RUNTIME vc14) # selecting previous compatible runtime version ++ endif() ++ endif() ++ endif() ++ endif() + endif() + elseif(MINGW) + set(OpenCV_RUNTIME mingw) diff --git a/deps/OpenCV/OpenCV.cmake b/deps/OpenCV/OpenCV.cmake index d9be1b7f50..ad8c0a3585 100644 --- a/deps/OpenCV/OpenCV.cmake +++ b/deps/OpenCV/OpenCV.cmake @@ -11,7 +11,7 @@ endif () orcaslicer_add_cmake_project(OpenCV URL https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz URL_HASH SHA256=1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277 - PATCH_COMMAND git apply ${OpenCV_DIRECTORY_FLAG} --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-vs2022.patch ${CMAKE_CURRENT_LIST_DIR}/0002-clang19-macos.patch + PATCH_COMMAND git apply ${OpenCV_DIRECTORY_FLAG} --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-vs.patch ${CMAKE_CURRENT_LIST_DIR}/0002-clang19-macos.patch CMAKE_ARGS -DBUILD_SHARED_LIBS=0 -DBUILD_PERE_TESTS=OFF diff --git a/deps/deps-windows.cmake b/deps/deps-windows.cmake index 5b47c68ce1..cd4dbd150f 100644 --- a/deps/deps-windows.cmake +++ b/deps/deps-windows.cmake @@ -19,6 +19,10 @@ elseif (MSVC_VERSION LESS 1950) # 1930-1949 = VS 17.0 (v143 toolset) set(DEP_VS_VER "17") set(DEP_BOOST_TOOLSET "msvc-14.3") +elseif (MSVC_VERSION LESS 1960) +# 1950-1959 = VS 18.0 (v145 toolset) + set(DEP_VS_VER "18") + set(DEP_BOOST_TOOLSET "msvc-14.5") else () message(FATAL_ERROR "Unsupported MSVC version") endif ()