0032536: Configuration - extend adm/scripts with USE_DRACO option
[occt.git] / adm / scripts / android_build.bat
CommitLineData
eca6e7c5 1@echo OFF
2
3rem Auxiliary script for semi-automated building of OCCT for Android platform.
4rem android_custom.bat should be configured with paths
5rem to CMake, 3rd-parties, Android NDK and MinGW make tool.
6
7set "aCasSrc=%~dp0..\.."
8set "aBuildRoot=%aCasSrc%\work"
9
10set aNbJobs=%NUMBER_OF_PROCESSORS%
11
12rem Paths to 3rd-party tools and libraries
13set "anNdkPath="
14set "aFreeType="
15set "aRapidJson="
91428b46 16set "aDraco="
eca6e7c5 17
18rem Build stages to perform
19set "toCMake=1"
20set "toClean=0"
21set "toMake=1"
22set "toInstall=1"
23set "toPack=1"
24set "isStatic=0"
25
26rem Minimal Android platform and CPU architectures
27set "anNdkApiLevel=21"
28set "anNdkAbiList=armeabi-v7a x86 arm64-v8a x86_64"
29
30rem OCCT Modules to build
31set "BUILD_ModelingData=ON"
32set "BUILD_ModelingAlgorithms=ON"
33set "BUILD_Visualization=ON"
34set "BUILD_ApplicationFramework=ON"
35set "BUILD_DataExchange=ON"
36
37rem Optional 3rd-party libraries to enable
91428b46 38set "USE_FREETYPE=ON"
be8c9f2b 39set "USE_RAPIDJSON=OFF"
91428b46 40set "USE_DRACO=OFF"
eca6e7c5 41
42rem Archive tool
43set "THE_7Z_PARAMS=-t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on"
44set "THE_7Z_PATH=%ProgramW6432%\7-Zip\7z.exe"
45
46rem Configuration file
47if exist "%~dp0android_custom.bat" call "%~dp0android_custom.bat"
48
49set "aCompiler=gcc"
50set "aCppLib=gnustl_shared"
51if 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)
57set "aLibType=Shared"
58if ["%isStatic%"] == ["1"] set "aLibType=Static"
59set "aDestDir=%aBuildRoot%\android-%aCompiler%"
be8c9f2b 60if ["%toCMake%"] == ["1"] (
61 if ["%toClean%"] == ["1"] (
62 rmdir /S /Q %aDestDir%"
63 )
64)
eca6e7c5 65
66set "anOcctVerSuffix="
67set "anOcctVersion=0.0.0"
68set "aGitBranch="
69for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_DEVELOPMENT" "%aCasSrc%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVerSuffix=%%i" )
70for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_COMPLETE" "%aCasSrc%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVersion=%%i" )
71for /f %%i in ('git symbolic-ref --short HEAD') do ( set "aGitBranch=%%i" )
72
73for %%s in (%anNdkAbiList%) do (
74 call :cmakeGenerate "%anNdkApiLevel%" "%%s"
be8c9f2b 75 if errorlevel 1 (
76 if not ["%1"] == ["-nopause"] (
77 pause
78 )
79 exit /B 1
80 goto :eof
81 )
eca6e7c5 82)
83
84for /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)
93set DAY00=%DAY00:~-2%
94set MONTH00=%MONTH00:~-2%
95set "aRevision=-%YEAR%-%MONTH00%-%DAY00%"
96rem set "aRevision=-%aGitBranch%"
97set "anArchName=occt-%anOcctVersion%%anOcctVerSuffix%%aRevision%-android"
98set "aTarget=%aBuildRoot%\%anArchName%"
99if ["%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)
108if not ["%1"] == ["-nopause"] (
109 pause
110)
111
112goto :eof
113
114:cmakeGenerate
115set "anApi=%~1"
116set "anAbi=%~2"
be8c9f2b 117if ["%anApi%"] == [""] (
118 set "anApi=21"
119 if ["%anAbi%"] == ["armeabi-v7a"] ( set "anApi=16" )
120 if ["%anAbi%"] == ["x86"] ( set "anApi=16" )
121)
eca6e7c5 122set "aPlatformAndCompiler=android-%anAbi%-%aCompiler%"
123set "aWorkDir=%aBuildRoot%\%aPlatformAndCompiler%-make"
124set "aLogFile=%aBuildRoot%\build-%aPlatformAndCompiler%.log"
be8c9f2b 125if ["%toCMake%"] == ["1"] (
126 if ["%toClean%"] == ["1"] (
127 rmdir /S /Q %aWorkDir%"
128 )
129)
eca6e7c5 130if not exist "%aWorkDir%" ( mkdir "%aWorkDir%" )
131if exist "%aLogFile%" ( del "%aLogFile%" )
132
133rem include some information about OCCT into archive
134echo ^<pre^>> "%aWorkDir%\VERSION.html"
135git status >> "%aWorkDir%\VERSION.html"
136git log -n 100 >> "%aWorkDir%\VERSION.html"
137echo ^</pre^>>> "%aWorkDir%\VERSION.html"
138
139echo Start building OCCT for %aPlatformAndCompiler%
be8c9f2b 140echo Start building OCCT for %aPlatformAndCompiler%, API level %anApi%>> %aLogFile%
eca6e7c5 141
142pushd "%aWorkDir%"
143
144set "aTimeZERO=%TIME%"
145if ["%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" ^
91428b46 168 -D USE_FREETYPE:BOOL="%USE_FREETYPE%" ^
eca6e7c5 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" ^
91428b46 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" ^
eca6e7c5 182 "%aCasSrc%"
183
184 if errorlevel 1 (
185 popd
186 exit /B 1
187 goto :eof
188 )
189)
be8c9f2b 190set "aTimeGEN=%TIME%"
eca6e7c5 191call :computeDuration %aTimeZERO% %aTimeGEN%
192if ["%toCMake%"] == ["1"] (
193 echo Generation time: %DURATION%
194 echo Generation time: %DURATION%>> "%aLogFile%"
195)
196
197if ["%toClean%"] == ["1"] (
198 mingw32-make clean
199)
200
201if ["%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)
be8c9f2b 212set "aTimeBUILD=%TIME%"
eca6e7c5 213call :computeDuration %aTimeGEN% %aTimeBUILD%
214if ["%toMake%"] == ["1"] (
215 echo Building time: %DURATION%
216 echo Building time: %DURATION%>> "%aLogFile%"
217)
218call :computeDuration %aTimeZERO% %aTimeBUILD%
219if ["%toMake%"] == ["1"] (
220 echo Total building time: %DURATION%
221 echo Total building time: %DURATION%>> "%aLogFile%"
222)
223
224if ["%toInstall%"] == ["1"] (
225 echo Installing into %aDestDir%...
226 mingw32-make install 2>> "%aLogFile%"
227 copy /Y "%aWorkDir%\VERSION.html" "%aDestDir%\VERSION.html"
228)
229set "aTimeINSTALL=%TIME%"
230call :computeDuration "%aTimeBUILD%" "%aTimeINSTALL%"
231if ["%toInstall%"] == ["1"] (
232 echo Install time: %DURATION%
233 echo Install time: %DURATION%>> "%aLogFile%"
234)
235
236call :computeDuration "%aTimeZERO%" "%aTimeINSTALL%"
237echo Total time: %DURATION%
238echo Total time: %DURATION%>> "%aLogFile%"
239
240popd
241goto :eof
242
243:computeDuration
244set "aTimeFrom=%~1"
245set "aTimeEnd=%~2"
246rem handle time before 10AM (win10 - remove empty space at the beginning)
247if "%aTimeFrom:~0,1%"==" " set "aTimeFrom=%aTimeFrom:~1%"
248if "%aTimeEnd:~0,1%"==" " set "aTimeEnd=%aTimeEnd:~1%"
249rem handle time before 10AM (win7 - add 0 at the beginning)
250if "%aTimeFrom:~1,1%"==":" set "aTimeFrom=0%aTimeFrom%"
251if "%aTimeEnd:~1,1%"==":" set "aTimeEnd=0%aTimeEnd%"
252rem convert hours:minutes:seconds:ms into duration
253set /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)
254set /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)
255set /A aDurTotalSec=%aTimeEnd%-%aTimeFrom%
256if %aTimeEnd% LSS %aTimeFrom% set set /A aDurTotalSec=%aTimeFrom%-%aTimeEnd%
257set /A aDurHH=%aDurTotalSec% / 360000
258set /A aDurMM=(%aDurTotalSec% - %aDurHH%*360000) / 6000
259set /A aDurSS=(%aDurTotalSec% - %aDurHH%*360000 - %aDurMM%*6000) / 100
260if %aDurHH% LSS 10 set aDurHH=0%aDurHH%
261if %aDurMM% LSS 10 set aDurMM=0%aDurMM%
262if %aDurSS% LSS 10 set aDurSS=0%aDurSS%
263
264set "DURATION=%aDurHH%:%aDurMM%:%aDurSS%"
265goto :eof