-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.cmd
More file actions
287 lines (255 loc) · 7.6 KB
/
install.cmd
File metadata and controls
287 lines (255 loc) · 7.6 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
@echo off
setlocal enabledelayedexpansion
:: WinDevices Library Installation Script
:: ======================================
:: This script builds and installs the WinDevices library.
::
:: Usage:
:: install.cmd [options]
::
:: Options:
:: --prefix PATH Installation directory (default: C:\Program Files\WinDevices)
:: --config TYPE Build configuration: Debug or Release (default: Debug)
:: --build-only Build without installing
:: --clean Clean build directory before building
:: --no-dotnet Skip .NET library build and installation
:: --help Show this help message
set "INSTALL_PREFIX="
set "BUILD_CONFIG=Debug"
set "BUILD_ONLY=0"
set "CLEAN_BUILD=0"
set "BUILD_DIR=build"
set "BUILD_DOTNET=1"
:: Parse command line arguments
:parse_args
if "%~1"=="" goto :args_done
if /i "%~1"=="--prefix" (
set "INSTALL_PREFIX=%~2"
shift
shift
goto :parse_args
)
if /i "%~1"=="--config" (
set "BUILD_CONFIG=%~2"
shift
shift
goto :parse_args
)
if /i "%~1"=="--build-only" (
set "BUILD_ONLY=1"
shift
goto :parse_args
)
if /i "%~1"=="--clean" (
set "CLEAN_BUILD=1"
shift
goto :parse_args
)
if /i "%~1"=="--no-dotnet" (
set "BUILD_DOTNET=0"
shift
goto :parse_args
)
if /i "%~1"=="--help" (
goto :show_help
)
echo Unknown option: %~1
goto :show_help
:args_done
echo.
echo ============================================
echo WinDevices Library Installation
echo ============================================
echo.
:: Check for CMake
where cmake >nul 2>&1
if errorlevel 1 (
echo ERROR: CMake not found in PATH.
echo Please install CMake from https://cmake.org/download/
exit /b 1
)
:: Check for Visual Studio
where cl >nul 2>&1
if errorlevel 1 (
echo WARNING: Visual Studio compiler not found in PATH.
echo Please run this script from a Visual Studio Developer Command Prompt.
echo.
)
:: Clean build if requested
if "%CLEAN_BUILD%"=="1" (
echo Cleaning build directory...
if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%"
)
:: Configure CMake
echo.
echo Configuring CMake...
echo Build type: %BUILD_CONFIG%
if defined INSTALL_PREFIX (
echo Install prefix: %INSTALL_PREFIX%
cmake -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=%BUILD_CONFIG% -DCMAKE_INSTALL_PREFIX="%INSTALL_PREFIX%" -DBUILD_TESTS=OFF -DBUILD_E2E_TESTS=OFF
) else (
echo Install prefix: Default ^(C:\Program Files\WinDevices^)
cmake -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=%BUILD_CONFIG% -DBUILD_TESTS=OFF -DBUILD_E2E_TESTS=OFF
)
if errorlevel 1 (
echo.
echo ERROR: CMake configuration failed.
exit /b 1
)
:: Build
echo.
echo Building %BUILD_CONFIG% configuration...
cmake --build "%BUILD_DIR%" --config %BUILD_CONFIG%
if errorlevel 1 (
echo.
echo ERROR: Build failed.
exit /b 1
)
echo.
echo Native build completed successfully.
:: Build .NET library
if "%BUILD_DOTNET%"=="1" (
echo.
echo Building .NET library...
where dotnet >nul 2>&1
if errorlevel 1 (
echo WARNING: .NET SDK not found. Skipping .NET build.
echo Install .NET SDK from https://dotnet.microsoft.com/download
set "BUILD_DOTNET=0"
goto :skip_dotnet_build
)
pushd dotnet\WinDevicesNet
if "%CLEAN_BUILD%"=="1" (
dotnet clean -c %BUILD_CONFIG%
)
dotnet build -c %BUILD_CONFIG%
if errorlevel 1 (
popd
echo ERROR: .NET library build failed!
exit /b 1
)
popd
:: Copy native DLL to .NET output for build verification
copy /Y "%BUILD_DIR%\bin\%BUILD_CONFIG%\WinDevices.dll" "dotnet\WinDevicesNet\bin\%BUILD_CONFIG%\net8.0\" >nul
echo .NET library built successfully.
)
:skip_dotnet_build
:: Install if not build-only
if "%BUILD_ONLY%"=="1" (
echo.
echo Build-only mode: Skipping installation.
echo Artifacts are available in: %BUILD_DIR%\bin\%BUILD_CONFIG%
goto :success
)
echo.
echo Installing...
echo NOTE: Installation to Program Files requires Administrator privileges.
echo.
cmake --install "%BUILD_DIR%" --config %BUILD_CONFIG%
if errorlevel 1 (
echo.
echo ERROR: Native installation failed.
echo Try running this script as Administrator.
exit /b 1
)
echo Native library installed successfully.
:: Install .NET library
if "%BUILD_DOTNET%"=="1" (
echo.
echo Installing .NET library...
:: Determine install prefix
if defined INSTALL_PREFIX (
set "DOTNET_INSTALL_DIR=!INSTALL_PREFIX!\dotnet"
) else (
set "DOTNET_INSTALL_DIR=C:\Program Files\WinDevices\dotnet"
)
:: Create dotnet directory
if not exist "!DOTNET_INSTALL_DIR!" mkdir "!DOTNET_INSTALL_DIR!"
:: Copy .NET DLL
copy /Y "dotnet\WinDevicesNet\bin\%BUILD_CONFIG%\net8.0\WinDevicesNet.dll" "!DOTNET_INSTALL_DIR!\" >nul
if errorlevel 1 (
echo ERROR: Could not copy WinDevicesNet.dll
exit /b 1
)
:: Copy XML documentation if it exists
if exist "dotnet\WinDevicesNet\bin\%BUILD_CONFIG%\net8.0\WinDevicesNet.xml" (
copy /Y "dotnet\WinDevicesNet\bin\%BUILD_CONFIG%\net8.0\WinDevicesNet.xml" "!DOTNET_INSTALL_DIR!\" >nul
)
:: Copy native DLL to .NET directory for self-contained deployment
copy /Y "%BUILD_DIR%\bin\%BUILD_CONFIG%\WinDevices.dll" "!DOTNET_INSTALL_DIR!\" >nul
if errorlevel 1 (
echo WARNING: Could not copy native DLL to .NET directory
)
echo .NET library installed to: !DOTNET_INSTALL_DIR!
)
:success
echo.
echo ============================================
echo Installation Complete!
echo ============================================
echo.
if "%BUILD_ONLY%"=="0" (
if defined INSTALL_PREFIX (
echo Installed to: %INSTALL_PREFIX%
) else (
echo Installed to: C:\Program Files\WinDevices
)
echo.
echo Installed files:
echo bin\WinDevices.dll - Runtime library
echo lib\WinDevices.lib - Import library
echo lib\cmake\WinDevices\ - CMake configuration
echo include\WinDevices\ - Header files
if "%BUILD_DOTNET%"=="1" (
echo dotnet\WinDevicesNet.dll - .NET wrapper library
echo dotnet\WinDevices.dll - Native DLL for .NET
)
echo.
echo To use in your CMake project:
echo find_package(WinDevices REQUIRED^)
echo target_link_libraries(your_target PRIVATE WinDevices::WinDevicesAPI^)
if "%BUILD_DOTNET%"=="1" (
echo.
echo To use in your .NET project, add to your .csproj:
echo ^<Reference Include="WinDevicesNet"^>
echo ^<HintPath^>C:\Program Files\WinDevices\dotnet\WinDevicesNet.dll^</HintPath^>
echo ^</Reference^>
)
)
echo.
exit /b 0
:show_help
echo.
echo WinDevices Library Installation Script
echo ======================================
echo.
echo Usage:
echo install.cmd [options]
echo.
echo Options:
echo --prefix PATH Installation directory
echo Default: C:\Program Files\WinDevices
echo --config TYPE Build configuration: Debug or Release
echo Default: Debug
echo --build-only Build without installing
echo --clean Clean build directory before building
echo --no-dotnet Skip .NET library build and installation
echo --help Show this help message
echo.
echo Examples:
echo install.cmd
echo Build and install with defaults (native + .NET)
echo.
echo install.cmd --prefix "C:\SDK\WinDevices"
echo Install to custom directory
echo.
echo install.cmd --config Release --build-only
echo Build release version without installing
echo.
echo install.cmd --clean --config Release
echo Clean rebuild and install
echo.
echo install.cmd --no-dotnet
echo Build and install native library only
echo.
exit /b 0