forked from PokemonAutomation/Arduino-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.bat
More file actions
242 lines (204 loc) · 6.46 KB
/
Copy pathBuild.bat
File metadata and controls
242 lines (204 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
@echo off
setlocal EnableDelayedExpansion
set "ROOT_DIR=%~dp0"
set "SOURCE_DIR=%ROOT_DIR%SerialPrograms"
set "DEFAULT_PRESET=RelWithDebInfo"
set "CMAKE_EXE=cmake"
set "QT_PREFIX_PATH="
if /I "%~1"=="-h" goto :usage
if /I "%~1"=="--help" goto :usage
if /I "%~1"=="/?" goto :usage
set "PRESET=%~1"
if "%PRESET%"=="" set "PRESET=%DEFAULT_PRESET%"
if not "%~1"=="" shift /1
set "CMAKE_ARGS="
:collect_args
if "%~1"=="" goto :args_done
set "CMAKE_ARGS=%CMAKE_ARGS% %~1"
shift /1
goto :collect_args
:args_done
if not exist "%SOURCE_DIR%\CMakeLists.txt" (
echo ERROR: Could not find SerialPrograms\CMakeLists.txt.
echo Run this script from the Arduino-Source checkout, or keep it in the repo root.
exit /b 1
)
call :setup_cmake
if errorlevel 1 (
echo ERROR: CMake was not found on PATH.
echo Install CMake and rerun this script.
exit /b 1
)
where ninja >nul 2>nul
if errorlevel 1 (
echo ERROR: Ninja was not found on PATH.
echo The CMake presets use the Ninja generator. Install Ninja or add it to PATH.
exit /b 1
)
call :setup_qt_path
if errorlevel 1 exit /b 1
call :clean_msys_cmake_cache
where cl >nul 2>nul
if errorlevel 1 call :setup_msvc
if errorlevel 1 exit /b 1
pushd "%SOURCE_DIR%"
echo.
echo === Configuring SerialPrograms (%PRESET%) ===
if "%QT_PREFIX_PATH%"=="" (
"%CMAKE_EXE%" --preset "%PRESET%"%CMAKE_ARGS%
) else (
"%CMAKE_EXE%" --preset "%PRESET%" -DCMAKE_PREFIX_PATH="%QT_PREFIX_PATH%" -DPREFERRED_QT_DIR="%QT_ROOT_DIR%" -DPREFERRED_QT_VER="%QT_VERSION%"%CMAKE_ARGS%
)
if errorlevel 1 (
echo.
echo ERROR: CMake configure failed.
popd
exit /b 1
)
echo.
echo === Building SerialPrograms (%PRESET%) ===
"%CMAKE_EXE%" --build --preset "%PRESET%" --parallel
if errorlevel 1 (
echo.
echo ERROR: Build failed.
popd
exit /b 1
)
popd
echo.
echo Build completed successfully.
echo Output folder: "%ROOT_DIR%build\%PRESET%"
exit /b 0
:setup_cmake
if exist "%ProgramFiles%\CMake\bin\cmake.exe" (
set "CMAKE_EXE=%ProgramFiles%\CMake\bin\cmake.exe"
exit /b 0
)
if exist "%ProgramFiles(x86)%\CMake\bin\cmake.exe" (
set "CMAKE_EXE=%ProgramFiles(x86)%\CMake\bin\cmake.exe"
exit /b 0
)
where cmake >nul 2>nul
if errorlevel 1 exit /b 1
for /f "tokens=*" %%I in ('where cmake') do (
set "CMAKE_EXE=%%I"
goto :cmake_found
)
:cmake_found
echo "%CMAKE_EXE%" | findstr /I "msys2" >nul
if not errorlevel 1 (
echo ERROR: The first CMake on PATH is MSYS2 CMake:
echo "%CMAKE_EXE%"
echo Install native Windows CMake or move it before MSYS2 on PATH.
exit /b 1
)
exit /b 0
:setup_msvc
echo MSVC compiler environment not detected. Looking for Visual Studio 2022...
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" (
echo ERROR: cl.exe was not found, and vswhere.exe is not installed.
echo Run this script from "x64 Native Tools Command Prompt for VS 2022" or install Visual Studio 2022 C++ tools.
exit /b 1
)
for /f "usebackq tokens=*" %%I in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VS_INSTALL=%%I"
if "%VS_INSTALL%"=="" (
echo ERROR: Visual Studio 2022 C++ tools were not found.
echo Install the "Desktop development with C++" workload.
exit /b 1
)
set "VSDEVCMD=%VS_INSTALL%\Common7\Tools\VsDevCmd.bat"
if not exist "%VSDEVCMD%" (
echo ERROR: Could not find VsDevCmd.bat at "%VSDEVCMD%".
exit /b 1
)
call "%VSDEVCMD%" -arch=x64 -host_arch=x64
where cl >nul 2>nul
if errorlevel 1 (
echo ERROR: Visual Studio environment setup completed, but cl.exe is still unavailable.
exit /b 1
)
exit /b 0
:setup_qt_path
call :try_qt_dir "C:\Qt\6.8.3"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
call :try_qt_dir "C:\Qt6.8.3\6.8.3"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
call :try_qt_dir "C:\Qt6.8.3"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
call :try_qt_dir "C:\Qt\6.10.0"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
call :try_qt_dir "C:\Qt6.10.0\6.10.0"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
call :try_qt_dir "C:\Qt6.10.0"
if not "%QT_PREFIX_PATH%"=="" exit /b 0
for /d %%D in ("C:\Qt\6.*") do (
call :try_qt_dir "%%~fD"
if not "!QT_PREFIX_PATH!"=="" exit /b 0
)
for /d %%D in ("C:\Qt*") do (
call :try_qt_dir "%%~fD"
if not "!QT_PREFIX_PATH!"=="" exit /b 0
)
echo WARNING: Qt MSVC 2022 64-bit development files were not found.
echo Expected a file like:
echo C:\Qt\6.8.3\msvc2022_64\lib\cmake\Qt6\Qt6Config.cmake
echo.
echo CMake will fail until Qt is installed or you pass a prefix, for example:
echo Build.bat %PRESET% -DCMAKE_PREFIX_PATH=C:/Qt/6.8.3/msvc2022_64/lib/cmake
echo.
echo Install the Qt 6.8.3 MSVC 2022 64-bit component, then rerun this script.
echo.
echo If Qt is already installed elsewhere, rerun with -DCMAKE_PREFIX_PATH=... or -DQt6_DIR=...
echo.
echo "%CMAKE_ARGS%" | findstr /I "CMAKE_PREFIX_PATH Qt6_DIR" >nul
if not errorlevel 1 exit /b 0
if not "%CMAKE_PREFIX_PATH%"=="" exit /b 0
exit /b 1
:try_qt_dir
set "QT_CANDIDATE=%~1"
if exist "%QT_CANDIDATE%\msvc2022_64\lib\cmake\Qt6\Qt6Config.cmake" (
set "QT_PREFIX_PATH=%QT_CANDIDATE%\msvc2022_64\lib\cmake"
set "QT_ROOT_DIR=%~dp1"
set "QT_ROOT_DIR=%QT_ROOT_DIR:~0,-1%"
set "QT_VERSION=%~nx1"
set "PATH=%QT_CANDIDATE%\msvc2022_64\bin;%PATH%"
echo Found Qt %QT_VERSION% at "%QT_CANDIDATE%\msvc2022_64".
exit /b 0
)
if exist "%QT_CANDIDATE%\lib\cmake\Qt6\Qt6Config.cmake" (
set "QT_PREFIX_PATH=%QT_CANDIDATE%\lib\cmake"
set "QT_ROOT_DIR=%~dp1"
set "QT_ROOT_DIR=%QT_ROOT_DIR:~0,-1%"
set "QT_VERSION=%~nx1"
set "PATH=%QT_CANDIDATE%\bin;%PATH%"
echo Found Qt at "%QT_CANDIDATE%".
exit /b 0
)
exit /b 0
:clean_msys_cmake_cache
set "BUILD_DIR=%ROOT_DIR%build\%PRESET%"
set "CACHE_FILE=%BUILD_DIR%\CMakeCache.txt"
if not exist "%CACHE_FILE%" exit /b 0
findstr /C:"/home/" /C:"/c/" /C:"devkitPro/msys2" "%CACHE_FILE%" >nul 2>nul
if errorlevel 1 exit /b 0
echo.
echo Removing stale CMake cache created by MSYS2 CMake:
echo "%BUILD_DIR%"
del /q "%CACHE_FILE%" >nul 2>nul
if exist "%BUILD_DIR%\CMakeFiles" rd /s /q "%BUILD_DIR%\CMakeFiles"
exit /b 0
:usage
echo Build SerialPrograms with the repo's CMake presets.
echo.
echo Usage:
echo Build.bat [preset] [extra CMake configure args]
echo.
echo Examples:
echo Build.bat
echo Build.bat Debug
echo Build.bat Release -DPREFERRED_QT_DIR=C:/Qt -DPREFERRED_QT_VER=6.8.3
echo.
echo Available presets are defined in SerialPrograms\CMakePresets.json:
echo Debug, Release, RelWithDebInfo, MinSizeRel, Publish
exit /b 0