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
This commit is contained in:
Noisyfox
2025-11-13 23:11:56 +08:00
committed by GitHub
parent d94fa0a95d
commit 7f1aad8bc1
7 changed files with 170 additions and 44 deletions

View File

@@ -69,8 +69,8 @@ jobs:
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: | run: |
choco install strawberryperl choco install strawberryperl
.\build_release_vs2022.bat deps .\build_release_vs.bat deps
.\build_release_vs2022.bat pack .\build_release_vs.bat pack
cd ${{ github.workspace }}/deps/build cd ${{ github.workspace }}/deps/build
- name: Build on Mac ${{ inputs.arch }} - name: Build on Mac ${{ inputs.arch }}

View File

@@ -233,7 +233,7 @@ jobs:
env: env:
WindowsSdkDir: 'C:\Program Files (x86)\Windows Kits\10\' WindowsSdkDir: 'C:\Program Files (x86)\Windows Kits\10\'
WindowsSDKVersion: '10.0.26100.0\' WindowsSDKVersion: '10.0.26100.0\'
run: .\build_release_vs2022.bat slicer run: .\build_release_vs.bat slicer
- name: Create installer Win - name: Create installer Win
if: inputs.os == 'windows-latest' if: inputs.os == 'windows-latest'

119
build_release_vs.bat Normal file
View File

@@ -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%

View File

@@ -61,6 +61,7 @@ mkdir %build_dir%
cd %build_dir% cd %build_dir%
echo on 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 .. -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 cmake --build . --config %build_type% --target ALL_BUILD -- -m
@echo off @echo off

View File

@@ -1,15 +1,21 @@
From 6fb3f6333150a777e835fc7c48e49750591bf7fe Mon Sep 17 00:00:00 2001 diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake
From: Benjamin Buch <bebuch@users.noreply.github.com> index 7f229cde96..d8e20f8fe9 100644
Date: Thu, 23 May 2024 16:05:19 +0200 --- a/cmake/OpenCVDetectCXXCompiler.cmake
Subject: [PATCH] Support VS 2022 17.1x.y +++ b/cmake/OpenCVDetectCXXCompiler.cmake
@@ -171,8 +171,10 @@ elseif(MSVC)
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. set(OpenCV_RUNTIME vc15)
--- elseif(MSVC_VERSION MATCHES "^192[0-9]$")
cmake/templates/OpenCVConfig.root-WIN32.cmake.in | 2 +- set(OpenCV_RUNTIME vc16)
1 file changed, 1 insertion(+), 1 deletion(-) - 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 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 --- a/cmake/templates/OpenCVConfig.root-WIN32.cmake.in
+++ b/cmake/templates/OpenCVConfig.root-WIN32.cmake.in +++ b/cmake/templates/OpenCVConfig.root-WIN32.cmake.in
@@ -137,7 +137,7 @@ elseif(MSVC) @@ -137,7 +137,7 @@ elseif(MSVC)
@@ -21,32 +27,28 @@ index b0f254ebe8..62e36272f3 100644
set(OpenCV_RUNTIME vc17) set(OpenCV_RUNTIME vc17)
check_one_config(has_VS2022) check_one_config(has_VS2022)
if(NOT has_VS2022) if(NOT has_VS2022)
-- @@ -151,6 +151,24 @@ elseif(MSVC)
2.45.2.windows.1 endif()
endif()
From f85818ba6f9031c450475a7453dee0acce31a881 Mon Sep 17 00:00:00 2001 endif()
From: Benjamin Buch <bebuch@users.noreply.github.com> + elseif(MSVC_VERSION MATCHES "^195[0-9]$")
Date: Fri, 24 May 2024 11:10:09 +0200 + set(OpenCV_RUNTIME vc18)
Subject: [PATCH] Support VS 2022 17.1x.y in OpenCVDetectCXXCompiler.cmake + check_one_config(has_VS2026)
+ if(NOT has_VS2026)
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. + set(OpenCV_RUNTIME vc17)
--- + check_one_config(has_VS2022)
cmake/OpenCVDetectCXXCompiler.cmake | 2 +- + if(NOT has_VS2022)
1 file changed, 1 insertion(+), 1 deletion(-) + set(OpenCV_RUNTIME vc16)
+ check_one_config(has_VS2019)
diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake + if(NOT has_VS2019)
index 1743aca11f..448afd46ea 100644 + set(OpenCV_RUNTIME vc15) # selecting previous compatible runtime version
--- a/cmake/OpenCVDetectCXXCompiler.cmake + check_one_config(has_VS2017)
+++ b/cmake/OpenCVDetectCXXCompiler.cmake + if(NOT has_VS2017)
@@ -176,7 +176,7 @@ elseif(MSVC) + set(OpenCV_RUNTIME vc14) # selecting previous compatible runtime version
set(OpenCV_RUNTIME vc15) + endif()
elseif(MSVC_VERSION MATCHES "^192[0-9]$") + endif()
set(OpenCV_RUNTIME vc16) + endif()
- elseif(MSVC_VERSION MATCHES "^193[0-9]$") + endif()
+ elseif(MSVC_VERSION MATCHES "^19[34][0-9]$") endif()
set(OpenCV_RUNTIME vc17) elseif(MINGW)
else() set(OpenCV_RUNTIME mingw)
message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME")
--
2.45.2.windows.1

View File

@@ -11,7 +11,7 @@ endif ()
orcaslicer_add_cmake_project(OpenCV orcaslicer_add_cmake_project(OpenCV
URL https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz URL https://github.com/opencv/opencv/archive/refs/tags/4.6.0.tar.gz
URL_HASH SHA256=1ec1cba65f9f20fe5a41fda1586e01c70ea0c9a6d7b67c9e13edf0cfe2239277 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 CMAKE_ARGS
-DBUILD_SHARED_LIBS=0 -DBUILD_SHARED_LIBS=0
-DBUILD_PERE_TESTS=OFF -DBUILD_PERE_TESTS=OFF

View File

@@ -19,6 +19,10 @@ elseif (MSVC_VERSION LESS 1950)
# 1930-1949 = VS 17.0 (v143 toolset) # 1930-1949 = VS 17.0 (v143 toolset)
set(DEP_VS_VER "17") set(DEP_VS_VER "17")
set(DEP_BOOST_TOOLSET "msvc-14.3") 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 () else ()
message(FATAL_ERROR "Unsupported MSVC version") message(FATAL_ERROR "Unsupported MSVC version")
endif () endif ()