3 # Auxiliary script for semi-automated building of OCCT for macOS platform.
4 # macos_custom.sh should be configured with paths to CMake and other 3rd-parties.
5 # FreeType should be specified as mandatory dependency.
7 aScriptDir=${BASH_SOURCE%/*}
8 if [ -d "$aScriptDir" ]; then cd "$aScriptDir"; fi
11 aCasSrc=${aScriptDir}/../..
12 aNbJobs="$(getconf _NPROCESSORS_ONLN)"
14 export aBuildRoot=work
16 # paths to pre-built 3rd-parties
22 # build stages to perform
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 export BUILD_DETools=OFF
40 export USE_FREETYPE=ON
41 export USE_FREEIMAGE=ON
42 export USE_RAPIDJSON=OFF
45 export MACOSX_DEPLOYMENT_TARGET=10.10
46 #export anAbiList="arm64 x86_64"
47 export anAbiList="x86_64"
50 if [[ -f "${aScriptDir}/macos_custom.sh" ]]; then
51 source "${aScriptDir}/macos_custom.sh"
54 anOcctVerSuffix=`grep -e "#define OCC_VERSION_DEVELOPMENT" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
55 anOcctVersion=`grep -e "#define OCC_VERSION_COMPLETE" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
56 aGitBranch=`git symbolic-ref --short HEAD`
61 aRevision=-${YEAR}-${MONTH}-${DAY}
62 #aRevision=-${aGitBranch}
68 if [[ $toDebug == 1 ]]; then
70 aBuildTypePrefix="-debug"
74 if [[ $isStatic == 1 ]]; then
82 aPlatformAndCompiler=${aPlatform}-${anAbi}${aBuildTypePrefix}-clang
84 aWorkDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}-make"
85 aDestDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}"
86 aLogFile="${aCasSrc}/${aBuildRoot}/build-${aPlatformAndCompiler}.log"
88 if [[ $toCMake == 1 ]] && [[ $toClean == 1 ]]; then
96 # include some information about OCCT into archive
97 echo \<pre\>> "${aWorkDir}/VERSION.html"
98 git status >> "${aWorkDir}/VERSION.html"
99 git log -n 100 >> "${aWorkDir}/VERSION.html"
100 echo \</pre\>>> "${aWorkDir}/VERSION.html"
106 function logDuration {
107 if [[ $1 == 1 ]]; then
109 echo $2 time: $aDur sec>> "$aLogFile"
113 # (re)generate Make files
114 if [[ $toCMake == 1 ]]; then
115 echo Configuring OCCT for macOS...
116 cmake -G "Unix Makefiles" \
117 -D CMAKE_OSX_ARCHITECTURES:STRING="$anAbi" \
118 -D CMAKE_BUILD_TYPE:STRING="$aBuildType" \
119 -D BUILD_LIBRARY_TYPE:STRING="$aLibType" \
120 -D INSTALL_DIR:PATH="$aDestDir" \
121 -D INSTALL_DIR_INCLUDE:STRING="inc" \
122 -D INSTALL_DIR_LIB:STRING="lib" \
123 -D INSTALL_DIR_RESOURCE:STRING="src" \
124 -D INSTALL_NAME_DIR:STRING="@executable_path/../Frameworks" \
125 -D USE_FREETYPE:BOOL="$USE_FREETYPE" \
126 -D 3RDPARTY_FREETYPE_DIR:PATH="$aFreeType" \
127 -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="$aFreeType/include" \
128 -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="$aFreeType/include" \
129 -D 3RDPARTY_FREETYPE_LIBRARY_DIR:PATH="$aFreeType/lib" \
130 -D 3RDPARTY_FREETYPE_LIBRARY:FILEPATH="$aFreeType/lib/libfreetype.dylib" \
131 -D USE_RAPIDJSON:BOOL="$USE_RAPIDJSON" \
132 -D 3RDPARTY_RAPIDJSON_DIR:PATH="$aRapidJson" \
133 -D 3RDPARTY_RAPIDJSON_INCLUDE_DIR:PATH="$aRapidJson/include" \
134 -D USE_DRACO:BOOL="$USE_DRACO" \
135 -D 3RDPARTY_DRACO_DIR:PATH="$aDraco" \
136 -D 3RDPARTY_DRACO_INCLUDE_DIR:FILEPATH="$aDraco/include" \
137 -D 3RDPARTY_DRACO_LIBRARY_DIR:PATH="$aDraco/lib" \
138 -D USE_FREEIMAGE:BOOL="$USE_FREEIMAGE" \
139 -D 3RDPARTY_FREEIMAGE_DIR:PATH="$aFreeImage" \
140 -D 3RDPARTY_FREEIMAGE_INCLUDE_DIR:FILEPATH="$aFreeImage/include" \
141 -D 3RDPARTY_FREEIMAGE_LIBRARY_DIR:PATH="$aFreeImage/lib" \
142 -D 3RDPARTY_FREEIMAGE_LIBRARY:FILEPATH="$aFreeImage/lib/libfreeimage.a" \
143 -D BUILD_MODULE_FoundationClasses:BOOL="ON" \
144 -D BUILD_MODULE_ModelingData:BOOL="${BUILD_ModelingData}" \
145 -D BUILD_MODULE_ModelingAlgorithms:BOOL="${BUILD_ModelingAlgorithms}" \
146 -D BUILD_MODULE_Visualization:BOOL="${BUILD_Visualization}" \
147 -D BUILD_MODULE_ApplicationFramework:BOOL="${BUILD_ApplicationFramework}" \
148 -D BUILD_MODULE_DataExchange:BOOL="${BUILD_DataExchange}" \
149 -D BUILD_MODULE_DETools:BOOL="${BUILD_DETools}" \
150 -D BUILD_MODULE_Draw:BOOL="${BUILD_Draw}" \
151 -D BUILD_DOC_Overview:BOOL="OFF" \
152 "$aCasSrc" 2>&1 | tee -a "$aLogFile"
153 aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
156 logDuration $toCMake "Generation" $aTimeZERO $aTimeGEN
158 # clean up from previous build
159 if [[ $toClean == 1 ]]; then
164 if [[ $toMake == 1 ]]; then
165 echo Building OCCT...
166 make -j $aNbJobs 2>&1 | tee -a "$aLogFile"
167 aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
170 logDuration $toMake "Building" $aTimeGEN $aTimeBUILD
171 logDuration $toMake "Total building" $aTimeZERO $aTimeBUILD
173 # install the project
174 if [[ $toInstall == 1 ]]; then
175 echo Installing OCCT into $aDestDir...
176 make install 2>&1 | tee -a "$aLogFile"
177 cp -f "$aWorkDir/VERSION.html" "$aDestDir/VERSION.html"
178 echo Platform: macOS ABI: ${anAbi} Build: ${aBuildType} MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET} > "$aDestDir/build_target.txt"
180 aTimeINSTALL=$SECONDS
181 logDuration $toInstall "Install" $aTimeBUILD $aTimeINSTALL
184 if [[ $toPack == 1 ]]; then
185 anArchName=occt-${anOcctVersion}${anOcctVerSuffix}${aRevision}-${aPlatformAndCompiler}.tar.bz2
186 echo Creating an archive ${aCasSrc}/${aBuildRoot}/${anArchName}...
187 rm ${aDestDir}/../${anArchName} &>/dev/null
189 tar -jcf ${aDestDir}/../${anArchName} *
193 logDuration $toPack "Packing archive" $aTimeINSTALL $aTimePACK
196 DURATION=$(($aTimePACK - $aTimeZERO))
197 echo Total time: $DURATION sec
198 logDuration 1 "Total" $aTimeZERO $aTimePACK
203 for anArchIter in $anAbiList
205 echo Platform: macOS ABI: ${anArchIter} Build: ${aBuildType}
206 buildArch $anArchIter
209 # create a FAT archive
210 if [[ $toPackFat == 1 ]]; then
211 aSuffixFat=${aPlatform}${aBuildTypePrefix}-clang
212 aFatDir="${aCasSrc}/${aBuildRoot}/${aSuffixFat}"
214 # merge per-arch builds into fat builds
216 for anArchIter in $anAbiList
218 aSuffixThin=${aPlatform}-${anArchIter}${aBuildTypePrefix}-clang
219 anArchDir="${aCasSrc}/${aBuildRoot}/${aSuffixThin}"
220 if [[ $hasPlatform == 0 ]]; then
222 echo Packing FAT archive
225 if [[ $isStatic == 1 ]]; then
226 rsync -r -l --exclude '*.a' "$anArchDir/" "$aFatDir"
228 rsync -r -l --exclude '*.dylib' "$anArchDir/" "$aFatDir"
230 rm -f "$aFatDir/build_target.txt"
232 if [[ -L "$anArchDir/bin/DRAWEXE" ]]; then
233 aDrawExe=$(readlink "$anArchDir/bin/DRAWEXE")
234 rm $aFatDir/bin/$aDrawExe
235 lipo "$anArchDir/bin/$aDrawExe" -output "$aFatDir/bin/$aDrawExe" -create
238 for aLibIter in $anArchDir/lib/*.$aLibExt; do
239 aLibName=`basename $aLibIter`
240 if [[ -L "$anArchDir/lib/$aLibName" ]]; then
241 cp -a "$anArchDir/lib/$aLibName" "$aFatDir/lib/"
243 lipo "$anArchDir/lib/$aLibName" -output "$aFatDir/lib/$aLibName" -create
247 if [[ -L "$anArchDir/bin/DRAWEXE" ]]; then
248 aDrawExe=$(readlink "$anArchDir/bin/DRAWEXE")
249 lipo "$aFatDir/bin/$aDrawExe" "$anArchDir/bin/$aDrawExe" -output "$aFatDir/bin/$aDrawExe" -create
252 for aLibIter in $aFatDir/lib/*.$aLibExt; do
253 aLibName=`basename $aLibIter`
254 if [[ ! -L "$anArchDir/lib/$aLibName" ]]; then
255 lipo "$aFatDir/lib/$aLibName" "$anArchDir/lib/$aLibName" -output "$aFatDir/lib/$aLibName" -create
256 #lipo -info "$aFatDir/lib/$aLibName"
260 cat "$anArchDir/build_target.txt" >> "$aFatDir/build_target.txt"
264 anArchName=occt-${anOcctVersion}${anOcctVerSuffix}${aRevision}-${aSuffixFat}.tar.bz2
265 echo Creating an archive ${aCasSrc}/${aBuildRoot}/${anArchName}...
266 rm ${aFatDir}/../${anArchName} &>/dev/null
268 tar -jcf ${aFatDir}/../${anArchName} *