User Tools

Site Tools


openvsp_build_script

OpenVSP Build Script for Ubuntu

The following bash script downloads and builds OpenVSP on Debian based systems.

You may copy the script to an editor and name it openvsp-build.sh. The script may then be executed with the command:

bash openvsp-build.sh.

For a fully automated build using default settings that generates a deb package, use:

yes | bash openvsp-build.sh

#!/bin/bash
#
# This script builds OpenVSP on a Debian-based system
# It provides the user with options to create a zip or deb package
#
# Usage: bash openvsp-build.sh

set -e

# Define usage for using with --help or -h
if [ $# -ne 0 ]; then
  if [ $1 == "-h" ] || [ $1 == "--help" ]; then
    echo "Usage: bash openvsp-build.sh"
  fi
fi

# Set some variables
VSPRepo=https://github.com/OpenVSP/OpenVSP.git 
OpenVSPdir=$(pwd)/OpenVSP
NumOfThreads=$(nproc)

# Get some variables
echo "Create a Deb package?:"
echo "[y] Deb package (default)"
echo "[n] Zip folder"
read -p "Choice [Y/n] : " -n 1 pkgChoice
pkgChoice=${pkgChoice:-1}
case $pkgChoice in 
  y|Y)  # DEB
    pkgGen="DEB"
    ;;
  n|N)  # ZIP
    pkgGen="ZIP"
    ;;
  *)  # Default choice
    pkgGen="DEB"
    ;;
esac
echo

# Install packages using apt
echo
echo "Installing required packages using apt ..."
sudo apt-get install python3-dev git git-gui cmake libxml2-dev \
  libfltk1.3-dev g++ libjpeg-dev libglm-dev libcminpack-dev \
  libglew-dev swig doxygen graphviz texlive-latex-base ninja-build

# Create temporary directories if not present
echo
echo "Creating temporary directories ..."
mkdir -p $OpenVSPdir
mkdir -p $OpenVSPdir/build $OpenVSPdir/buildlibs

# Download source into temporary repo directory if absent
echo
echo "Downloading OpenVSP source from GitHub ..."
[ -d $OpenVSPdir/repo ] || git clone --depth=1 $VSPRepo $OpenVSPdir/repo
cd $OpenVSPdir/repo; git pull $VSPRepo

# Build using Ninja since it's faster.
# Fallback to Make if errors occur
echo
echo "Building libraries ..."
rm -rf $OpenVSP/buildlibs/*
{ echo "Build using Ninja" &&
  cd $OpenVSPdir/buildlibs && 
  cmake -G "Ninja" \
  -DVSP_USE_SYSTEM_LIBXML2=true \
  -DVSP_USE_SYSTEM_FLTK=true \
  -DVSP_USE_SYSTEM_GLM=true \
  -DVSP_USE_SYSTEM_GLEW=true \
  -DVSP_USE_SYSTEM_CMINPACK=true \
  -DVSP_USE_SYSTEM_LIBIGES=false \
  -DVSP_USE_SYSTEM_EIGEN=false \
  -DVSP_USE_SYSTEM_CODEELI=false \
  -DVSP_USE_SYSTEM_CPPTEST=false \
  $OpenVSPdir/repo/Libraries -DCMAKE_BUILD_TYPE=Release &&
  ninja
} || { 
  echo "Build using Make" &&
  cd $OpenVSPdir/buildlibs && 
  cmake \
  -DVSP_USE_SYSTEM_LIBXML2=true \
  -DVSP_USE_SYSTEM_FLTK=true \
  -DVSP_USE_SYSTEM_GLM=true \
  -DVSP_USE_SYSTEM_GLEW=true \
  -DVSP_USE_SYSTEM_CMINPACK=true \
  -DVSP_USE_SYSTEM_LIBIGES=false \
  -DVSP_USE_SYSTEM_EIGEN=false \
  -DVSP_USE_SYSTEM_CODEELI=false \
  -DVSP_USE_SYSTEM_CPPTEST=false \
  $OpenVSPdir/repo/Libraries -DCMAKE_BUILD_TYPE=Release &&
  make -j $NumOfThreads
}

# Build source
echo
echo "Building source ..."
rm -rf $OpenVSPdir/build/*
# Build using Ninja since it's faster.
# Fallback to Make if errors occur
{ echo "Build using Ninja" &&
  cd $OpenVSPdir/build &&
  cmake -G "Ninja" ../repo/src/ \
  -DVSP_LIBRARY_PATH=$OpenVSPdir/buildlibs \
  -DCMAKE_BUILD_TYPE=Release \
  -DVSP_CPACK_GEN=$pkgGen &&
  ninja package &&
  cp *.deb $OpenVSPdir/
} || {
  echo "Build using Make" &&
  cd $OpenVSPdir/build && rm -f $OpenVSPdir/build/* &&
  cmake ../repo/src/ \
  -DVSP_LIBRARY_PATH=$OpenVSPdir/buildlibs \
  -DCMAKE_BUILD_TYPE=Release \
  -DVSP_CPACK_GEN=$pkgGen &&
  make -j $NumOfThreads package &&
  cp *.deb $OpenVSPdir/
}

echo
echo "Removing temporary directories ..."
echo "Remove temporary directories?:"
echo "[y] Remove (default)"
echo "[n] Do not remove"
read -p "Choice [Y/n] : " -n 1 rmChoice
rmChoice=${rmChoice:-1}
case $rmChoice in
  y|Y) # Remove all
    rm -rf $OpenVSPdir/build* $OpenVSPdir/repo
    ;;
  n|N) # Do not remove
    ;;
  *)  # Default choice
    rm -rf $OpenVSPdir/build* $OpenVSPdir/repo
    ;;
esac

echo 
echo "OpenVSP build successfull!"
echo "Deb package created in directory: $OpenVSPdir/"
openvsp_build_script.txt · Last modified: 2020/06/03 14:42 by cibin