0032536: Configuration - extend adm/scripts with USE_DRACO option
[occt.git] / adm / scripts / android_build.bat
1 @echo OFF
2
3 rem Auxiliary script for semi-automated building of OCCT for Android platform.
4 rem android_custom.bat should be configured with paths
5 rem to CMake, 3rd-parties, Android NDK and MinGW make tool.
6
7 set "aCasSrc=%~dp0..\.."
8 set "aBuildRoot=%aCasSrc%\work"
9
10 set aNbJobs=%NUMBER_OF_PROCESSORS%
11
12 rem Paths to 3rd-party tools and libraries
13 set "anNdkPath="
14 set "aFreeType="
15 set "aRapidJson="
16 set "aDraco="
17
18 rem Build stages to perform
19 set "toCMake=1"
20 set "toClean=0"
21 set "toMake=1"
22 set "toInstall=1"
23 set "toPack=1"
24 set "isStatic=0"
25
26 rem Minimal Android platform and CPU architectures
27 set "anNdkApiLevel=21"
28 set "anNdkAbiList=armeabi-v7a x86 arm64-v8a x86_64"
29
30 rem OCCT Modules to build
31 set "BUILD_ModelingData=ON"
32 set "BUILD_ModelingAlgorithms=ON"
33 set "BUILD_Visualization=ON"
34 set "BUILD_ApplicationFramework=ON"
35 set "BUILD_DataExchange=ON"
36
37 rem Optional 3rd-party libraries to enable
38 set "USE_FREETYPE=ON"
39 set "USE_RAPIDJSON=OFF"
40 set "USE_DRACO=OFF"
41
42 rem Archive tool
43 set "THE_7Z_PARAMS=-t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on"
44 set "THE_7Z_PATH=%ProgramW6432%\7-Zip\7z.exe"
45
46 rem Configuration file
47 if exist "%~dp0android_custom.bat" call "%~dp0android_custom.bat"
48
49 set "aCompiler=gcc"
50 set "aCppLib=gnustl_shared"
51 if not exist "%anNdkPath%/sources/cxx-stl/gnu-libstdc++" (
52   if exist "%anNdkPath%/sources/cxx-stl/llvm-libc++" (
53     set "aCompiler=clang"
54     set "aCppLib=c++_shared"
55   )
56 )
57 set "aLibType=Shared"
58 if ["%isStatic%"] == ["1"] set "aLibType=Static"
59 set "aDestDir=%aBuildRoot%\android-%aCompiler%"
60 if ["%toCMake%"] == ["1"] (
61   if ["%toClean%"] == ["1"] (
62     rmdir /S /Q %aDestDir%"
63   )
64 )
65
66 set "anOcctVerSuffix="
67 set "anOcctVersion=0.0.0"
68 set "aGitBranch="
69 for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_DEVELOPMENT" "%aCasSrc%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVerSuffix=%%i" )
70 for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_COMPLETE" "%aCasSrc%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVersion=%%i" )
71 for /f %%i in ('git symbolic-ref --short HEAD') do ( set "aGitBranch=%%i" )
72
73 for %%s in (%anNdkAbiList%) do (
74   call :cmakeGenerate "%anNdkApiLevel%" "%%s"
75   if errorlevel 1 (
76     if not ["%1"] == ["-nopause"] (
77       pause
78     )
79     exit /B 1
80     goto :eof
81   )
82 )
83
84 for /F "skip=1 delims=" %%F in ('
85   wmic PATH Win32_LocalTime GET Day^,Month^,Year /FORMAT:TABLE
86 ') do (
87   for /F "tokens=1-3" %%L in ("%%F") do (
88     set DAY00=0%%L
89     set MONTH00=0%%M
90     set YEAR=%%N
91   )
92 )
93 set DAY00=%DAY00:~-2%
94 set MONTH00=%MONTH00:~-2%
95 set "aRevision=-%YEAR%-%MONTH00%-%DAY00%"
96 rem set "aRevision=-%aGitBranch%"
97 set "anArchName=occt-%anOcctVersion%%anOcctVerSuffix%%aRevision%-android"
98 set "aTarget=%aBuildRoot%\%anArchName%"
99 if ["%toPack%"] == ["1"] (
100   echo Creating archive %anArchName%.7z
101   rmdir /S /Q "%aTarget%"
102   if not exist "%aTarget%" ( mkdir "%aTarget%" )
103   if exist "%aBuildRoot%/%anArchName%.7z" del "%aBuildRoot%/%anArchName%.7z"
104   xcopy /S /Y "%aDestDir%\*" "%aTarget%\"
105
106   "%THE_7Z_PATH%" a -r %THE_7Z_PARAMS% "%aBuildRoot%/%anArchName%.7z" "%aTarget%"
107 )
108 if not ["%1"] == ["-nopause"] (
109   pause
110 )
111
112 goto :eof
113
114 :cmakeGenerate
115 set "anApi=%~1"
116 set "anAbi=%~2"
117 if ["%anApi%"] == [""] (
118   set "anApi=21"
119   if ["%anAbi%"] == ["armeabi-v7a"] ( set "anApi=16" )
120   if ["%anAbi%"] == ["x86"]         ( set "anApi=16" )
121 )
122 set "aPlatformAndCompiler=android-%anAbi%-%aCompiler%"
123 set "aWorkDir=%aBuildRoot%\%aPlatformAndCompiler%-make"
124 set "aLogFile=%aBuildRoot%\build-%aPlatformAndCompiler%.log"
125 if ["%toCMake%"] == ["1"] (
126   if ["%toClean%"] == ["1"] (
127     rmdir /S /Q %aWorkDir%"
128   )
129 )
130 if not exist "%aWorkDir%" ( mkdir "%aWorkDir%" )
131 if     exist "%aLogFile%" ( del   "%aLogFile%" )
132
133 rem include some information about OCCT into archive
134 echo ^<pre^>> "%aWorkDir%\VERSION.html"
135 git status >> "%aWorkDir%\VERSION.html"
136 git log -n 100 >> "%aWorkDir%\VERSION.html"
137 echo ^</pre^>>> "%aWorkDir%\VERSION.html"
138
139 echo Start building OCCT for %aPlatformAndCompiler%
140 echo Start building OCCT for %aPlatformAndCompiler%, API level %anApi%>> %aLogFile%
141
142 pushd "%aWorkDir%"
143
144 set "aTimeZERO=%TIME%"
145 if ["%toCMake%"] == ["1"] (
146   echo Configuring OCCT for Android %anAbi%, API level %anApi%...
147   cmake -G "MinGW Makefiles" ^
148  -D CMAKE_SYSTEM_NAME:STRING="Android" ^
149  -D CMAKE_ANDROID_NDK="%anNdkPath%" ^
150  -D CMAKE_BUILD_TYPE:STRING="Release" ^
151  -D CMAKE_ANDROID_ARCH_ABI:STRING="%anAbi%" ^
152  -D CMAKE_SYSTEM_VERSION:STRING="%anApi%" ^
153  -D CMAKE_ANDROID_STL_TYPE="%aCppLib%" ^
154  -D BUILD_LIBRARY_TYPE:STRING="%aLibType%" ^
155  -D INSTALL_DIR:PATH="%aDestDir%" ^
156  -D INSTALL_DIR_INCLUDE:STRING="inc" ^
157  -D INSTALL_DIR_LIB:STRING="libs/%anAbi%" ^
158  -D INSTALL_DIR_CMAKE:STRING="libs/%anAbi%/cmake/opencascade" ^
159  -D INSTALL_DIR_RESOURCE:STRING="src" ^
160  -D BUILD_MODULE_FoundationClasses:BOOL="ON" ^
161  -D BUILD_MODULE_ModelingData:BOOL="%BUILD_ModelingData%" ^
162  -D BUILD_MODULE_ModelingAlgorithms:BOOL="%BUILD_ModelingAlgorithms%" ^
163  -D BUILD_MODULE_Visualization:BOOL="%BUILD_Visualization%" ^
164  -D BUILD_MODULE_ApplicationFramework:BOOL="%BUILD_ApplicationFramework%" ^
165  -D BUILD_MODULE_DataExchange:BOOL="%BUILD_DataExchange%" ^
166  -D BUILD_MODULE_Draw:BOOL="OFF" ^
167  -D BUILD_DOC_Overview:BOOL="OFF" ^
168  -D USE_FREETYPE:BOOL="%USE_FREETYPE%" ^
169  -D 3RDPARTY_FREETYPE_DIR:PATH="%aFreeType%" ^
170  -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="%aFreeType%/include" ^
171  -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="%aFreeType%/include" ^
172  -D 3RDPARTY_FREETYPE_LIBRARY_DIR:PATH="%aFreeType%/libs/%anAbi%" ^
173  -D 3RDPARTY_FREETYPE_LIBRARY:FILEPATH="%aFreeType%/libs/%anAbi%/libfreetype.so" ^
174  -D USE_RAPIDJSON:BOOL="%USE_RAPIDJSON%" ^
175  -D 3RDPARTY_RAPIDJSON_DIR:PATH="%aRapidJson%" ^
176  -D 3RDPARTY_RAPIDJSON_INCLUDE_DIR:PATH="%aRapidJson%/include" ^
177  -D USE_DRACO:BOOL="%USE_DRACO%" ^
178  -D 3RDPARTY_DRACO_DIR:PATH="%aDraco%" ^
179  -D 3RDPARTY_DRACO_INCLUDE_DIR:FILEPATH="%aDraco%/include" ^
180  -D 3RDPARTY_DRACO_LIBRARY_DIR:PATH="%aDraco%/libs/%anAbi%" ^
181  -D 3RDPARTY_DRACO_LIBRARY:FILEPATH="%aDraco%/libs/%anAbi%/libfreetype.so" ^
182  "%aCasSrc%"
183
184   if errorlevel 1 (
185     popd
186     exit /B 1
187     goto :eof
188   )
189 )
190 set "aTimeGEN=%TIME%"
191 call :computeDuration %aTimeZERO% %aTimeGEN%
192 if ["%toCMake%"] == ["1"] (
193   echo Generation time: %DURATION%
194   echo Generation time: %DURATION%>> "%aLogFile%"
195 )
196
197 if ["%toClean%"] == ["1"] (
198   mingw32-make clean
199 )
200
201 if ["%toMake%"] == ["1"] (
202   echo Building...
203   mingw32-make -j %aNbJobs% 2>> "%aLogFile%"
204   if errorlevel 1 (
205     type "%aLogFile%"
206     popd
207     exit /B 1
208     goto :eof
209   )
210   type "%aLogFile%"
211 )
212 set "aTimeBUILD=%TIME%"
213 call :computeDuration %aTimeGEN% %aTimeBUILD%
214 if ["%toMake%"] == ["1"] (
215   echo Building time: %DURATION%
216   echo Building time: %DURATION%>> "%aLogFile%"
217 )
218 call :computeDuration %aTimeZERO% %aTimeBUILD%
219 if ["%toMake%"] == ["1"] (
220   echo Total building time: %DURATION%
221   echo Total building time: %DURATION%>> "%aLogFile%"
222 )
223
224 if ["%toInstall%"] == ["1"] (
225   echo Installing into %aDestDir%...
226   mingw32-make install 2>> "%aLogFile%"
227   copy /Y "%aWorkDir%\VERSION.html" "%aDestDir%\VERSION.html"
228 )
229 set "aTimeINSTALL=%TIME%"
230 call :computeDuration "%aTimeBUILD%" "%aTimeINSTALL%"
231 if ["%toInstall%"] == ["1"] (
232   echo Install time: %DURATION%
233   echo Install time: %DURATION%>> "%aLogFile%"
234 )
235
236 call :computeDuration "%aTimeZERO%" "%aTimeINSTALL%"
237 echo Total time: %DURATION%
238 echo Total time: %DURATION%>> "%aLogFile%"
239
240 popd
241 goto :eof
242
243 :computeDuration
244 set "aTimeFrom=%~1"
245 set "aTimeEnd=%~2"
246 rem handle time before 10AM (win10 - remove empty space at the beginning)
247 if "%aTimeFrom:~0,1%"==" " set "aTimeFrom=%aTimeFrom:~1%"
248 if  "%aTimeEnd:~0,1%"==" " set  "aTimeEnd=%aTimeEnd:~1%"
249 rem handle time before 10AM (win7 - add 0 at the beginning)
250 if "%aTimeFrom:~1,1%"==":" set "aTimeFrom=0%aTimeFrom%"
251 if  "%aTimeEnd:~1,1%"==":" set  "aTimeEnd=0%aTimeEnd%"
252 rem convert hours:minutes:seconds:ms into duration
253 set /A aTimeFrom=(1%aTimeFrom:~0,2%-100)*360000 + (1%aTimeFrom:~3,2%-100)*6000 + (1%aTimeFrom:~6,2%-100)*100 + (1%aTimeFrom:~9,2%-100)
254 set /A  aTimeEnd= (1%aTimeEnd:~0,2%-100)*360000 +  (1%aTimeEnd:~3,2%-100)*6000 +  (1%aTimeEnd:~6,2%-100)*100 +  (1%aTimeEnd:~9,2%-100)
255 set /A aDurTotalSec=%aTimeEnd%-%aTimeFrom%
256 if %aTimeEnd% LSS %aTimeFrom% set set /A aDurTotalSec=%aTimeFrom%-%aTimeEnd%
257 set /A aDurHH=%aDurTotalSec% / 360000
258 set /A aDurMM=(%aDurTotalSec% - %aDurHH%*360000) / 6000
259 set /A aDurSS=(%aDurTotalSec% - %aDurHH%*360000 - %aDurMM%*6000) / 100
260 if %aDurHH% LSS 10 set aDurHH=0%aDurHH%
261 if %aDurMM% LSS 10 set aDurMM=0%aDurMM%
262 if %aDurSS% LSS 10 set aDurSS=0%aDurSS%
263
264 set "DURATION=%aDurHH%:%aDurMM%:%aDurSS%"
265 goto :eof