[IOT-2334][IOT-2335] Fixed presence sample app crash issue
[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% RD_MODE=%RD_MODE% ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP% MULTIPLE_OWNER=%MULTIPLE_OWNER% 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
203   REM First: just build, but don't run tests.
204   echo.scons.bat -j %THREAD_COUNT% VERBOSE=1 TEST=0 %BUILD_OPTIONS%
205   call scons.bat -j %THREAD_COUNT% VERBOSE=1 TEST=0 %BUILD_OPTIONS%
206   if ERRORLEVEL 1 (
207     echo SCons failed - exiting run.bat with code 3
208     exit /B 3
209   )
210
211   REM Second: run tests if needed, using a single SCons thread.
212   if "!TEST!"=="1" (
213     echo.scons.bat -j 1 VERBOSE=1 TEST=1 %BUILD_OPTIONS%
214     call scons.bat -j 1 VERBOSE=1 TEST=1 %BUILD_OPTIONS%
215     if ERRORLEVEL 1 (
216         echo SCons failed - exiting run.bat with code 4
217         exit /B 4
218     )
219   )
220 ) else if "!RUN_ARG!"=="clean" (
221   echo Cleaning IoTivity build
222   del /S *.ilk
223   echo.scons.bat -j 1 VERBOSE=1 TEST=%TEST% %BUILD_OPTIONS% -c
224   call scons.bat -j 1 VERBOSE=1 TEST=%TEST% %BUILD_OPTIONS% -c
225   if ERRORLEVEL 1 (
226     echo SCons failed - exiting run.bat with code 2
227     exit /B 2
228   )
229 ) else if "!RUN_ARG!"=="cleangtest" (
230   rd /s /q extlibs\gtest\googletest-release-1.7.0
231   del extlibs\gtest\release-1.7.0.zip
232 ) else (
233   echo.%0 - Script requires a valid argument!
234   echo Exiting run.bat with code 1
235   exit /B 1
236 )
237
238 cd %IOTIVITY_DIR%
239
240 echo Done!
241
242 goto EOF
243
244 :USAGE
245 echo %0 - Helper to build/test iotivity.  Requires an argument.
246 echo Installation: Drop this into your iotivity root directory to use it.
247 echo.
248 echo. Default build settings are: debug binaries run unittests and no logging
249 echo.
250 echo. Default build parameters can be overridden using the following arguments
251 echo.
252 REM At a quick look, the "Build either amd64 or x86 architecture binaries" message
253 REM below seems out of alignment with the other messages underneath it. But, "^|"
254 REM gets echoed as a single character, so the messages are actually aligned correctly
255 REM in the output of "run.bat".
256 echo   -arch [x86 ^| amd64]          - Build either amd64 or x86 architecture binaries
257 echo.
258 echo   -noTest                      - Don't run the unittests after building the binaries
259 echo.
260 echo   -logging                     - Enable logging while building the binaries
261 echo.
262 echo   -debugger                    - Debug the requested application
263 echo.
264 echo   -release                     - Build release binaries
265 echo.
266 echo   -threads [NUMBER_OF_THREADS] - Build in parallel using [NUMBER_OF_THREADS] threads. Default: %NUMBER_OF_PROCESSORS%.
267 echo.
268 echo   -noTCP                       - Build with the TCP adapter disabled
269 echo.
270 echo   -noSecurity                  - Remove security support (results in code that cannot be certified by OCF)
271 echo.
272 echo   -noMOT                       - Remove Multiple Ownership Transfer support.
273 echo.
274 echo   -automaticUpdate             - Automatically update libcoap to required version.
275 echo.
276 echo   -uwp                         - Build for the Universal Windows Platform (UWP).
277 echo.
278 echo.
279 echo. Usage examples:
280 echo.
281 echo   Launch SimpleClient with debugger:
282 echo      %0 client -debugger
283 echo.
284 echo   Launch SimpleServer:
285 echo      %0 server
286 echo.
287 echo   Launch WinUIClient built in msys:
288 echo      %0 msys winuiclient
289 echo.
290 echo   Build amd64 debug binaries and run unit tests:
291 echo      %0 build
292 echo.
293 echo   Build amd64 release binaries w/o running tests:
294 echo      %0 build -arch amd64 -noTest -release
295 echo.
296 echo   Build x86 debug binaries and run unit tests:
297 echo      %0 build -arch x86
298 echo.
299 echo   Build amd64 release binaries with logging enabled:
300 echo      %0 build -arch amd64 -release -logging
301 echo.
302 echo   Build using only one thread:
303 echo      %0 build -threads 1
304 echo.
305 echo   Build with TCP adapter disabled and run unit tests:
306 echo      %0 build -noTCP
307 echo.
308 echo   Build without security support and run unit tests:
309 echo      %0 build -noSecurity
310 echo.
311 echo   Build without Multiple Ownership Transfer support and run unit tests:
312 echo      %0 build -noMOT
313 echo.
314 echo   Run all tests:
315 echo      %0 test
316 echo.
317 echo   Clean:
318 echo      %0 clean
319
320 :EOF