0031737: Configuration - Add batch files to build OCCT with Emscripten
authorosa <osa@opencascade.com>
Mon, 18 Nov 2019 11:35:45 +0000 (14:35 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 2 Sep 2020 16:51:56 +0000 (19:51 +0300)
The scripts occ_build_wasm.bat and occ_build_wasm.sh have been added
to simplify batch building of OCCT with Emscripten (Web Assembly packages) correspondingly on Windows and Linux platforms.
These scripts are configurable through calling files with custom environment wasm_custom_env.bat and wasm_custom_env.sh.

adm/scripts/.gitignore [new file with mode: 0644]
adm/scripts/wasm_build.bat [new file with mode: 0644]
adm/scripts/wasm_build.sh [new file with mode: 0755]
adm/scripts/wasm_custom.bat.template [new file with mode: 0644]
adm/scripts/wasm_custom.sh.template [new file with mode: 0644]

diff --git a/adm/scripts/.gitignore b/adm/scripts/.gitignore
new file mode 100644 (file)
index 0000000..3e9b15d
--- /dev/null
@@ -0,0 +1,2 @@
+*custom.bat
+*custom.sh
diff --git a/adm/scripts/wasm_build.bat b/adm/scripts/wasm_build.bat
new file mode 100644 (file)
index 0000000..219ab93
--- /dev/null
@@ -0,0 +1,165 @@
+@echo OFF
+
+rem Auxiliary script for semi-automated building of OCCT for WASM platform.
+rem wasm_custom.bat should be configured with paths to CMake, 3rd-parties and Emscripten SDK.
+rem FreeType should be specified as mandatory dependency.
+
+set "aSrcRoot=%~dp0..\.."
+set "aBuildRoot=work"
+
+set aNbJobs=%NUMBER_OF_PROCESSORS%
+
+set "toCMake=1"
+set "toClean=0"
+set "toMake=1"
+set "toInstall=1"
+
+set "BUILD_ModelingData=ON"
+set "BUILD_ModelingAlgorithms=ON"
+set "BUILD_Visualization=ON"
+set "BUILD_ApplicationFramework=ON"
+set "BUILD_DataExchange=ON"
+
+rem Configuration file
+if exist "%~dp0wasm_custom.bat" call "%~dp0wasm_custom.bat"
+
+call "%EMSDK_ROOT%\emsdk_env.bat"
+set "aToolchain=%EMSDK%/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
+
+set "anOcctVerSuffix="
+set "anOcctVersion=0.0.0"
+set "aGitBranch="
+for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_DEVELOPMENT" "%aSrcRoot%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVerSuffix=%%i" )
+for /f tokens^=2^ delims^=^" %%i in ('findstr /b /c:"#define OCC_VERSION_COMPLETE" "%aSrcRoot%\src\Standard\Standard_Version.hxx"') do ( set "anOcctVersion=%%i" )
+for /f %%i in ('git symbolic-ref --short HEAD') do ( set "aGitBranch=%%i" )
+
+call :cmakeGenerate
+if not ["%1"] == ["-nopause"] (
+  pause
+)
+
+goto :eof
+
+:cmakeGenerate
+set "aPlatformAndCompiler=wasm"
+set "aWorkDir=%aSrcRoot%\%aBuildRoot%\%aPlatformAndCompiler%-make"
+set "aDestDir=%aSrcRoot%\%aBuildRoot%\%aPlatformAndCompiler%"
+set "aLogFile=%aSrcRoot%\%aBuildRoot%\build-%aPlatformAndCompiler%.log"
+if not exist "%aWorkDir%" ( mkdir "%aWorkDir%" )
+if     exist "%aLogFile%" ( del   "%aLogFile%" )
+
+rem include some information about OCCT into archive
+echo ^<pre^>> "%aWorkDir%\VERSION.html"
+git status >> "%aWorkDir%\VERSION.html"
+git log -n 100 >> "%aWorkDir%\VERSION.html"
+echo ^</pre^>>> "%aWorkDir%\VERSION.html"
+
+echo Start building OCCT for %aPlatformAndCompiler%
+echo Start building OCCT for %aPlatformAndCompiler%>> %aLogFile%
+
+pushd "%aWorkDir%"
+
+set aTimeZERO=%TIME%
+if ["%toCMake%"] == ["1"] (
+  echo "Configuring OCCT for WASM..."
+  cmake -G "MinGW Makefiles" ^
+ -D CMAKE_TOOLCHAIN_FILE:FILEPATH="%aToolchain%" ^
+ -D CMAKE_BUILD_TYPE:STRING="Release" ^
+ -D BUILD_LIBRARY_TYPE:STRING="Static" ^
+ -D INSTALL_DIR:PATH="%aDestDir%" ^
+ -D INSTALL_DIR_INCLUDE:STRING="inc" ^
+ -D INSTALL_DIR_RESOURCE:STRING="src" ^
+ -D 3RDPARTY_FREETYPE_DIR:PATH="%aFreeType%" ^
+ -D 3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="%aFreeType%/include" ^
+ -D 3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="%aFreeType%/include" ^
+ -D BUILD_MODULE_FoundationClasses:BOOL="ON" ^
+ -D BUILD_MODULE_ModelingData:BOOL="%BUILD_ModelingData%" ^
+ -D BUILD_MODULE_ModelingAlgorithms:BOOL="%BUILD_ModelingAlgorithms%" ^
+ -D BUILD_MODULE_Visualization:BOOL="%BUILD_Visualization%" ^
+ -D BUILD_MODULE_ApplicationFramework:BOOL="%BUILD_ApplicationFramework%" ^
+ -D BUILD_MODULE_DataExchange:BOOL="%BUILD_DataExchange%" ^
+ -D BUILD_MODULE_Draw:BOOL="OFF" ^
+ -D BUILD_DOC_Overview:BOOL="OFF" ^
+ "%aSrcRoot%"
+
+  if errorlevel 1 (
+    popd
+    exit /B 1
+    goto :eof
+  )
+)
+set aTimeGEN=%TIME%
+call :computeDuration %aTimeZERO% %aTimeGEN%
+if ["%toCMake%"] == ["1"] (
+  echo Generation time: %DURATION%
+  echo Generation time: %DURATION%>> "%aLogFile%"
+)
+
+if "%toClean%"=="1" (
+  mingw32-make clean
+)
+
+if "%toMake%"=="1" (
+  echo Building...
+  mingw32-make -j %aNbJobs% 2>> "%aLogFile%"
+  if errorlevel 1 (
+    popd
+    exit /B 1
+    goto :eof
+  )
+  type "%aLogFile%"
+)
+set aTimeBUILD=%TIME%
+call :computeDuration %aTimeGEN% %aTimeBUILD%
+if "%toMake%"=="1" (
+  echo Building time: %DURATION%
+  echo Building time: %DURATION%>> "%aLogFile%"
+)
+call :computeDuration %aTimeZERO% %aTimeBUILD%
+if "%toMake%"=="1" (
+  echo Total building time: %DURATION%
+  echo Total building time: %DURATION%>> "%aLogFile%"
+)
+
+if "%toInstall%"=="1" (
+  echo Installing into %aDestDir%...
+  mingw32-make install 2>> "%aLogFile%"
+  copy /Y "%aWorkDir%\VERSION.html" "%aDestDir%\VERSION.html"
+)
+set aTimeINSTALL=%TIME%
+call :computeDuration %aTimeBUILD% %aTimeINSTALL%
+if "%toInstall%"=="1" (
+  echo Install time: %DURATION%
+  echo Install time: %DURATION%>> "%aLogFile%"
+)
+
+call :computeDuration %aTimeZERO% %aTimeINSTALL%
+echo Total time: %DURATION%
+echo Total time: %DURATION%>> "%aLogFile%"
+
+popd
+goto :eof
+
+:computeDuration
+set aTimeFrom=%1
+set aTimeEnd=%2
+rem handle time before 10AM (win10 - remove empty space at the beginning)
+if "%aTimeFrom:~0,1%"==" " set "aTimeFrom=%aTimeFrom:~1%"
+if  "%aTimeEnd:~0,1%"==" " set  "aTimeEnd=%aTimeEnd:~1%"
+rem handle time before 10AM (win7 - add 0 at the beginning)
+if "%aTimeFrom:~1,1%"==":" set "aTimeFrom=0%aTimeFrom%"
+if  "%aTimeEnd:~1,1%"==":" set  "aTimeEnd=0%aTimeEnd%"
+rem convert hours:minutes:seconds:ms into duration
+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)
+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)
+set /A aDurTotalSec=%aTimeEnd%-%aTimeFrom%
+if %aTimeEnd% LSS %aTimeFrom% set set /A aDurTotalSec=%aTimeFrom%-%aTimeEnd%
+set /A aDurHH=%aDurTotalSec% / 360000
+set /A aDurMM=(%aDurTotalSec% - %aDurHH%*360000) / 6000
+set /A aDurSS=(%aDurTotalSec% - %aDurHH%*360000 - %aDurMM%*6000) / 100
+if %aDurHH% LSS 10 set aDurHH=0%aDurHH%
+if %aDurMM% LSS 10 set aDurMM=0%aDurMM%
+if %aDurSS% LSS 10 set aDurSS=0%aDurSS%
+
+set "DURATION=%aDurHH%:%aDurMM%:%aDurSS%"
+goto :eof
diff --git a/adm/scripts/wasm_build.sh b/adm/scripts/wasm_build.sh
new file mode 100755 (executable)
index 0000000..b02a308
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+# Auxiliary script for semi-automated building of OCCT for WASM platform.
+# wasm_custom.sh should be configured with paths to CMake, 3rd-parties and Emscripten SDK.
+# FreeType should be specified as mandatory dependency.
+
+export aScriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+export aSrcRoot="${aScriptDir}/../.."
+export aBuildRoot=work
+
+export aNbJobs=${NUMBER_OF_PROCESSORS}
+
+export toCMake=1
+export toClean=0
+export toMake=1
+export toInstall=1
+
+export BUILD_ModelingData=ON
+export BUILD_ModelingAlgorithms=ON
+export BUILD_Visualization=ON
+export BUILD_ApplicationFramework=ON
+export BUILD_DataExchange=ON
+
+if [ -f "${aScriptDir}/wasm_custom.sh" ] ; then
+  . "${aScriptDir}/wasm_custom.sh"
+fi
+
+. "${EMSDK_ROOT}/emsdk_env.sh"
+
+export aToolchain="${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
+
+export aGitBranch=`git symbolic-ref --short HEAD`
+
+echo "Compilation OCCT branch : $aGitBranch"
+
+export aPlatformAndCompiler=wasm
+
+export aWorkDir="${aSrcRoot}/${aBuildRoot}/${aPlatformAndCompiler}-make"
+if [ ! -d "${aWorkDir}" ]; then
+  mkdir -p "${aWorkDir}"
+fi
+
+export aDestDir="${aSrcRoot}/${aBuildRoot}/${aPlatformAndCompiler}"
+if [ ! -d "${aDestDir}" ]; then
+  mkdir -p "${aDestDir}"
+fi
+
+export aLogFile="${aSrcRoot}/${aBuildRoot}/build-${aPlatformAndCompiler}.log"
+if [ -f "${aLogFile}" ]; then
+  rm "${aLogFile}"
+fi
+
+echo Start building OCCT for ${aPlatformAndCompiler}
+echo Start building OCCT for ${aPlatformAndCompiler}>> "${aLogFile}"
+
+pushd "${aWorkDir}"
+pwd
+echo toCMake=${toCMake}
+if [ "${toCMake}" = "1" ]; then
+
+echo "Configuring OCCT for WASM..."
+echo cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE:FILEPATH="${aToolchain}" \
+-DCMAKE_BUILD_TYPE:STRING="Release" \
+-DBUILD_LIBRARY_TYPE:STRING="Static" \
+-DINSTALL_DIR:PATH="${aDestDir}" \
+-DINSTALL_DIR_INCLUDE:STRING="inc" \
+-DINSTALL_DIR_RESOURCE:STRING="src" \
+-D3RDPARTY_FREETYPE_DIR:PATH="$aFreeType" \
+-D3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="$aFreeType/include" \
+-D3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="$aFreeType/include" \
+-DBUILD_MODULE_FoundationClasses:BOOL="ON" \
+-DBUILD_MODULE_ModelingData:BOOL="${BUILD_ModelingData}" \
+-DBUILD_MODULE_ModelingAlgorithms:BOOL="${BUILD_ModelingAlgorithms}" \
+-DBUILD_MODULE_Visualization:BOOL="${BUILD_Visualization}" \
+-DBUILD_MODULE_ApplicationFramework:BOOL="${BUILD_ApplicationFramework}" \
+-DBUILD_MODULE_DataExchange:BOOL="${BUILD_DataExchange}" \
+-DBUILD_MODULE_Draw:BOOL="OFF" \
+-DBUILD_DOC_Overview:BOOL="OFF" "${aSrcRoot}"
+
+cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE:FILEPATH="${aToolchain}" \
+-DCMAKE_BUILD_TYPE:STRING="Release" \
+-DBUILD_LIBRARY_TYPE:STRING="Static" \
+-DINSTALL_DIR:PATH="${aDestDir}" \
+-DINSTALL_DIR_INCLUDE:STRING="inc" \
+-DINSTALL_DIR_RESOURCE:STRING="src" \
+-D3RDPARTY_FREETYPE_DIR:PATH="$aFreeType" \
+-D3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2:FILEPATH="$aFreeType/include" \
+-D3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build:FILEPATH="$aFreeType/include" \
+-DBUILD_MODULE_FoundationClasses:BOOL="ON" \
+-DBUILD_MODULE_ModelingData:BOOL="${BUILD_ModelingData}" \
+-DBUILD_MODULE_ModelingAlgorithms:BOOL="${BUILD_ModelingAlgorithms}" \
+-DBUILD_MODULE_Visualization:BOOL="${BUILD_Visualization}" \
+-DBUILD_MODULE_ApplicationFramework:BOOL="${BUILD_ApplicationFramework}" \
+-DBUILD_MODULE_DataExchange:BOOL="${BUILD_DataExchange}" \
+-DBUILD_MODULE_Draw:BOOL="OFF" \
+-DBUILD_DOC_Overview:BOOL="OFF" "${aSrcRoot}"
+
+  if [ $? -ne 0 ]; then
+    echo "Problem during configuration"
+    popd
+    exit 1
+  fi
+
+fi
+
+if [ "${toClean}" = "1" ]; then
+  make clean
+fi
+
+if [ "${toMake}" = "1" ]; then
+  echo Building...
+  make -j ${aNbJobs} 2>> "${aLogFile}"
+  if [ $? -ne 0 ]; then
+    echo "Problem during make operation"
+    popd
+    exit 1
+  fi
+  echo "${aLogFile}"
+fi
+
+if [ "${toInstall}" = "1" ]; then
+  echo Installing into ${aDestDir}
+  make install 2>> "${aLogFile}"
+fi
+
+popd
diff --git a/adm/scripts/wasm_custom.bat.template b/adm/scripts/wasm_custom.bat.template
new file mode 100644 (file)
index 0000000..5b21b7a
--- /dev/null
@@ -0,0 +1,16 @@
+rem Environment configuration template for occ_build_wasm.bat (to be renamed as wasm_custom_env.bat)
+set "aFreeType=%aSrcRoot%\..\3rdparty\freetype-2.7.1-wasm"
+set "EMSDK_ROOT=%aSrcRoot%\..\emsdk"
+
+rem Uncomment to customize building steps
+rem set "aBuildRoot=work"
+rem set "toCMake=1"
+rem set "toClean=0"
+rem set "toMake=1"
+rem set "toInstall=1"
+
+rem set "BUILD_ModelingData=ON"
+rem set "BUILD_ModelingAlgorithms=ON"
+rem set "BUILD_Visualization=ON"
+rem set "BUILD_ApplicationFramework=ON"
+rem set "BUILD_DataExchange=ON"
diff --git a/adm/scripts/wasm_custom.sh.template b/adm/scripts/wasm_custom.sh.template
new file mode 100644 (file)
index 0000000..29157c9
--- /dev/null
@@ -0,0 +1,16 @@
+# environment configuration template for occ_build_wasm.sh (to be renamed as wasm_custom_env.sh)
+export aFreeType="$aSrcRoot/../3rdparty/freetype-2.7.1-wasm"
+export EMSDK_ROOT="$aSrcRoot/../emsdk"
+
+# Uncomment to customize building steps
+#export aBuildRoot=work
+#export toCMake=1
+#export toClean=0
+#export toMake=1
+#export toInstall=1
+
+#export BUILD_ModelingData=ON
+#export BUILD_ModelingAlgorithms=ON
+#export BUILD_Visualization=ON
+#export BUILD_ApplicationFramework=ON
+#export BUILD_DataExchange=ON