Last active
August 7, 2020 15:06
-
-
Save cristobaltapia/646fd03a3fc91b9e1a9678d9d33e3c07 to your computer and use it in GitHub Desktop.
Makefile to install pythonocc-core in a python virtualenv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** link.txt 2020-08-05 13:48:49.659309029 +0200 | |
--- link_new.txt 2020-08-05 13:54:15.455429048 +0200 | |
*************** | |
*** 1 **** | |
! /usr/bin/cc -O3 -DNDEBUG -lm -rdynamic CMakeFiles/gl2psTest.dir/gl2psTest.o -o gl2psTest libgl2ps.a -lGL -lGLU -lglut -lXmu -lXi -lz -lpng -lz -lpng | |
--- 1 ---- | |
! /usr/bin/cc -O3 -DNDEBUG -lm -rdynamic CMakeFiles/gl2psTest.dir/gl2psTest.o -o gl2psTest libgl2ps.a -lGL -lGLU -lglut -lXmu -lXi -lz -lpng -lz -lpng -lm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** link.txt 2020-08-05 13:56:54.295587436 +0200 | |
--- link_new.txt 2020-08-05 13:58:27.845324968 +0200 | |
*************** | |
*** 1 **** | |
! /usr/bin/cc -O3 -DNDEBUG -lm -rdynamic CMakeFiles/gl2psTestSimple.dir/gl2psTestSimple.o -o gl2psTestSimple libgl2ps.a -lGL -lGLU -lglut -lXmu -lXi -lz -lpng -lz -lpng | |
--- 1 ---- | |
! /usr/bin/cc -O3 -DNDEBUG -lm -rdynamic CMakeFiles/gl2psTestSimple.dir/gl2psTestSimple.o -o gl2psTestSimple libgl2ps.a -lGL -lGLU -lglut -lXmu -lXi -lz -lpng -lz -lpng -lm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY : prepare-venv clean clean-all all | |
current_dir = $(shell pwd) | |
PY_MAJORVERSION=3 | |
PY_MINORVERSION=6 | |
PY_MICROVERSION=2 | |
PY_VERSION=$(PY_MAJORVERSION).$(PY_MINORVERSION).$(PY_MICROVERSION) | |
PY_VERSION_SHORT=$(PY_MAJORVERSION).$(PY_MINORVERSION) | |
OCE_VERSION=OCE-0.18.3 | |
PYTHONOCC_VERSION=0.18.2 | |
VENV_DIR=$(current_dir)/venv | |
BUILD_DIR=$(HOME)/git/build_occ | |
GL2PS_BUILD=$(BUILD_DIR)/gl2ps | |
OCE_INSTALL=$(current_dir)/libs/oce | |
OCE_BUILD=$(BUILD_DIR)/oce | |
OCC_BUILD=$(BUILD_DIR)/python-occ | |
GL2PS_INSTALL=$(current_dir)/libs/gl2ps | |
SMESH_BUILD=$(BUILD_DIR)/smesh | |
prepare-venv : $(VENV_DIR)/bin/activate | |
##################################################################### | |
# Install dependencies | |
##################################################################### | |
install-ubuntu-dependencies : | |
apt install \ | |
liboce-foundation-dev \ | |
liboce-modeling-dev \ | |
liboce-ocaf-dev \ | |
liboce-visualization-dev \ | |
ninja-build \ | |
swig \ | |
libfreeimage-dev \ | |
libfreeimageplus-dev \ | |
doxygen | |
$(VENV_DIR)/bin/activate : requirements.txt | |
# Install pythonocc-core in a virtualenv | |
mkdir --parents $(BUILD_DIR) | |
# Install virtualenv | |
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $(PY_VERSION) | |
# Directory of the virtualenv | |
mkdir -p $(VENV_DIR) | |
cp ./patches-py-occ/patch_activate.patch $(VENV_DIR)/patch_activate.patch | |
# | |
virtualenv --python=$(HOME)/.pyenv/versions/$(PY_VERSION)/bin/python$(PY_VERSION_SHORT) $(VENV_DIR) | |
# Patch activate file | |
patch -u $(VENV_DIR)/bin/activate < patch_activate.patch | |
sed -i "s,VENVDIR,$(VENV_DIR),g" $(VENV_DIR)/bin/activate | |
# Activate virtualenv | |
. $(VENV_DIR)/bin/activate ;\ | |
yes | pip install -r requirements.txt | |
touch $(VENV_DIR)/bin/activate | |
##################################################################### | |
# Build gl2ps | |
##################################################################### | |
installed_gl2ps.txt : $(VENV_DIR)/bin/activate | |
rm -rf $(GL2PS_BUILD) | |
mkdir -p $(GL2PS_BUILD) | |
mkdir -p $(GL2PS_BUILD)/build | |
# | |
cd $(BUILD_DIR) && wget -nc http://geuz.org/gl2ps/src/gl2ps-1.3.8.tgz | |
tar -xvzf $(BUILD_DIR)/gl2ps-1.3.8.tgz -C $(GL2PS_BUILD)/ && \ | |
mv $(GL2PS_BUILD)/gl2ps-1.3.8-source/* $(GL2PS_BUILD)/ | |
cmake \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_INSTALL_PREFIX:PATH=$(GL2PS_INSTALL) \ | |
-DCMAKE_EXE_LINKER_FLAGS=-lm \ | |
-B $(GL2PS_BUILD)/build $(GL2PS_BUILD) | |
# | |
patch -c -i link_gl2psTest.patch \ | |
$(GL2PS_BUILD)/build/CMakeFiles/gl2psTest.dir/link.txt | |
patch -c -i link_gl2psTestSimple.patch \ | |
$(GL2PS_BUILD)/build/CMakeFiles/gl2psTestSimple.dir/link.txt | |
# | |
make -C $(GL2PS_BUILD)/build | |
make -C $(GL2PS_BUILD)/build install > installed_gl2ps.txt | |
##################################################################### | |
# Build OCE | |
##################################################################### | |
installed_oce.txt : installed_gl2ps.txt | |
# @rm -rf $(OCE_BUILD) | |
if [ ! -e $(OCE_BUILD)/.git/config ]; \ | |
then \ | |
git clone https://github.com/tpaviot/oce.git $(OCE_BUILD) ; \ | |
rm -rf $(OCE_BUILD)/build && mkdir $(OCE_BUILD)/build ; \ | |
fi; | |
cd $(OCE_BUILD) && git checkout $(OCE_VERSION) | |
# - Patch for `xlocal.h` | |
if [ ! -e "/usr/include/xlocale.h" ]; \ | |
then \ | |
sed -i 's, #include <xlocale.h>, #include <locale.h>,g' "$(OCE_BUILD)/src/Standard/Standard_CLocaleSentry.hxx" ; \ | |
fi; | |
# | |
cmake \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DOCE_COPY_HEADERS_BUILD=ON \ | |
-DOCE_BUILD_SHARED_LIB:BOOL=ON \ | |
-DOCE_DATAEXCHANGE:BOOL=ON \ | |
-DOCE_INSTALL_LIB_DIR=lib \ | |
-DOCE_INSTALL_BIN_DIR=bin \ | |
-DOCE_DRAW:BOOL=ON \ | |
-DOCE_MODEL:BOOL=ON \ | |
-DOCE_MULTITHREAD_LIBRARY:STRING=TBB \ | |
-DOCE_OCAF:BOOL=ON \ | |
-DOCE_VISUALISATION:BOOL=ON \ | |
-DOCE_WITH_FREEIMAGE:BOOL=ON \ | |
-DOCE_WITH_VTK:BOOL=ON \ | |
-DOCE_WITH_GL2PS:BOOL=ON \ | |
-DOCE_TESTING:BOOL=OFF \ | |
-DOCE_FREEIMAGE_INCLUDE_DIR:PATH=/usr/include \ | |
-DGL2PS_INCLUDE_DIR:PATH=$(GL2PS_INSTALL)/include \ | |
-DOCE_INSTALL_PREFIX:PATH=$(OCE_INSTALL) \ | |
-GNinja -B $(OCE_BUILD)/build $(OCE_BUILD) | |
ninja -C $(OCE_BUILD)/build | |
ninja install -C $(OCE_BUILD)/build > installed_oce.txt | |
##################################################################### | |
# Build PythonOCC | |
##################################################################### | |
installed_pythonocc.txt : installed_oce.txt | |
if [ ! -e $(OCC_BUILD)/.git/config ]; \ | |
then \ | |
git clone https://github.com/tpaviot/pythonocc-core.git $(OCC_BUILD) ; \ | |
fi; | |
cd $(OCC_BUILD) && git checkout $(PYTHONOCC_VERSION) | |
rm -rf $(OCC_BUILD)/build | |
mkdir $(OCC_BUILD)/build | |
# | |
cmake \ | |
-DCMAKE_INSTALL_PREFIX:PATH=$(VENV_DIR) \ | |
-DPYTHON_EXECUTABLE:PATH=$(VENV_DIR)/bin/python$(PY_VERSION_SHORT) \ | |
-DPYTHON_LIBRARY:PATH=$(HOME)/.pyenv/versions/$(PY_VERSION)/lib/libpython$(PY_MAJORVERSION).so \ | |
-DOCE_INCLUDE_PATH:PATH=$(OCE_INSTALL)/include/oce \ | |
-DOCE_LIB_PATH:PATH=$(OCE_INSTALL)/lib \ | |
-GNinja -B $(OCC_BUILD)/build $(OCC_BUILD) | |
# | |
. venv/bin/activate && ninja -C $(OCC_BUILD)/build | |
. venv/bin/activate && ninja -C $(OCC_BUILD)/build install > installed_pythonocc.txt | |
all : installed_pythonocc.txt | |
clean : | |
rm installed_pythonocc.txt | |
rm installed_oce.txt | |
rm installed_gl2ps.txt | |
rm -rf $(VENV_DIR) | |
clean-build : | |
rm -rf $(OCE_BUILD) | |
rm -rf $(GL2PS_BUILD) | |
rm -rf $(OCC_BUILD) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- bin/activate 2019-01-18 14:34:11.916832564 +0100 | |
+++ bin/activate 2019-01-18 16:47:39.069701617 +0100 | |
@@ -17,6 +17,12 @@ | |
unset _OLD_VIRTUAL_PYTHONHOME | |
fi | |
+ if [ -n "$_OLD_VIRTUAL_LD_LIBRARY_PATH" ] ; then | |
+ LD_LIBRARY_PATH="$_OLD_VIRTUAL_LD_LIBRARY_PATH" | |
+ export LD_LIBRARY_PATH | |
+ unset _OLD_VIRTUAL_LD_LIBRARY_PATH | |
+ fi | |
+ | |
# This should detect bash and zsh, which have a hash command that must | |
# be called to get it to forget past commands. Without forgetting | |
# past commands the $PATH changes we made may not be respected | |
@@ -47,6 +53,10 @@ | |
PATH="$VIRTUAL_ENV/bin:$PATH" | |
export PATH | |
+_OLD_VIRTUAL_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" | |
+LD_LIBRARY_PATH="VENVDIR/lib:$LD_LIBRARY_PATH" | |
+export LD_LIBRARY_PATH | |
+ | |
# unset PYTHONHOME if set | |
if ! [ -z "${PYTHONHOME+_}" ] ; then | |
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment