#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see .
#
# 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
#------------------------------------------------------------------------------
# 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.so" ]
then
echo " CGAL headers in $dir/include"
echo " CGAL libs in $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.so" ]
then
echo " BOOST headers in $root/include"
echo " BOOST libs in $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 # Purge current values
# CGAL, boost and gmp/mpfr versions from OpenFOAM etc/config.sh files.
# Get compiler first and let CGAL config override GMP (eg, when there is no GMP)
_foamEtc config.sh/compiler
_foamEtc config.sh/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)
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()
{
local info=$(cat $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
echo " system : boost"
# Tagged as 'system' but could actually point to a central location
if [ -d "$BOOST_ARCH_PATH/include" ]
then
configBoost="-DBOOST_ROOT=$BOOST_ARCH_PATH"
fi
## For system - possible that /usr/lib64 not being found?
## configBoost="-DBoost_LIBRARY_DIRS=$boostLib"
elif [ -d "$BOOST_ARCH_PATH" ]
then
echo " ThirdParty : boost"
configBoost=$(cat <> $CGAL_ARCH_PATH/share/files
fi
done
# record our build-status
recordCGALinfo
echo "Done CGAL"
)
#------------------------------------------------------------------------------