0032536: Configuration - extend adm/scripts with USE_DRACO option
[occt.git] / adm / scripts / ios_build.sh
1 #!/bin/bash
2
3 # Auxiliary script for semi-automated building of OCCT for iOS platform.
4 # macos_custom.sh should be configured with paths to CMake and other 3rd-parties.
5 # FreeType should be specified as mandatory dependency.
6
7 aScriptDir=${BASH_SOURCE%/*}
8 if [ -d "$aScriptDir" ]; then cd "$aScriptDir"; fi
9 aScriptDir="$PWD"
10
11 aCasSrc=${aScriptDir}/../..
12 aNbJobs="$(getconf _NPROCESSORS_ONLN)"
13
14 export aBuildRoot=work
15
16 # paths to pre-built 3rd-parties
17 export aFreeType=
18 export aFreeImage=
19 export aRapidJson=
20 export aDraco=
21
22 # build stages to perform
23 export toSimulator=0
24 export isStatic=1
25 export toCMake=1
26 export toClean=1
27 export toMake=1
28 export toInstall=1
29 export toPack=0
30 export toDebug=0
31
32 export BUILD_ModelingData=ON
33 export BUILD_ModelingAlgorithms=ON
34 export BUILD_Visualization=ON
35 export BUILD_ApplicationFramework=ON
36 export BUILD_DataExchange=ON
37
38 export USE_FREETYPE=ON
39 export USE_FREEIMAGE=OFF
40 export USE_RAPIDJSON=OFF
41 export USE_DRACO=OFF
42
43 export IPHONEOS_DEPLOYMENT_TARGET=8.0
44 export anAbi=arm64
45 #export anAbi=x86_64
46
47 if [[ -f "${aScriptDir}/ios_custom.sh" ]]; then
48   source "${aScriptDir}/ios_custom.sh"
49 fi
50
51 aBuildType="Release"
52 aBuildTypePrefix=
53 if [[ $toDebug == 1 ]]; then
54   aBuildType="Debug"
55   aBuildTypePrefix="-debug"
56 fi
57 aLibType="Shared"
58 if [[ $isStatic == 1 ]]; then
59   aLibType="Static"
60 fi
61 aPlatformAndCompiler=ios-${anAbi}${aBuildTypePrefix}-clang
62 aPlatformSdk="iphoneos"
63 aSysRoot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
64 if [[ $toSimulator == 1 ]]; then
65   #anAbi=x86_64
66   aPlatformAndCompiler=ios-simulator64-${anAbi}${aBuildTypePrefix}-clang
67   aPlatformSdk="iphonesimulator"
68   aSysRoot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
69 fi
70
71 aWorkDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}-make"
72 aDestDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}"
73 aLogFile="${aCasSrc}/${aBuildRoot}/build-${aPlatformAndCompiler}.log"
74
75 if [[ $toCMake == 1 ]] && [[ $toClean == 1 ]]; then
76   rm -r -f "$aWorkDir"
77   rm -r -f "$aDestDir"
78 fi
79 mkdir -p "$aWorkDir"
80 mkdir -p "$aDestDir"
81 rm -f "$aLogFile"
82
83 anOcctVerSuffix=`grep -e "#define OCC_VERSION_DEVELOPMENT" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
84 anOcctVersion=`grep -e "#define OCC_VERSION_COMPLETE" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
85 aGitBranch=`git symbolic-ref --short HEAD`
86
87 # include some information about OCCT into archive
88 echo \<pre\>> "${aWorkDir}/VERSION.html"
89 git status >> "${aWorkDir}/VERSION.html"
90 git log -n 100 >> "${aWorkDir}/VERSION.html"
91 echo \</pre\>>> "${aWorkDir}/VERSION.html"
92
93 pushd "$aWorkDir"
94
95 aTimeZERO=$SECONDS
96 set -o pipefail
97
98 function logDuration {
99   if [[ $1 == 1 ]]; then
100     aDur=$(($4 - $3))
101     echo $2 time: $aDur sec>> "$aLogFile"
102   fi
103 }
104
105 # (re)generate Make files
106 if [[ $toCMake == 1 ]]; then
107   echo Configuring OCCT for iOS...
108   cmake -G "Unix Makefiles" \
109   -D CMAKE_SYSTEM_NAME="iOS" \
110   -D CMAKE_OSX_ARCHITECTURES:STRING="$anAbi" \
111   -D CMAKE_OSX_DEPLOYMENT_TARGET:STRING="$IPHONEOS_DEPLOYMENT_TARGET" \
112   -D CMAKE_OSX_SYSROOT:PATH="$aSysRoot" \
113   -D ENABLE_VISIBILITY:BOOL="TRUE" \
114   -D CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS:BOOL="OFF" \
115   -D CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS:BOOL="OFF" \
116   -D CMAKE_BUILD_TYPE:STRING="$aBuildType" \
117   -D BUILD_LIBRARY_TYPE:STRING="$aLibType" \
118   -D INSTALL_DIR:PATH="$aDestDir" \
119   -D INSTALL_DIR_INCLUDE:STRING="inc" \
120   -D INSTALL_DIR_LIB:STRING="lib" \
121   -D INSTALL_DIR_RESOURCE:STRING="src" \
122   -D INSTALL_NAME_DIR:STRING="@executable_path/../Frameworks" \
123   -D USE_FREETYPE:BOOL="$USE_FREETYPE" \
124   -D 3RDPARTY_FREETYPE_DIR:PATH="$aFreeType" \
125   -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="$aFreeType/include" \
126   -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="$aFreeType/include" \
127   -D 3RDPARTY_FREETYPE_LIBRARY_DIR:PATH="$aFreeType/lib" \
128   -D USE_RAPIDJSON:BOOL="$USE_RAPIDJSON" \
129   -D 3RDPARTY_RAPIDJSON_DIR:PATH="$aRapidJson" \
130   -D 3RDPARTY_RAPIDJSON_INCLUDE_DIR:PATH="$aRapidJson/include" \
131   -D USE_DRACO:BOOL="$USE_DRACO" \
132   -D 3RDPARTY_DRACO_DIR:PATH="$aDraco" \
133   -D 3RDPARTY_DRACO_INCLUDE_DIR:FILEPATH="$aDraco/include" \
134   -D 3RDPARTY_DRACO_LIBRARY_DIR:PATH="$aDraco/lib" \
135   -D USE_FREEIMAGE:BOOL="$USE_FREEIMAGE" \
136   -D 3RDPARTY_FREEIMAGE_DIR:PATH="$aFreeImage" \
137   -D 3RDPARTY_FREEIMAGE_INCLUDE_DIR:FILEPATH="$aFreeImage/include" \
138   -D 3RDPARTY_FREEIMAGE_LIBRARY_DIR:PATH="$aFreeImage/lib" \
139   -D 3RDPARTY_FREEIMAGE_LIBRARY:FILEPATH="$aFreeImage/lib/libfreeimage.a" \
140   -D BUILD_MODULE_FoundationClasses:BOOL="ON" \
141   -D BUILD_MODULE_ModelingData:BOOL="${BUILD_ModelingData}" \
142   -D BUILD_MODULE_ModelingAlgorithms:BOOL="${BUILD_ModelingAlgorithms}" \
143   -D BUILD_MODULE_Visualization:BOOL="${BUILD_Visualization}" \
144   -D BUILD_MODULE_ApplicationFramework:BOOL="${BUILD_ApplicationFramework}" \
145   -D BUILD_MODULE_DataExchange:BOOL="${BUILD_DataExchange}" \
146   -D BUILD_MODULE_Draw:BOOL="OFF" \
147   -D BUILD_DOC_Overview:BOOL="OFF" \
148   "$aCasSrc" 2>&1 | tee -a "$aLogFile"
149   aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
150 fi
151 aTimeGEN=$SECONDS
152 logDuration $toCMake "Generation" $aTimeZERO $aTimeGEN
153
154 # clean up from previous build
155 if [[ $toClean == 1 ]]; then
156   make clean
157 fi
158
159 # build the project
160 if [[ $toMake == 1 ]]; then
161   echo Building...
162   make -j $aNbJobs 2>&1 | tee -a "$aLogFile"
163   aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
164 fi
165 aTimeBUILD=$SECONDS
166 logDuration $toMake "Building"       $aTimeGEN  $aTimeBUILD
167 logDuration $toMake "Total building" $aTimeZERO $aTimeBUILD
168
169 # install the project
170 if [[ $toInstall == 1 ]]; then
171   echo Installing OCCT into $aDestDir...
172   make install 2>&1 | tee -a "$aLogFile"
173   cp -f "$aWorkDir/VERSION.html" "$aDestDir/VERSION.html"
174 fi
175 aTimeINSTALL=$SECONDS
176 logDuration $toInstall "Install" $aTimeBUILD $aTimeINSTALL
177
178 # create an archive
179 if [[ $toPack == 1 ]]; then
180   YEAR=$(date +"%Y")
181   MONTH=$(date +"%m")
182   DAY=$(date +"%d")
183   aRevision=-${YEAR}-${MONTH}-${DAY}
184   #aRevision=-${aGitBranch}
185
186   anArchName=occt-${anOcctVersion}${anOcctVerSuffix}${aRevision}-${aPlatformAndCompiler}.tar.bz2
187   echo Creating an archive ${aCasSrc}/${aBuildRoot}/${anArchName}...
188   rm ${aDestDir}/../${anArchName} &>/dev/null
189   pushd "$aDestDir"
190   tar -jcf ${aDestDir}/../${anArchName} *
191   popd
192 fi
193 aTimePACK=$SECONDS
194 logDuration $toPack "Packing archive" $aTimeINSTALL $aTimePACK
195
196 # finished
197 DURATION=$(($aTimePACK - $aTimeZERO))
198 echo Total time: $DURATION sec
199 logDuration 1 "Total" $aTimeZERO $aTimePACK
200
201 popd