1+ @ echo off
2+ setlocal enabledelayedexpansion
3+
4+ :: CUDA Toolkit should be manually installed on the computer before running this script
5+ :: We assume also that cuDNN is merged into CUDA installed directory.
6+ where nvcc > nul 2 >& 1
7+ if !errorlevel! neq 0 (
8+ echo [ERROR] nvcc was not found in your PATH.
9+ pause
10+ exit /b
11+ )
12+ for /f " tokens=5" %%a in ('nvcc --version ^ | findstr " release" ') do (
13+ set " RAW_VER = %%a "
14+ :: This removes the trailing comma
15+ set " CUDA_VER = !RAW_VER:, =! "
16+ set " CUDA_VER_SHORT = !CUDA_VER:. =! "
17+ )
18+ if " !CUDA_VER! " == " " (
19+ echo [ERROR] Could not parse CUDA version.
20+ pause
21+ exit /b
22+ )
23+ echo Installed CUDA Toolkit: %CUDA_VER%
24+
25+ :: --- CONFIGURATION ---
26+ set " VCPKG_ROOT = %~dp0 vcpkg"
27+ set " EXPORT_DIR = %~dp0 vcpkg_binaries"
28+ set " TRIPLET = x64-windows-release"
29+ set " SEVENZIP_EXE = C:\Program Files\7-Zip\7z.exe"
30+
31+ set " VCPKG_JSON = %~dp0 vcpkg.json"
32+ for /f " usebackq tokens=*" %%a in (`powershell -NoProfile -Command " (Get-Content '%VCPKG_JSON% ' -Raw | ConvertFrom-Json).'builtin-baseline'" ` ) do set " VCPKG_COMMIT = %%a "
33+
34+ if " %VCPKG_COMMIT% " == " " (
35+ echo [X] Error: Could not find 'builtin-baseline' in %VCPKG_JSON%
36+ pause
37+ exit /b 1
38+ )
39+
40+ set VCPKG_COMMIT_SHORT = %VCPKG_COMMIT:~0 ,8 %
41+ set " VS_LOCATOR = %ProgramFiles(x86)% \Microsoft Visual Studio\Installer\vswhere.exe"
42+ for /f " usebackq tokens=*" %%i in (`" %VS_LOCATOR% " -latest -property catalog_productLineVersion`) do set VS_YEAR = vs%%i
43+ set ORG_TARGET_NAME = vcpkg-export-%VCPKG_COMMIT_SHORT% -x64-%VS_YEAR%
44+ set TARGET_NAME = %ORG_TARGET_NAME% -cuda%CUDA_VER_SHORT%
45+ set VCPKG_EXPORT_PATH = %EXPORT_DIR% \%ORG_TARGET_NAME%
46+ set FINAL_EXPORT_PATH = %EXPORT_DIR% \%TARGET_NAME%
47+
48+ if not exist " %FINAL_EXPORT_PATH% " (
49+ if not exist " %VCPKG_EXPORT_PATH% " (
50+ call bundle_windows_deps.bat || exit /b %errorlevel%
51+ )
52+ echo [+] Copying %VCPKG_EXPORT_PATH% to %FINAL_EXPORT_PATH%
53+ xcopy " %VCPKG_EXPORT_PATH% " " %FINAL_EXPORT_PATH% \" /E /I /H /Y /Q || exit /b %errorlevel%
54+ echo [+] Remove opencv built by vcpkg
55+ rmdir /s /q " %FINAL_EXPORT_PATH% \installed\%TRIPLET% \include\opencv4" || exit /b %errorlevel%
56+ rmdir /s /q " %FINAL_EXPORT_PATH% \installed\%TRIPLET% \share\opencv4" || exit /b %errorlevel%
57+ rmdir /s /q " %FINAL_EXPORT_PATH% \installed\%TRIPLET% \share\opencv" || exit /b %errorlevel%
58+ del " %FINAL_EXPORT_PATH% \installed\%TRIPLET% \bin\opencv*" || exit /b %errorlevel%
59+ del " %FINAL_EXPORT_PATH% \installed\%TRIPLET% \lib\opencv*" || exit /b %errorlevel%
60+ )
61+
62+ :: pytorch deps
63+ %FINAL_EXPORT_PATH% /installed/%TRIPLET% /tools/python3/python.exe -m pip install numpy packaging " cmake<4" setuptools pyyaml typing_extensions
64+
65+ :: pytorch, build with local cuda libraries to avoid duplicating them when we install rtabmap
66+ echo [+] Building pytorch with cuda support...
67+ if not exist pytorch (
68+ echo [+] Downloading pytorch...
69+ git config --global core.longpaths true
70+ git clone https://github.com/pytorch/pytorch || exit /b %errorlevel%
71+ cd pytorch
72+ :: Jan 21, 2026
73+ git checkout v2.10.0
74+ git submodule update --init --recursive || exit /b %errorlevel%
75+ cd ..
76+ )
77+
78+ cd pytorch
79+ set CMAKE_GENERATOR = Ninja
80+ set Python_ROOT_DIR = %FINAL_EXPORT_PATH% \installed\x64-windows-release
81+ set PYTHONHOME = %FINAL_EXPORT_PATH% \installed\x64-windows-release\tools\python3
82+ set BUILD_TEST = 0
83+ set LIB = " %LIB% ;%FINAL_EXPORT_PATH% \installed\x64-windows-release\lib"
84+ set INCLUDE = " %INCLUDE% ;%FINAL_EXPORT_PATH% \installed\x64-windows-release\include"
85+ %FINAL_EXPORT_PATH% /installed/%TRIPLET% /tools/python3/python.exe setup.py install || exit /b %errorlevel%
86+ cd ..
87+
88+ :: opencv_cuda
89+ echo [+] Building opencv with cuda support...
90+ if not exist opencv (
91+ echo [+] Downloading opencv...
92+ git clone https://github.com/opencv/opencv.git || exit /b %errorlevel%
93+ cd opencv
94+ :: 4.13.0 minimum required to be compatible with cuda 13
95+ :: Dec 31, 2025
96+ git checkout 4.13.0
97+ cd ..
98+ )
99+ if not exist opencv_contrib (
100+ echo [+] Downloading opencv_contrib...
101+ git clone https://github.com/opencv/opencv_contrib.git || exit /b %errorlevel%
102+ cd opencv
103+ :: 4.13.0 minimum required to be compatible with cuda 13
104+ :: Dec 31, 2025
105+ git checkout 4.13.0
106+ cd ..
107+ )
108+ cd opencv
109+ cmake -S . -B build -GNinja ^
110+ -DVCPKG_MANIFEST_INSTALL=OFF ^
111+ -DVCPKG_TARGET_TRIPLET=x64-windows-release ^
112+ -DVCPKG_INSTALLED_DIR=" %FINAL_EXPORT_PATH% \installed" ^
113+ -DCMAKE_TOOLCHAIN_FILE=" %FINAL_EXPORT_PATH% \scripts\buildsystems\vcpkg.cmake" ^
114+ -DCMAKE_INSTALL_PREFIX=" %FINAL_EXPORT_PATH% \installed\%TRIPLET% " ^
115+ -DCMAKE_BUILD_TYPE=Release ^
116+ -DOPENCV_BIN_INSTALL_PATH=" bin" ^
117+ -DOPENCV_LIB_INSTALL_PATH=" lib" ^
118+ -DOPENCV_CONFIG_INSTALL_PATH=" share/opencv" ^
119+ -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ^
120+ -DBUILD_SHARED_LIBS=ON ^
121+ -DBUILD_TESTS=OFF ^
122+ -DBUILD_PERF_TESTS=OFF ^
123+ -DOPENCV_ENABLE_NONFREE=ON ^
124+ -DBUILD_opencv_apps=OFF ^
125+ -DBUILD_opencv_python3=ON ^
126+ -DPYTHON_EXECUTABLE=%FINAL_EXPORT_PATH% /installed/%TRIPLET% /tools/python3/python.exe ^
127+ -DBUILD_opencv_java_bindings_generator=OFF ^
128+ -DWITH_CUDA=ON ^
129+ -DWITH_TBB=ON || exit /b %errorlevel%
130+ cmake --build build --config Release --target install || exit /b %errorlevel%
131+ cd ..
132+
133+
134+ :: 5. ZIP the folder
135+ echo [+] Creating final package with 7-Zip...
136+ :: Rip off pdb files
137+ cd /d " %FINAL_EXPORT_PATH% "
138+ del /s /q /f *.pdb > nul 2 >& 1
139+
140+ cd ..
141+
142+ set " FINAL_ZIP = %TARGET_NAME% .7z"
143+
144+ :: compress contents without the root folder
145+ " %SEVENZIP_EXE% " u -t7z -mx9 " %FINAL_ZIP% " " %FINAL_EXPORT_PATH% \*" -up0q0
146+
147+ if %ERRORLEVEL% EQU 0 (
148+ echo [!] Success! Package created at %FINAL_ZIP%
149+ ) else (
150+ echo [X] 7-Zip failed with error code %ERRORLEVEL%
151+ )
152+
153+ :: Example building rtabmap with opencv cuda and libtorch afterwards
154+ goto :EndComment
155+
156+ set VCPKG_UNZIPPED_EXPORT_PATH = %USERPROFILE% \Downloads\vcpkg-export-########-x64-vs2022-cuda131
157+ set PATH = %VCPKG_UNZIPPED_EXPORT_PATH% \installed\x64-windows-release\bin;%PATH%
158+ set PATH = %CUDA_PATH% \bin\x64;%PATH%
159+ set PATH = %CUDA_PATH% \extras\CUPTI\lib64;%PATH%
160+ set PATH = %VCPKG_UNZIPPED_EXPORT_PATH% \installed\x64-windows-release\tools\python3\Lib\site-packages\torch\lib;%PATH%
161+
162+ cmake -B build_cuda -GNinja ^
163+ -DCMAKE_BUILD_TYPE=Release ^
164+ -DBUILD_AS_BUNDLE=ON ^
165+ -DWITH_PYTHON=ON ^
166+ -DWITH_TORCH=ON ^
167+ -DWITH_ZED=ON ^
168+ -DVCPKG_MANIFEST_INSTALL=OFF ^
169+ -DVCPKG_TARGET_TRIPLET=x64-windows-release ^
170+ -DVCPKG_INSTALLED_DIR=" %VCPKG_UNZIPPED_EXPORT_PATH% /installed" ^
171+ -DCMAKE_TOOLCHAIN_FILE=%VCPKG_UNZIPPED_EXPORT_PATH% /scripts/buildsystems/vcpkg.cmake ^
172+ -DGTSAM_DIR=%VCPKG_UNZIPPED_EXPORT_PATH% \installed\x64-windows-release\CMake ^
173+ -DTorch_DIR=%VCPKG_UNZIPPED_EXPORT_PATH% \installed\x64-windows-release\tools\python3\Lib\site-packages\torch\share\cmake\Torch
174+
175+ cmake --build build_cuda --config Release --target package
176+
177+ :EndComment
0 commit comments