#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# | Copyright (C) 2012-2016 OpenFOAM Foundation
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# .
#
# Script
# makeCGAL
#
# Description
# Build script for CGAL
#
# Note
# Normally builds against ThirdParty boost and gmp/mpfr when possible.
# To override this behaviour (and use the system boost and/or gmp/mpfr),
# simply specify a 'system' version. For example,
# makeCGAL boost-system gmp-system
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
# Dynamic library ending (default is .so)
[ "$(uname -s)" = Darwin ] && EXT_SO=.dylib || EXT_SO=.so
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
[ "$#" -eq 3 ] || { echo "${0##*/} -test : needs 2 argument"; exit 1; }
dir="${2%/}" # <- CGAL_ARCH_PATH
if [ -d "$dir/include" -a -r "$dir/lib$WM_COMPILER_LIB_ARCH/libCGAL$EXT_SO" ]
then
echo " CGAL include: $dir/include"
echo " CGAL library: $dir/lib$WM_COMPILER_LIB_ARCH"
# Additional information about boost
dir="${3%/}" # <- BOOST_ARCH_PATH
for root in "$dir" /usr
do
if [ -d "$root/include/boost" \
-a -r "$root/lib$WM_COMPILER_LIB_ARCH/libboost_system$EXT_SO" ]
then
echo " boost include: $root/include"
echo " boost library: $root/lib$WM_COMPILER_LIB_ARCH"
break
fi
done
exit 0
else
exit 2
fi
fi
#------------------------------------------------------------------------------
# Run from third-party directory only
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
echo " Check your OpenFOAM environment and installation"
exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
unset BOOST_ARCH_PATH CGAL_ARCH_PATH GMP_ARCH_PATH MPFR_ARCH_PATH # Purge old
# CGAL, boost and gmp/mpfr versions from OpenFOAM etc/config.sh files.
# Get compiler first and let CGAL config override GMP and MPFR
_foamConfig compiler
_foamConfig CGAL
boostPACKAGE=${boost_version:-boost-system}
gmpPACKAGE=${gmp_version:-gmp-system}
mpfrPACKAGE=${mpfr_version:-mpfr-system}
cgalPACKAGE=$cgal_version
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat</dev/null && pwd -P)
then
boostPACKAGE=${BOOST_ARCH_PATH##*/}
else
echo "ERROR: bad path for BOOST_ARCH_PATH"
echo "stopping build"
exit 1
fi
libdir="$BOOST_ARCH_PATH/lib"
else
boostInc="/usr/include"
boostLib="/usr/lib$WM_COMPILER_LIB_ARCH"
libdir="/usr/lib"
fi
# Use lib/ when lib64/ does not exist
[ ! -d "$boostLib" -a -d "$libdir" ] && boostLib="$libdir"
elif [ -f "$boostInc/boost/version.hpp" ]
then
echo "Using $boostPACKAGE"
libdir="$BOOST_ARCH_PATH/lib"
# Use lib when lib64 does not exist
[ ! -d "$boostLib" -a -d "$libdir" ] && boostLib="$libdir"
else
echo "Starting build: $boostPACKAGE"
echo
# Absolute path for --libdir
(
# Configuration options:
unset buildOpt
cd $BOOST_SOURCE_DIR || exit 1
export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
rm -rf $BOOST_ARCH_PATH
case "$WM_COMPILER" in
(Arm*)
# Toolset for bootstrap
optToolset="gcc"
echo "using clang : arm : $(whichCC) ;" > user-config.jam
echo "using mpi ;" >> user-config.jam
# Toolset for build
buildOpt="--user-config=user-config.jam toolset=clang"
;;
(Mingw*)
# Toolset for bootstrap
optToolset="gcc"
echo "using gcc : mingw : $(whichCC) ;" > user-config.jam
# Toolset for build
buildOpt="--user-config=user-config.jam toolset=gcc"
buildOpt="$buildOpt target-os=windows release"
;;
(*)
# Toolset for bootstrap and build
[ -n "$optToolset" ] || optToolset="$(whichCC)"
buildOpt="toolset=$optToolset"
;;
esac
./bootstrap.sh \
--prefix=$BOOST_ARCH_PATH \
--libdir=$boostLib \
--with-libraries=thread \
--with-libraries=system \
--with-toolset="$optToolset" \
&& ./b2 $buildOpt -j $WM_NCOMPPROCS install \
&& echo "Built: boost"
) || {
echo "Error building: boost"
exit 1
}
fi
# Nothing left to build
if _foamIsSystem $cgalPACKAGE
then
echo "Using cgal-system (skip ThirdParty build of CGAL)"
exit 0
fi
# Retrieve boost version:
if [ -f "$boostInc/boost/version.hpp" ]
then
BOOST_VERSION=$(sed -ne 's/^ *# *define *BOOST_VERSION *\([0-9][0-9]*\).*$/\1/p' $boostInc/boost/version.hpp)
else
echo
echo "ERROR: boost does not appear to be installed, but is required to build CGAL"
echo " Change your settings, or disable entirely (with cgal-system, cgal-none, boost-none)"
echo "stopping build"
echo
exit 1
fi
#------------------------------------------------------------------------------
#
# Build CGAL
# For 64-bit:
# - system is normally built into 'lib64'
# - use Third-Party 'lib64' for consistency.
# CGAL-4.9 normally builds into 'lib64', older versions into 'lib'.
#
# CGAL_SOURCE_DIR : location of the original sources
# CGAL_BUILD_DIR : location of the build
# CGAL_ARCH_PATH : installation directory
CGAL_SOURCE_DIR=$sourceBASE/$cgalPACKAGE
CGAL_BUILD_DIR=$buildBASE/$cgalPACKAGE
: ${CGAL_ARCH_PATH:=$installBASE/$cgalPACKAGE} # Fallback
# gmp/mpfr are installed without compiler name
mpfrBASE=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH
# Enable/disable gmp/mpfr together
if _foamIsNone $gmpPACKAGE || _foamIsNone $mpfrPACKAGE
then
GMP_ARCH_PATH=none
MPFR_ARCH_PATH=none
elif _foamIsSystem $gmpPACKAGE || _foamIsSystem $mpfrPACKAGE
then
# May really be system, but could also by a central installation
# Ensure everything is accurately recorded. Resolve paths etc.
if [ -d "$GMP_ARCH_PATH" ]
then
if GMP_ARCH_PATH=$(cd $GMP_ARCH_PATH 2>/dev/null && pwd -P)
then
gmpPACKAGE=${GMP_ARCH_PATH##*/}
else
echo "ERROR: bad path for GMP_ARCH_PATH"
echo "stopping build"
exit 1
fi
else
GMP_ARCH_PATH=system
fi
if [ -d "$MPFR_ARCH_PATH" ]
then
if MPFR_ARCH_PATH=$(cd $MPFR_ARCH_PATH 2>/dev/null && pwd -P)
then
mpfrPACKAGE=${MPFR_ARCH_PATH##*/}
else
echo "ERROR: bad path for MPFR_ARCH_PATH"
echo "stopping build"
exit 1
fi
else
MPFR_ARCH_PATH=system
fi
else
GMP_ARCH_PATH=$mpfrBASE/$gmpPACKAGE
MPFR_ARCH_PATH=$mpfrBASE/$mpfrPACKAGE
fi
#------------------------------------------------------------------------------
cat</dev/null)
cat< $buildInfoFile
# Information from OpenFOAM build on '$(date)'
#
CGAL=${CGAL_ARCH_PATH##*/}
BOOST=${BOOST_ARCH_PATH##*/}
GMP=${GMP_ARCH_PATH##*/}
MPFR=${MPFR_ARCH_PATH##*/}
CGAL_VERSION=$CGAL_VERSION
BOOST_VERSION=$BOOST_VERSION
CGAL_lib=lib$WM_COMPILER_LIB_ARCH
BOOST_lib=lib$WM_COMPILER_LIB_ARCH
CGAL_HEADER_ONLY=${optHeadersOnly:-false}
BUILD_INFO
}
# Compare expected vs what is extracted as KEY=... in text
# $1 = key
# $2 = expected
# $3 = text to extract from
infoValueEq()
{
local val=$(echo "${3:-unset}" | sed -ne "s/^$1=//p")
if [ "$2" = "$val" ]
then
:
else
echo " $1=$2, previous build had $1='${val:-not-found}'"
return 1
fi
}
# Needs build
cgalIsCurrent()
{
# Only need VAR=... (also avoids embedded '#' that bothers some shells)
local info=$(sed -n -e '/^[A-Z]/p' $buildInfoFile 2>/dev/null)
[ -n "$info" ] || return 1
local libDirName="lib$WM_COMPILER_LIB_ARCH"
echo "checking information from existing build ..."
echo " ${CGAL_ARCH_PATH}"
infoValueEq CGAL "${CGAL_ARCH_PATH##*/}" "$info" || return 1
infoValueEq BOOST "${BOOST_ARCH_PATH##*/}" "$info" || return 1
infoValueEq GMP "${GMP_ARCH_PATH##*/}" "$info" || return 1
infoValueEq MPFR "${MPFR_ARCH_PATH##*/}" "$info" || return 1
infoValueEq BOOST_VERSION "${BOOST_VERSION}" "$info" || return 1
infoValueEq CGAL_lib "$libDirName" "$info" || return 1
infoValueEq BOOST_lib "$libDirName" "$info" || return 1
return 0
}
if cgalIsCurrent
then
echo " ${CGAL_ARCH_PATH##*/} build appears to be up-to-date - skipping"
echo
exit 0
fi
(
# Remove any existing build folder and recreate
if [ -d $CGAL_BUILD_DIR ]
then
echo "removing old build directory"
echo " $CGAL_BUILD_DIR"
rm -rf $CGAL_BUILD_DIR
fi
mkdir -p $CGAL_BUILD_DIR
cd $CGAL_BUILD_DIR || exit 1
export GIT_DIR=$CGAL_SOURCE_DIR/.git # Mask seeing our own git-repo
unset configBoost configGmp configMpfr
echo "----"
echo "Configuring $cgalPACKAGE with boost $BOOST_VERSION"
echo " Source : $CGAL_SOURCE_DIR"
echo " Build : $CGAL_BUILD_DIR"
echo " Target : $CGAL_ARCH_PATH"
# See http://doc.cgal.org/latest/Manual/installation.html
if _foamIsSystem $boostPACKAGE
then
# Tagged as 'system' but could actually point to a central location
if [ -d "$BOOST_ARCH_PATH/include" ]
then
echo " boost : ${BOOST_ARCH_PATH##*/}"
configBoost="-DBOOST_ROOT=$BOOST_ARCH_PATH"
else
echo " boost : system"
fi
## For system - possible that /usr/lib64 not being found?
## configBoost="-DBoost_LIBRARY_DIRS=$boostLib"
elif [ -d "$BOOST_ARCH_PATH" ]
then
echo " boost : $boostPACKAGE"
configBoost=$(cat <> $CGAL_ARCH_PATH/share/files
fi
done
# Record our build-status
recordCGALinfo
echo "Done CGAL"
)
#------------------------------------------------------------------------------