Repository navigation
Expand file tree
/
Copy pathbuild.cmd
More file actions
415 lines (364 loc) · 12.7 KB
/
Copy pathbuild.cmd
File metadata and controls
415 lines (364 loc) · 12.7 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
@echo off
setlocal enabledelayedexpansion
set "PROJECT_ROOT=%~dp0"
set "PROJECT_ROOT=%PROJECT_ROOT:~0,-1%"
set "LOCAL_INSTALL_DIR=%PROJECT_ROOT%\local-install"
set "BUILD_TYPE=Release"
set "PRESET=windows-release"
set "LIVEKIT_VERSION="
set "CMAKE_EXTRA_ARGS="
set "CAPTURE_OVERRIDE=none"
set "BUILD_PARALLEL_JOBS="
set "DO_BUNDLE="
set "PREFIX="
REM ============================================================
REM Auto-detect LIBCLANG_PATH if not already set
REM ============================================================
if not defined LIBCLANG_PATH (
echo ==^> Detecting LIBCLANG_PATH...
REM Define common VS installation paths to check
REM VS 2022 editions
set "VS_PATHS[0]=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[1]=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[2]=D:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[3]=C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[4]=D:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[5]=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[6]=D:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[7]=C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\x64\bin"
REM VS 2019 editions
set "VS_PATHS[8]=D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[9]=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[10]=D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[11]=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[12]=D:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin"
set "VS_PATHS[13]=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin"
REM Standalone LLVM installations
set "VS_PATHS[14]=C:\Program Files\LLVM\bin"
set "VS_PATHS[15]=D:\Program Files\LLVM\bin"
set "LIBCLANG_FOUND="
for /L %%i in (0,1,15) do (
if not defined LIBCLANG_FOUND (
if exist "!VS_PATHS[%%i]!\libclang.dll" (
set "LIBCLANG_PATH=!VS_PATHS[%%i]!"
set "LIBCLANG_FOUND=1"
echo Found libclang at: !LIBCLANG_PATH!
)
)
)
if not defined LIBCLANG_FOUND (
echo Warning: Could not auto-detect LIBCLANG_PATH.
echo Please set LIBCLANG_PATH manually to the directory containing libclang.dll
echo Example: set LIBCLANG_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin
)
) else (
echo ==^> Using existing LIBCLANG_PATH: %LIBCLANG_PATH%
)
if "%1"=="" (
echo ERROR: No command specified
call :usage
exit /b 1
)
if /I "%1"=="help" goto usage
if "%1"=="-h" goto usage
if "%1"=="--help" goto usage
set "CMD="
set "LIVEKIT_VERSION="
:parse_all
if "%~1"=="" goto after_parse
:: 1. Capture the command if we don't have one yet
if not defined CMD (
set "CMD=%~1"
echo Command set to: %~1
shift
goto parse_all
)
:: 2. Check for the version flag
if /I "%~1"=="--version" (
shift
goto :get_version_value
)
set "ARG=%~1"
if /I "!ARG:~0,10!"=="--capture=" (
set "CAPTURE_OVERRIDE=!ARG:~10!"
if "!CAPTURE_OVERRIDE!"=="" (
echo ERROR: --capture= requires a value ^(gstreamer, pattern, clock, or all^)
exit /b 1
)
shift
goto :collect_capture_tokens
)
if /I "%~1"=="--capture" (
set "CAPTURE_OVERRIDE="
shift
goto :collect_capture_tokens
)
if /I "%~1"=="--no-capture" (
set "CAPTURE_OVERRIDE=none"
shift
goto parse_all
)
:: 3. Install the SDK bundle after a successful build.
if /I "%~1"=="--bundle" (
set "DO_BUNDLE=1"
shift
goto parse_all
)
:: 4. Set the install prefix for --bundle.
if /I "%~1"=="--prefix" (
shift
goto :get_prefix_value
)
:: 5. Handle unknown arguments
echo ERROR: Unknown option: %~1
exit /b 1
:get_version_value
echo 1 after shift is : %~1
set "LIVEKIT_VERSION=%~1"
shift
goto parse_all
:get_prefix_value
if "%~1"=="" (
echo ERROR: --prefix requires a value
exit /b 1
)
set "PREFIX=%~1"
shift
goto parse_all
REM cmd.exe splits unquoted commas and equals signs. Rejoin source names that
REM followed --capture so --capture=pattern,clock reaches CMake intact.
:collect_capture_tokens
if "%~1"=="" goto :finish_capture_tokens
set "NEXT=%~1"
if /I "!NEXT!"=="gstreamer" goto :append_capture_token
if /I "!NEXT!"=="pattern" goto :append_capture_token
if /I "!NEXT!"=="clock" goto :append_capture_token
if /I "!NEXT!"=="all" goto :append_capture_token
if /I "!NEXT!"=="none" goto :append_capture_token
goto :finish_capture_tokens
:append_capture_token
if defined CAPTURE_OVERRIDE (
set "CAPTURE_OVERRIDE=!CAPTURE_OVERRIDE!,!NEXT!"
) else (
set "CAPTURE_OVERRIDE=!NEXT!"
)
shift
goto :collect_capture_tokens
:finish_capture_tokens
if not defined CAPTURE_OVERRIDE set "CAPTURE_OVERRIDE=all"
goto parse_all
:validate_capture
set "CAPTURE_CHECK=!CAPTURE_OVERRIDE!"
set "CAPTURE_CHECK=!CAPTURE_CHECK: =!"
if /I "!CAPTURE_CHECK!"=="" exit /b 0
if /I "!CAPTURE_CHECK!"=="none" exit /b 0
if /I "!CAPTURE_CHECK!"=="all" exit /b 0
set "CAPTURE_CHECK=!CAPTURE_CHECK:,= !"
set "CAPTURE_INVALID="
for %%T in (!CAPTURE_CHECK!) do (
if /I not "%%T"=="gstreamer" if /I not "%%T"=="pattern" if /I not "%%T"=="clock" (
echo ERROR: Unknown capture source '%%T'. Expected: gstreamer, pattern, clock, all, or none.
set "CAPTURE_INVALID=1"
)
)
if defined CAPTURE_INVALID exit /b 1
exit /b 0
:after_parse
call :validate_capture
if errorlevel 1 exit /b 1
if not defined CMD (
echo ERROR: No command specified
call :usage
exit /b 1
)
if defined LIVEKIT_VERSION (
set "CMAKE_EXTRA_ARGS=-DLIVEKIT_VERSION=%LIVEKIT_VERSION%"
echo ==^> Injecting LIVEKIT_VERSION=%LIVEKIT_VERSION%
)
set "CMAKE_EXTRA_ARGS=%CMAKE_EXTRA_ARGS% -DLIVEKIT_CAPTURE=%CAPTURE_OVERRIDE%"
goto dispatch
:dispatch
if "%CMD%"=="debug" (
set "BUILD_TYPE=Debug"
set "PRESET=windows-debug"
set "BUILD_DIR=%PROJECT_ROOT%\build-debug"
goto configure_build
)
if "%CMD%"=="debug-examples" (
set "BUILD_TYPE=Debug"
set "PRESET=windows-debug-examples"
set "BUILD_DIR=%PROJECT_ROOT%\build-debug"
goto configure_build
)
if "%CMD%"=="release" (
set "BUILD_TYPE=Release"
set "PRESET=windows-release"
set "BUILD_DIR=%PROJECT_ROOT%\build-release"
goto configure_build
)
if "%CMD%"=="release-examples" (
set "BUILD_TYPE=Release"
set "PRESET=windows-release-examples"
set "BUILD_DIR=%PROJECT_ROOT%\build-release"
goto configure_build
)
if "%CMD%"=="debug-tests" (
set "BUILD_TYPE=Debug"
set "PRESET=windows-debug-tests"
set "BUILD_DIR=%PROJECT_ROOT%\build-debug"
goto configure_build
)
if "%CMD%"=="release-tests" (
set "BUILD_TYPE=Release"
set "PRESET=windows-release-tests"
set "BUILD_DIR=%PROJECT_ROOT%\build-release"
goto configure_build
)
if "%CMD%"=="release-all" (
set "BUILD_TYPE=Release"
set "PRESET=windows-release-all"
set "BUILD_DIR=%PROJECT_ROOT%\build-release"
goto configure_build
)
if "%CMD%"=="debug-all" (
set "BUILD_TYPE=Debug"
set "PRESET=windows-debug-all"
set "BUILD_DIR=%PROJECT_ROOT%\build-debug"
goto configure_build
)
if "%CMD%"=="clean" goto clean
if "%CMD%"=="clean-all" goto clean_all
echo ERROR: Unknown command: %CMD%
call :usage
exit /b 1
:usage
echo Usage: build.cmd [command]
echo.
echo Commands:
echo debug Configure + build Debug version (build-debug/)
echo debug-examples Configure + build Debug version with examples
echo debug-tests Configure + build Debug version with tests
echo debug-all Configure + build Debug version with tests + examples
echo release Configure + build Release version (build-release/)
echo release-examples Configure + build Release version with examples
echo release-tests Configure + build Release version with tests
echo release-all Configure + build Release version with tests + examples
echo clean Clean both Debug and Release build directories + local-install
echo clean-all Full clean (build dirs + local-install + Rust targets)
echo help Show this help
echo.
echo Options (for debug / release):
echo --capture[=list] Enable capture sources ^(default: all^).
echo list: gstreamer, pattern, clock ^(comma-separated^)
echo --no-capture Explicitly disable capture sources ^(the default^)
echo --bundle Install the SDK bundle using cmake --install
echo --prefix ^<dir^> Install prefix for --bundle ^(default: .\sdk-out\livekit-sdk^)
echo.
echo Examples:
echo build.cmd debug
echo build.cmd release
echo build.cmd release-examples
echo build.cmd release --bundle --prefix C:\path\to\livekit-sdk
echo build.cmd debug-tests
echo build.cmd release-tests
echo build.cmd release-all
echo build.cmd clean
echo build.cmd clean-all
goto :eof
:configure_build
echo ==^> Configuring CMake (%BUILD_TYPE%)...
if not defined VCPKG_ROOT (
echo Warning: VCPKG_ROOT is not set. Attempting to configure without vcpkg...
cmake -S . -B "%BUILD_DIR%" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=%BUILD_TYPE% %CMAKE_EXTRA_ARGS%
) else (
cmake --preset "%PRESET%" %CMAKE_EXTRA_ARGS%
)
if errorlevel 1 (
echo Configuration failed!
exit /b 1
)
goto build_only
:build_only
if not defined BUILD_PARALLEL_JOBS (
if defined CMAKE_BUILD_PARALLEL_LEVEL (
set "BUILD_PARALLEL_JOBS=%CMAKE_BUILD_PARALLEL_LEVEL%"
) else if defined NUMBER_OF_PROCESSORS (
set "BUILD_PARALLEL_JOBS=%NUMBER_OF_PROCESSORS%"
) else (
set "BUILD_PARALLEL_JOBS=2"
)
)
echo ==^> Building (%BUILD_TYPE%) with %BUILD_PARALLEL_JOBS% parallel jobs...
cmake --build "%BUILD_DIR%" --config %BUILD_TYPE% --parallel "%BUILD_PARALLEL_JOBS%"
if errorlevel 1 (
echo Build failed!
exit /b 1
)
echo ==^> Build complete!
if defined DO_BUNDLE (
call :install_bundle
if errorlevel 1 exit /b 1
)
goto :eof
:install_bundle
if not defined PREFIX set "PREFIX=%PROJECT_ROOT%\sdk-out\livekit-sdk"
if not "%PREFIX:~1,1%"==":" set "PREFIX=%PROJECT_ROOT%\%PREFIX%"
REM cmd's mkdir/rmdir reject forward slashes; normalize to backslashes.
set "PREFIX=%PREFIX:/=\%"
echo ==^> Installing SDK bundle to: %PREFIX%
if exist "%PREFIX%" rmdir /s /q "%PREFIX%"
if exist "%PREFIX%" (
echo Failed to remove existing bundle directory: %PREFIX%
exit /b 1
)
mkdir "%PREFIX%"
if errorlevel 1 exit /b 1
cmake --install "%BUILD_DIR%" --config %BUILD_TYPE% --prefix "%PREFIX%"
if errorlevel 1 (
echo SDK bundle install failed!
exit /b 1
)
echo ==^> SDK bundle installed.
exit /b 0
:clean
echo ==^> Cleaning build directories...
set "BUILD_DIR_DEBUG=%PROJECT_ROOT%\build-debug"
set "BUILD_DIR_RELEASE=%PROJECT_ROOT%\build-release"
if exist "%BUILD_DIR_DEBUG%\CMakeCache.txt" (
echo Cleaning build-debug...
cmake --build "%BUILD_DIR_DEBUG%" --target clean --config Debug 2>nul
) else (
echo ^(skipping^) build-debug does not exist or is not configured.
)
if exist "%BUILD_DIR_RELEASE%\CMakeCache.txt" (
echo Cleaning build-release...
cmake --build "%BUILD_DIR_RELEASE%" --target clean --config Release 2>nul
) else (
echo ^(skipping^) build-release does not exist or is not configured.
)
echo Removing local-install...
if exist "%LOCAL_INSTALL_DIR%" (
rmdir /s /q "%LOCAL_INSTALL_DIR%" 2>nul
)
echo ==^> Clean complete.
goto :eof
:clean_all
echo ==^> Running full clean-all ^(C++ + local-install + Rust^)...
echo Removing build-debug directory...
if exist "%PROJECT_ROOT%\build-debug" (
rmdir /s /q "%PROJECT_ROOT%\build-debug" 2>nul
)
echo Removing build-release directory...
if exist "%PROJECT_ROOT%\build-release" (
rmdir /s /q "%PROJECT_ROOT%\build-release" 2>nul
)
echo Removing local-install directory...
if exist "%LOCAL_INSTALL_DIR%" (
rmdir /s /q "%LOCAL_INSTALL_DIR%" 2>nul
)
echo Removing Rust target directory...
if exist "%PROJECT_ROOT%\client-sdk-rust\target" (
rmdir /s /q "%PROJECT_ROOT%\client-sdk-rust\target" 2>nul
)
echo ==^> Clean-all complete.
goto :eof