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
39 export USE_FREETYPE=ON
40 export USE_FREEIMAGE=ON
41 export USE_RAPIDJSON=OFF
44 export MACOSX_DEPLOYMENT_TARGET=10.10
45 #export anAbiList="arm64 x86_64"
46 export anAbiList="x86_64"
49 if [[ -f "${aScriptDir}/macos_custom.sh" ]]; then
50 source "${aScriptDir}/macos_custom.sh"
53 anOcctVerSuffix=`grep -e "#define OCC_VERSION_DEVELOPMENT" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
54 anOcctVersion=`grep -e "#define OCC_VERSION_COMPLETE" "$aCasSrc/src/Standard/Standard_Version.hxx" | awk '{print $3}' | xargs`
55 aGitBranch=`git symbolic-ref --short HEAD`
60 aRevision=-${YEAR}-${MONTH}-${DAY}
61 #aRevision=-${aGitBranch}
67 if [[ $toDebug == 1 ]]; then
69 aBuildTypePrefix="-debug"
73 if [[ $isStatic == 1 ]]; then
81 aPlatformAndCompiler=${aPlatform}-${anAbi}${aBuildTypePrefix}-clang
83 aWorkDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}-make"
84 aDestDir="${aCasSrc}/${aBuildRoot}/${aPlatformAndCompiler}"
85 aLogFile="${aCasSrc}/${aBuildRoot}/build-${aPlatformAndCompiler}.log"
87 if [[ $toCMake == 1 ]] && [[ $toClean == 1 ]]; then
95 # include some information about OCCT into archive
96 echo \<pre\>> "${aWorkDir}/VERSION.html"
97 git status >> "${aWorkDir}/VERSION.html"
98 git log -n 100 >> "${aWorkDir}/VERSION.html"
99 echo \</pre\>>> "${aWorkDir}/VERSION.html"
105 function logDuration {
106 if [[ $1 == 1 ]]; then
108 echo $2 time: $aDur sec>> "$aLogFile"
112 # (re)generate Make files
113 if [[ $toCMake == 1 ]]; then
114 echo Configuring OCCT for macOS...
115 cmake -G "Unix Makefiles" \
116 -D CMAKE_OSX_ARCHITECTURES:STRING="$anAbi" \
117 -D CMAKE_BUILD_TYPE:STRING="$aBuildType" \
118 -D BUILD_LIBRARY_TYPE:STRING="$aLibType" \
119 -D INSTALL_DIR:PATH="$aDestDir" \
120 -D INSTALL_DIR_INCLUDE:STRING="inc" \
121 -D INSTALL_DIR_LIB:STRING="lib" \
122 -D INSTALL_DIR_RESOURCE:STRING="src" \
123 -D INSTALL_NAME_DIR:STRING="@executable_path/../Frameworks" \
124 -D USE_FREETYPE:BOOL="$USE_FREETYPE" \
125 -D 3RDPARTY_FREETYPE_DIR:PATH="$aFreeType" \
126 -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="$aFreeType/include" \
127 -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="$aFreeType/include" \
128 -D 3RDPARTY_FREETYPE_LIBRARY_DIR:PATH="$aFreeType/lib" \
129 -D 3RDPARTY_FREETYPE_LIBRARY:FILEPATH="$aFreeType/lib/libfreetype.dylib" \
130 -D USE_RAPIDJSON:BOOL="$USE_RAPIDJSON" \
131 -D 3RDPARTY_RAPIDJSON_DIR:PATH="$aRapidJson" \
132 -D 3RDPARTY_RAPIDJSON_INCLUDE_DIR:PATH="$aRapidJson/include" \
133 -D USE_DRACO:BOOL="$USE_DRACO" \
134 -D 3RDPARTY_DRACO_DIR:PATH="$aDraco" \
135 -D 3RDPARTY_DRACO_INCLUDE_DIR:FILEPATH="$aDraco/include" \
136 -D 3RDPARTY_DRACO_LIBRARY_DIR:PATH="$aDraco/lib" \
137 -D USE_FREEIMAGE:BOOL="$USE_FREEIMAGE" \
138 -D 3RDPARTY_FREEIMAGE_DIR:PATH="$aFreeImage" \
139 -D 3RDPARTY_FREEIMAGE_INCLUDE_DIR:FILEPATH="$aFreeImage/include" \
140 -D 3RDPARTY_FREEIMAGE_LIBRARY_DIR:PATH="$aFreeImage/lib" \
141 -D 3RDPARTY_FREEIMAGE_LIBRARY:FILEPATH="$aFreeImage/lib/libfreeimage.a" \
142 -D BUILD_MODULE_FoundationClasses:BOOL="ON" \
143 -D BUILD_MODULE_ModelingData:BOOL="${BUILD_ModelingData}" \
144 -D BUILD_MODULE_ModelingAlgorithms:BOOL="${BUILD_ModelingAlgorithms}" \
145 -D BUILD_MODULE_Visualization:BOOL="${BUILD_Visualization}" \
146 -D BUILD_MODULE_ApplicationFramework:BOOL="${BUILD_ApplicationFramework}" \
147 -D BUILD_MODULE_DataExchange:BOOL="${BUILD_DataExchange}" \
148 -D BUILD_MODULE_Draw:BOOL="${BUILD_Draw}" \
149 -D BUILD_DOC_Overview:BOOL="OFF" \
150 "$aCasSrc" 2>&1 | tee -a "$aLogFile"
151 aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
154 logDuration $toCMake "Generation" $aTimeZERO $aTimeGEN
156 # clean up from previous build
157 if [[ $toClean == 1 ]]; then
162 if [[ $toMake == 1 ]]; then
163 echo Building OCCT...
164 make -j $aNbJobs 2>&1 | tee -a "$aLogFile"
165 aResult=$?; if [[ $aResult != 0 ]]; then exit $aResult; fi
168 logDuration $toMake "Building" $aTimeGEN $aTimeBUILD
169 logDuration $toMake "Total building" $aTimeZERO $aTimeBUILD
171 # install the project
172 if [[ $toInstall == 1 ]]; then
173 echo Installing OCCT into $aDestDir...
174 make install 2>&1 | tee -a "$aLogFile"
175 cp -f "$aWorkDir/VERSION.html" "$aDestDir/VERSION.html"
176 echo Platform: macOS ABI: ${anAbi} Build: ${aBuildType} MACOSX_DEPLOYMENT_TARGET: ${MACOSX_DEPLOYMENT_TARGET} > "$aDestDir/build_target.txt"
178 aTimeINSTALL=$SECONDS
179 logDuration $toInstall "Install" $aTimeBUILD $aTimeINSTALL
182 if [[ $toPack == 1 ]]; then
183 anArchName=occt-${anOcctVersion}${anOcctVerSuffix}${aRevision}-${aPlatformAndCompiler}.tar.bz2
184 echo Creating an archive ${aCasSrc}/${aBuildRoot}/${anArchName}...
185 rm ${aDestDir}/../${anArchName} &>/dev/null
187 tar -jcf ${aDestDir}/../${anArchName} *
191 logDuration $toPack "Packing archive" $aTimeINSTALL $aTimePACK
194 DURATION=$(($aTimePACK - $aTimeZERO))
195 echo Total time: $DURATION sec
196 logDuration 1 "Total" $aTimeZERO $aTimePACK
201 for anArchIter in $anAbiList
203 echo Platform: macOS ABI: ${anArchIter} Build: ${aBuildType}
204 buildArch $anArchIter
207 # create a FAT archive
208 if [[ $toPackFat == 1 ]]; then
209 aSuffixFat=${aPlatform}${aBuildTypePrefix}-clang
210 aFatDir="${aCasSrc}/${aBuildRoot}/${aSuffixFat}"
212 # merge per-arch builds into fat builds
214 for anArchIter in $anAbiList
216 aSuffixThin=${aPlatform}-${anArchIter}${aBuildTypePrefix}-clang
217 anArchDir="${aCasSrc}/${aBuildRoot}/${aSuffixThin}"
218 if [[ $hasPlatform == 0 ]]; then
220 echo Packing FAT archive
223 if [[ $isStatic == 1 ]]; then
224 rsync -r -l --exclude '*.a' "$anArchDir/" "$aFatDir"
226 rsync -r -l --exclude '*.dylib' "$anArchDir/" "$aFatDir"
228 rm -f "$aFatDir/build_target.txt"
230 if [[ -L "$anArchDir/bin/DRAWEXE" ]]; then
231 aDrawExe=$(readlink "$anArchDir/bin/DRAWEXE")
232 rm $aFatDir/bin/$aDrawExe
233 lipo "$anArchDir/bin/$aDrawExe" -output "$aFatDir/bin/$aDrawExe" -create
236 for aLibIter in $anArchDir/lib/*.$aLibExt; do
237 aLibName=`basename $aLibIter`
238 if [[ -L "$anArchDir/lib/$aLibName" ]]; then
239 cp -a "$anArchDir/lib/$aLibName" "$aFatDir/lib/"
241 lipo "$anArchDir/lib/$aLibName" -output "$aFatDir/lib/$aLibName" -create
245 if [[ -L "$anArchDir/bin/DRAWEXE" ]]; then
246 aDrawExe=$(readlink "$anArchDir/bin/DRAWEXE")
247 lipo "$aFatDir/bin/$aDrawExe" "$anArchDir/bin/$aDrawExe" -output "$aFatDir/bin/$aDrawExe" -create
250 for aLibIter in $aFatDir/lib/*.$aLibExt; do
251 aLibName=`basename $aLibIter`
252 if [[ ! -L "$anArchDir/lib/$aLibName" ]]; then
253 lipo "$aFatDir/lib/$aLibName" "$anArchDir/lib/$aLibName" -output "$aFatDir/lib/$aLibName" -create
254 #lipo -info "$aFatDir/lib/$aLibName"
258 cat "$anArchDir/build_target.txt" >> "$aFatDir/build_target.txt"
262 anArchName=occt-${anOcctVersion}${anOcctVerSuffix}${aRevision}-${aSuffixFat}.tar.bz2
263 echo Creating an archive ${aCasSrc}/${aBuildRoot}/${anArchName}...
264 rm ${aFatDir}/../${anArchName} &>/dev/null
266 tar -jcf ${aFatDir}/../${anArchName} *