[IOT-2259] Windows: Handle Persistent Storage for UWP Apps
[platform/upstream/iotivity.git] / run.bat
1 @echo off
2 REM Helper script to build and run IoTivity on Windows
3 SETLOCAL ENABLEDELAYEDEXPANSION
4
5 if [%1]==[] goto USAGE
6
7 set IOTIVITY_DIR=%~dp0
8 set HOME=%USERPROFILE%
9
10 IF /I "%1" == "msys" (
11   set BUILD_MSYS="YES"
12   SHIFT
13 ) ELSE (
14   set BUILD_MSYS=
15 )
16
17 REM *** Default BUILD OPTIONS ***
18 set TARGET_OS=windows
19
20 if "%JENKINS_HOME%" == "" (
21   set AUTOMATIC_UPDATE=0
22 ) else (
23   set AUTOMATIC_UPDATE=1
24 )
25
26 if "%TARGET_ARCH%" == "" (
27   set TARGET_ARCH=amd64
28 )
29
30 if "%TEST%" == "" (
31   set TEST=1
32 )
33
34 if "%LOGGING%" == "" (
35   set LOGGING=0
36 )
37
38 if "%RELEASE%" == "" (
39   set RELEASE=0
40 )
41
42 if "%WITH_TCP%" == "" (
43   set WITH_TCP=1
44 )
45
46 if "%SECURED%" == "" (
47   set SECURED=1
48 )
49
50 if "%MULTIPLE_OWNER%" == "" (
51   set MULTIPLE_OWNER=1
52 )
53
54 if "%UWP_APP%" == "" (
55   REM Set it to build Win32 app by default
56   set UWP_APP=0
57 )
58
59 set THREAD_COUNT=%NUMBER_OF_PROCESSORS%
60
61 set ROUTING=EP
62 set WITH_UPSTREAM_LIBCOAP=1
63 set BINDIR=debug
64 set RD_MODE=CLIENT,SERVER
65
66 set RUN_ARG=%1
67 SHIFT
68
69 set DEBUG=
70
71 :processArgs
72 IF NOT "%1"=="" (
73   IF /I "%1"=="-arch" (
74     SET TARGET_ARCH=%2
75     SHIFT
76   )
77   IF /I "%1"=="-threads" (
78     SET THREAD_COUNT=%2
79     SHIFT
80   )
81   IF /I "%1"=="-noTest" (
82     SET TEST=0
83   )
84   IF /I "%1"=="-logging" (
85     SET LOGGING=1
86   )
87   IF /I "%1"=="-debugger" (
88     set DEBUG="%ProgramFiles(x86)%\Windows Kits\10\Debuggers\x64\cdb.exe" -2 -c "g"
89   )
90   IF /I "%1"=="-release" (
91     SET RELEASE=1
92   )
93   IF /I "%1"=="-noTCP" (
94     SET WITH_TCP=0
95   )
96   IF /I "%1"=="-noSecurity" (
97     set SECURED=0
98   )
99   IF /I "%1"=="-noMOT" (
100     set MULTIPLE_OWNER=0
101   )
102   IF /I "%1"=="-automaticUpdate" (
103     set AUTOMATIC_UPDATE=1
104   )
105   IF /I "%1"=="-uwp" (
106     set UWP_APP=1
107   )
108
109   SHIFT
110   GOTO :processArgs
111 )
112
113 IF %RELEASE% == 1 (
114   set BINDIR=release
115 )
116
117 set BUILD_VARIANT=win32
118 if "%UWP_APP%" == "1" (
119   set BUILD_VARIANT=uwp
120 )
121
122 REM We need to append the "PATH" so the octbstack.dll can be found by executables
123 IF "%BUILD_MSYS%" == "" (
124   set BUILD_DIR=out\windows\%BUILD_VARIANT%\%TARGET_ARCH%\%BINDIR%
125   set PATH=!PATH!;!IOTIVITY_DIR!!BUILD_DIR!;
126 ) ELSE (
127   set BUILD_DIR=out\msys_nt\x86_64\%BINDIR%
128   set PATH=!PATH!;!BUILD_DIR!;C:\msys64\mingw64\bin
129 )
130
131 set BUILD_OPTIONS= TARGET_OS=%TARGET_OS% TARGET_ARCH=%TARGET_ARCH% UWP_APP=%UWP_APP% RELEASE=%RELEASE% WITH_RA=0 TARGET_TRANSPORT=IP SECURED=%SECURED% WITH_TCP=%WITH_TCP% BUILD_SAMPLE=ON LOGGING=%LOGGING% TEST=%TEST% RD_MODE=%RD_MODE% ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP% MULTIPLE_OWNER=%MULTIPLE_OWNER% -j %THREAD_COUNT% AUTOMATIC_UPDATE=%AUTOMATIC_UPDATE%
132
133 REM Use MSVC_VERSION=12.0 for VS2013, or MSVC_VERSION=14.0 for VS2015.
134 REM If MSVC_VERSION has not been defined here, SCons chooses automatically a VS version.
135 IF NOT "%MSVC_VERSION%" == "" (
136   set BUILD_OPTIONS=%BUILD_OPTIONS% MSVC_VERSION=%MSVC_VERSION%
137 )
138
139 REM *** BUILD OPTIONS ***
140
141 if "!RUN_ARG!"=="server" (
142   cd %BUILD_DIR%\resource\examples
143   %DEBUG% simpleserver.exe
144 ) else if "!RUN_ARG!"=="client" (
145   cd %BUILD_DIR%\resource\examples
146   %DEBUG% simpleclient.exe
147 ) else if "!RUN_ARG!"=="serverhq" (
148   cd %BUILD_DIR%\resource\examples
149   %DEBUG% simpleserverHQ.exe
150 ) else if "!RUN_ARG!"=="clienthq" (
151   cd %BUILD_DIR%\resource\examples
152   %DEBUG% simpleclientHQ.exe
153 ) else if "!RUN_ARG!"=="mediaclient" (
154   cd %BUILD_DIR%\resource\examples
155   %DEBUG% mediaclient.exe
156 ) else if "!RUN_ARG!"=="mediaserver" (
157   cd %BUILD_DIR%\resource\examples
158   %DEBUG% mediaserver.exe
159 ) else if "!RUN_ARG!"=="winuiclient" (
160   cd %BUILD_DIR%\resource\examples
161   %DEBUG% winuiclient.exe
162 ) else if "!RUN_ARG!"=="occlient" (
163   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
164   %DEBUG% occlientbasicops.exe -u 0 -t 3 -c 1
165 ) else if "!RUN_ARG!"=="ocserver" (
166   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
167   %DEBUG% ocserverbasicops.exe
168 ) else if "!RUN_ARG!"=="provclient" (
169   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
170   %DEBUG% provisioningclient.exe
171 ) else if "!RUN_ARG!"=="justworks" (
172   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
173   %DEBUG% sampleserver_justworks.exe
174 ) else if "!RUN_ARG!"=="test" (
175   %DEBUG% %BUILD_DIR%\resource\csdk\connectivity\test\catests.exe
176   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\stacktests.exe
177   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\cbortests.exe
178   %DEBUG% %BUILD_DIR%\resource\csdk\security\unittest\unittest.exe
179   %DEBUG% %BUILD_DIR%\resource\csdk\security\provisioning\unittest\unittest.exe
180   %DEBUG% %BUILD_DIR%\resource\c_common\ocrandom\test\randomtests.exe
181   %DEBUG% %BUILD_DIR%\resource\c_common\oic_malloc\test\malloctests.exe
182   %DEBUG% %BUILD_DIR%\resource\c_common\oic_string\test\stringtests.exe
183   %DEBUG% %BUILD_DIR%\resource\c_common\oic_time\test\timetests.exe
184   %DEBUG% %BUILD_DIR%\resource\unittests\unittests.exe
185 ) else if "!RUN_ARG!"=="build" (
186   echo Starting IoTivity build with these options:
187   echo   TARGET_OS=%TARGET_OS%
188   echo   TARGET_ARCH=%TARGET_ARCH%
189   echo   UWP_APP=%UWP_APP%
190   echo   BUILD_DIR=%BUILD_DIR%
191   echo   SECURED=%SECURED%
192   echo   RELEASE=%RELEASE%
193   echo   TEST=%TEST%
194   echo   LOGGING=%LOGGING%
195   echo   ROUTING=%ROUTING%
196   echo   WITH_TCP=%WITH_TCP%
197   echo   WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP%
198   echo   MULTIPLE_OWNER=%MULTIPLE_OWNER%
199   echo   MSVC_VERSION=%MSVC_VERSION%
200   echo   THREAD_COUNT=%THREAD_COUNT%
201   echo   AUTOMATIC_UPDATE=%AUTOMATIC_UPDATE%
202   echo.scons VERBOSE=1 %BUILD_OPTIONS%
203   call scons.bat VERBOSE=1 %BUILD_OPTIONS%
204   if ERRORLEVEL 1 (
205     echo SCons failed - exiting run.bat with code 3
206     exit /B 3
207   )
208 ) else if "!RUN_ARG!"=="clean" (
209   echo Cleaning IoTivity build
210   del /S *.ilk
211   call scons.bat VERBOSE=1 %BUILD_OPTIONS% -c
212   if ERRORLEVEL 1 (
213     echo SCons failed - exiting run.bat with code 2
214     exit /B 2
215   )
216 ) else if "!RUN_ARG!"=="cleangtest" (
217   rd /s /q extlibs\gtest\googletest-release-1.7.0
218   del extlibs\gtest\release-1.7.0.zip
219 ) else (
220   echo.%0 - Script requires a valid argument!
221   echo Exiting run.bat with code 1
222   exit /B 1
223 )
224
225 cd %IOTIVITY_DIR%
226
227 echo Done!
228
229 goto EOF
230
231 :USAGE
232 echo %0 - Helper to build/test iotivity.  Requires an argument.
233 echo Installation: Drop this into your iotivity root directory to use it.
234 echo.
235 echo. Default build settings are: debug binaries run unittests and no logging
236 echo.
237 echo. Default build parameters can be overridden using the following arguments
238 echo.
239 REM At a quick look, the "Build either amd64 or x86 architecture binaries" message
240 REM below seems out of alignment with the other messages underneath it. But, "^|"
241 REM gets echoed as a single character, so the messages are actually aligned correctly
242 REM in the output of "run.bat".
243 echo   -arch [x86 ^| amd64]          - Build either amd64 or x86 architecture binaries
244 echo.
245 echo   -noTest                      - Don't run the unittests after building the binaries
246 echo.
247 echo   -logging                     - Enable logging while building the binaries
248 echo.
249 echo   -debugger                    - Debug the requested application
250 echo.
251 echo   -release                     - Build release binaries
252 echo.
253 echo   -threads [NUMBER_OF_THREADS] - Build in parallel using [NUMBER_OF_THREADS] threads. Default: %NUMBER_OF_PROCESSORS%.
254 echo.
255 echo   -noTCP                       - Build with the TCP adapter disabled
256 echo.
257 echo   -noSecurity                  - Remove security support (results in code that cannot be certified by OCF)
258 echo.
259 echo   -noMOT                       - Remove Multiple Ownership Transfer support.
260 echo.
261 echo   -automaticUpdate             - Automatically update libcoap to required version.
262 echo.
263 echo   -uwp                         - Build for the Universal Windows Platform (UWP).
264 echo.
265 echo.
266 echo. Usage examples:
267 echo.
268 echo   Launch SimpleClient with debugger:
269 echo      %0 client -debugger
270 echo.
271 echo   Launch SimpleServer:
272 echo      %0 server
273 echo.
274 echo   Launch WinUIClient built in msys:
275 echo      %0 msys winuiclient
276 echo.
277 echo   Build amd64 debug binaries and run unit tests:
278 echo      %0 build
279 echo.
280 echo   Build amd64 release binaries w/o running tests:
281 echo      %0 build -arch amd64 -noTest -release
282 echo.
283 echo   Build x86 debug binaries and run unit tests:
284 echo      %0 build -arch x86
285 echo.
286 echo   Build amd64 release binaries with logging enabled:
287 echo      %0 build -arch amd64 -release -logging
288 echo.
289 echo   Build using only one thread:
290 echo      %0 build -threads 1
291 echo.
292 echo   Build with TCP adapter disabled and run unit tests:
293 echo      %0 build -noTCP
294 echo.
295 echo   Build without security support and run unit tests:
296 echo      %0 build -noSecurity
297 echo.
298 echo   Build without Multiple Ownership Transfer support and run unit tests:
299 echo      %0 build -noMOT
300 echo.
301 echo   Run all tests:
302 echo      %0 test
303 echo.
304 echo   Clean:
305 echo      %0 clean
306
307 :EOF