IOT-1749: Enabling multi-threaded builds in Windows.
[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 "%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 "%TARGET_ARCH%" == "" (
21   set TARGET_ARCH=amd64
22
23
24 if "%TEST%" == "" (
25   set TEST=1
26 )
27
28 if "%LOGGING%" == "" (
29   set LOGGING=0
30 )
31
32 if "%RELEASE%" == "" (
33   set RELEASE=0
34 )
35
36 set THREAD_COUNT=%NUMBER_OF_PROCESSORS%
37 set SECURED=1
38 set ROUTING=EP
39 set WITH_TCP=1
40 set WITH_UPSTREAM_LIBCOAP=1
41 set BINDIR=debug
42 set MULTIPLE_OWNER=1
43
44 set RUN_ARG=%1
45 SHIFT
46
47 set DEBUG=
48
49 :processArgs
50 IF NOT "%1"=="" (
51   IF "%1"=="-arch" (
52     SET TARGET_ARCH=%2
53     SHIFT
54   )
55   IF "%1"=="-threads" (
56     SET THREAD_COUNT=%2
57     SHIFT
58   )
59   IF "%1"=="-noTest" (
60     SET TEST=0
61   )
62   IF "%1"=="-logging" (
63     SET LOGGING=1
64   )    
65   IF "%1"=="-debugger" (
66     set DEBUG="%ProgramFiles(x86)%\Windows Kits\10\Debuggers\x64\cdb.exe" -2 -c "g" 
67   )
68   IF "%1"=="-release" (
69     SET RELEASE=1
70   )
71
72   SHIFT
73   GOTO :processArgs
74 )
75
76 IF %RELEASE% == 1 (
77   set BINDIR=release
78 )
79
80 REM We need to append the "PATH" so the octbstack.dll can be found by executables
81 IF "%BUILD_MSYS%" == "" (
82   set BUILD_DIR=out\windows\%TARGET_ARCH%\%BINDIR%
83   set PATH=!PATH!;!IOTIVITY_DIR!!BUILD_DIR!;
84 ) ELSE (
85   set BUILD_DIR=out\msys_nt\x86_64\%BINDIR%
86   set PATH=!PATH!;!BUILD_DIR!;C:\msys64\mingw64\bin
87 )
88
89 set BUILD_OPTIONS= TARGET_OS=%TARGET_OS% TARGET_ARCH=%TARGET_ARCH% RELEASE=%RELEASE% WITH_RA=0 TARGET_TRANSPORT=IP SECURED=%SECURED% WITH_TCP=%WITH_TCP% BUILD_SAMPLE=ON LOGGING=%LOGGING% TEST=%TEST% RD_MODE=CLIENT ROUTING=%ROUTING% WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP% MULTIPLE_OWNER=%MULTIPLE_OWNER% -j %THREAD_COUNT%
90
91 REM Use MSVC_VERSION=12.0 for VS2013, or MSVC_VERSION=14.0 for VS2015.
92 REM If MSVC_VERSION has not been defined here, SCons chooses automatically a VS version.
93 IF NOT "%MSVC_VERSION%" == "" (
94   set BUILD_OPTIONS=%BUILD_OPTIONS% MSVC_VERSION=%MSVC_VERSION%
95 )
96
97 REM *** BUILD OPTIONS ***
98
99 if "!RUN_ARG!"=="server" (
100   cd %BUILD_DIR%\resource\examples
101   %DEBUG% simpleserver.exe
102 ) else if "!RUN_ARG!"=="client" (
103   cd %BUILD_DIR%\resource\examples
104   %DEBUG% simpleclient.exe
105 ) else if "!RUN_ARG!"=="serverhq" (
106   cd %BUILD_DIR%\resource\examples
107   %DEBUG% simpleserverHQ.exe
108 ) else if "!RUN_ARG!"=="clienthq" (
109   cd %BUILD_DIR%\resource\examples
110   %DEBUG% simpleclientHQ.exe
111 ) else if "!RUN_ARG!"=="mediaclient" (
112   cd %BUILD_DIR%\resource\examples
113   %DEBUG% mediaclient.exe
114 ) else if "!RUN_ARG!"=="mediaserver" (
115   cd %BUILD_DIR%\resource\examples
116   %DEBUG% mediaserver.exe
117 ) else if "!RUN_ARG!"=="winuiclient" (
118   cd %BUILD_DIR%\resource\examples
119   %DEBUG% winuiclient.exe
120 ) else if "!RUN_ARG!"=="occlient" (
121   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
122   %DEBUG% occlientbasicops.exe -u 0 -t 3 -c 1
123 ) else if "!RUN_ARG!"=="ocserver" (
124   cd %BUILD_DIR%\resource\csdk\stack\samples\linux\SimpleClientServer
125   %DEBUG% ocserverbasicops.exe
126 ) else if "!RUN_ARG!"=="provclient" (
127   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
128   %DEBUG% provisioningclient.exe
129 ) else if "!RUN_ARG!"=="justworks" (
130   cd %BUILD_DIR%\resource\csdk\security\provisioning\sample
131   %DEBUG% sampleserver_justworks.exe
132 ) else if "!RUN_ARG!"=="test" (
133   %DEBUG% %BUILD_DIR%\resource\csdk\connectivity\test\catests.exe
134   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\stacktests.exe
135   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\cbortests.exe
136   %DEBUG% %BUILD_DIR%\resource\csdk\security\unittest\unittest.exe
137   %DEBUG% %BUILD_DIR%\resource\csdk\security\provisioning\unittest\unittest.exe
138   %DEBUG% %BUILD_DIR%\resource\c_common\ocrandom\test\randomtests.exe
139   %DEBUG% %BUILD_DIR%\resource\c_common\oic_malloc\test\malloctests.exe
140   %DEBUG% %BUILD_DIR%\resource\c_common\oic_string\test\stringtests.exe
141   %DEBUG% %BUILD_DIR%\resource\c_common\oic_time\test\timetests.exe
142   %DEBUG% %BUILD_DIR%\resource\unittests\unittests.exe
143 ) else if "!RUN_ARG!"=="build" (
144   echo Starting IoTivity build with these options:
145   echo   TARGET_OS=%TARGET_OS%
146   echo   TARGET_ARCH=%TARGET_ARCH%
147   echo   SECURED=%SECURED%
148   echo   RELEASE=%RELEASE%
149   echo   TEST=%TEST%
150   echo   LOGGING=%LOGGING%
151   echo   ROUTING=%ROUTING%
152   echo   WITH_TCP=%WITH_TCP%
153   echo   WITH_UPSTREAM_LIBCOAP=%WITH_UPSTREAM_LIBCOAP%
154   echo   MULTIPLE_OWNER=%MULTIPLE_OWNER%
155   echo   MSVC_VERSION=%MSVC_VERSION%
156   echo   THREAD_COUNT=%THREAD_COUNT%
157   echo.scons VERBOSE=1 %BUILD_OPTIONS%
158   scons VERBOSE=1 %BUILD_OPTIONS%
159 ) else if "!RUN_ARG!"=="clean" (
160   scons VERBOSE=1 %BUILD_OPTIONS% -c clean
161   rd /s /q out
162   del .sconsign.dblite
163   del extlibs\gtest\googletest*.lib
164   del extlibs\gtest\googletest-release-1.7.0\src\gtest*.obj
165   erase /s *.obj
166   erase resource\c_common\iotivity_config.h
167   erase extlibs\libcoap\coap.lib
168   erase extlibs\libcoap\libcoap\include\coap\coap_config.h
169   erase extlibs\mbedtls\mbed*.lib
170 ) else if "!RUN_ARG!"=="cleangtest" (
171   rd /s /q extlibs\gtest\googletest-release-1.7.0
172   del extlibs\gtest\release-1.7.0.zip
173 ) else (
174     echo.%0 - Script requires a valid argument!
175     goto :EOF
176 )
177
178 cd %IOTIVITY_DIR%
179
180 echo Done!
181
182 goto EOF
183
184 :USAGE
185 echo %0 - Helper to build/test iotivity.  Requires an argument.
186 echo Installation: Drop this into your iotivity root directory to use it.
187 echo.
188 echo. Default build settings are: debug binaries run unittests and no logging
189 echo.
190 echo. Default build parameters can be overridden using the following arguments
191 echo. 
192 echo   -arch [x86 ^| amd64]         - Build either amd64 or x86 architecture binaries
193 echo.
194 echo   -noTest                      - Don't run the unittests after building the binaries
195 echo.
196 echo   -logging                     - Enable logging while building the binaries
197 echo.
198 echo   -debugger                    - Debug the requested application
199 echo.
200 echo   -release                     - Build release binaries
201 echo.
202 echo   -threads [NUMBER_OF_THREADS] - Build in parallel using [NUMBER_OF_THREADS] threads. Default: %NUMBER_OF_PROCESSORS%.
203 echo.
204 echo. Usage examples:
205 echo   Launch SimpleClient with debugger:
206 echo      %0 client -debugger
207 echo.
208 echo   Launch SimpleServer:
209 echo      %0 server
210 echo.
211 echo   Launch WinUIClient built in msys:
212 echo      %0 msys winuiclient
213 echo.
214 echo   Build amd64 debug binaries and run unit tests:
215 echo      %0 build
216 echo.
217 echo   Build amd64 release binaries w/o running tests:
218 echo      %0 build -arch amd64 -noTest -release
219 echo.
220 echo   Build x86 debug binaries and run unit tests:
221 echo      %0 build -arch x86
222 echo.
223 echo   Build amd64 release binaries with logging enabled:
224 echo      %0 build -arch amd64 -release -logging
225 echo.
226 echo   Build using only one thread:
227 echo      %0 build -threads 1
228 echo.
229 echo   Run all tests:
230 echo      %0 test
231 echo.
232 echo   Clean:
233 echo      %0 clean
234
235 :EOF