Files
ThirdParty-common/makeCGAL
Mark Olesen 816173b7c4 CONFIG: update versions
ENH: add support of additional configure options to some make scripts

- remove hard-coded --verbs from makeOPENMPI in favour of letting the
  user provide it via the command-line for makeOPENMPI.

  eg,  makeOPENMPI openmpi-1.10.6 -- --with-verbs=DIRECTORY ...
2017-12-15 11:21:31 +01:00

494 lines
14 KiB
Bash
Executable File

#!/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, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# 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 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.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 # 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<<USAGE
usage: ${0##*/} [OPTION] [CGAL-VERSION] [boost-VERSION] [gmp-VERSION] [mpfr-VERSION]
options:
-cmake PATH with cmake from the path given
-gcc force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
-no-lib compile CGAL for use in headers only mode (since CGAL 4.9)
-system use system versions for boost/gmp/mpfr
-help
* build CGAL with
${cgalPACKAGE:-'unspecified CGAL version'}
$boostPACKAGE
$gmpPACKAGE
$mpfrPACKAGE
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,
${0##*/} boost-system gmp-system
Use gmp-none to disable use of gmp/mpfr (eg, not available)
USAGE
exit 1
}
#------------------------------------------------------------------------------
# Compiler settings for CMake/configure
[ -n "$WM_CC" ] && export CC="$WM_CC"
[ -n "$WM_CXX" ] && export CXX="$WM_CXX"
unset optHeadersOnly
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
'') ;; # Ignore empty
-h | -help) usage ;;
-gcc) useGcc ;;
-cmake)
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
CMAKE_PATH="${2%%/}"
shift
;;
-sys*)
gmpPACKAGE="gmp-system"
mpfrPACKAGE="mpfr-system"
boostPACKAGE="boost-system"
unset BOOST_ARCH_PATH # avoid inconsistency
;;
-no-lib)
optHeadersOnly=true
;;
gmp-[4-9]* | gmp-system | gmp-none)
gmpPACKAGE="${1%%/}"
;;
mpfr-[2-9]* | mpfr-system | mpfr-none)
mpfrPACKAGE="${1%%/}"
;;
CGAL-[0-9]*)
cgalPACKAGE="${1%%/}"
unset CGAL_ARCH_PATH # avoid inconsistency
;;
boost-[0-9]* | boost_[0-9]* | boost-system )
boostPACKAGE="${1%%/}"
unset BOOST_ARCH_PATH # avoid inconsistency
;;
*)
die "unknown option/argument: '$1'"
;;
esac
shift
done
[ -n "$cgalPACKAGE" ] || die "The cgal-VERSION was not specified"
# Nothing to build
if _foamIsNone $boostPACKAGE
then
echo "Using boost-none (skip ThirdParty build of BOOST/CGAL)"
exit 0
fi
if _foamIsNone $cgalPACKAGE
then
echo "Using cgal-none (skip ThirdParty build of CGAL)"
exit 0
fi
#------------------------------------------------------------------------------
#
# Build Boost
# For 64-bit:
# - system is normally built into 'lib64'
# - use Third-Party 'lib64' for consistency.
# Boost 1_62_0 and older normally build into 'lib'.
#
# BOOST_ARCH_PATH : installation directory
# BOOST_SOURCE_DIR : location of the original sources
BOOST_SOURCE_DIR=$sourceBASE/$boostPACKAGE
: ${BOOST_ARCH_PATH:=$installBASE/$boostPACKAGE} # Fallback
boostInc="$BOOST_ARCH_PATH/include"
boostLib="$BOOST_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH"
if _foamIsSystem $boostPACKAGE
then
echo "Using boost-system (skip ThirdParty build of BOOST)"
# Tagged as 'system' but could actually point to a central location
[ -d "$BOOST_ARCH_PATH/include" ] || {
boostInc="/usr/include"
boostLib="/usr/lib$WM_COMPILER_LIB_ARCH"
}
elif [ -f "$boostInc/boost/version.hpp" ]
then
echo "Using $boostPACKAGE"
else
echo "Starting build: $boostPACKAGE"
echo
# Absolute path for --libdir
(
cd $BOOST_SOURCE_DIR || exit 1
export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
rm -rf $BOOST_ARCH_PATH
./bootstrap.sh \
--prefix=$BOOST_ARCH_PATH \
--libdir=$boostLib \
--with-libraries=thread \
--with-libraries=system \
&& ./bjam toolset=$WM_CC -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
#------------------------------------------------------------------------------
cat<<SUMMARY
CGAL configuration
------------------
CGAL = $cgalPACKAGE
BOOST = $boostPACKAGE
GMP = $gmpPACKAGE
MPFR = $mpfrPACKAGE
------------------
SUMMARY
#------------------------------------------------------------------------------
#
# 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
installBASE=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH
GMP_ARCH_PATH=$installBASE/$gmpPACKAGE
MPFR_ARCH_PATH=$installBASE/$mpfrPACKAGE
# Enable/disable gmp/mpfr together
if _foamIsNone $gmpPACKAGE || _foamIsNone $mpfrPACKAGE
then
GMP_ARCH_PATH=none
MPFR_ARCH_PATH=none
elif _foamIsSystem $GMP_ARCH_PATH || _foamIsSystem $MPFR_ARCH_PATH
then
GMP_ARCH_PATH=system # for an accurate record
MPFR_ARCH_PATH=system
fi
#
# build information recorded for later use
#
buildInfoFile=$CGAL_ARCH_PATH/share/openfoam-build
recordCGALinfo()
{
CGAL_VERSION=$(sed -ne 's/^ *# *define *CGAL_VERSION_NR *\([0-9][0-9]*\).*$/\1/p' $CGAL_ARCH_PATH/include/CGAL/version.h 2>/dev/null)
cat<<BUILD_INFO > $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 <<CMAKE_OPTIONS
-DBoost_INCLUDE_DIR=$boostInc
-DBoost_LIBRARY_DIRS=$boostLib
-DBoost_THREAD_LIBRARY=$boostLib/libboost_thread.so
-DBoost_THREAD_LIBRARY_RELEASE=$boostLib/libboost_thread.so
-DBoost_SYSTEM_LIBRARY=$boostLib/libboost_system.so
-DBoost_SYSTEM_LIBRARY_RELEASE=$boostLib/libboost_system.so
-DBoost_VERSION=$BOOST_VERSION
CMAKE_OPTIONS
)
fi
if _foamIsSystem $GMP_ARCH_PATH
then
echo " system : gmp"
elif _foamIsNone $GMP_ARCH_PATH
then
echo " disabled : gmp"
configGmp="-DCGAL_DISABLE_GMP=TRUE" # Also used for mpfr
elif [ -d "$GMP_ARCH_PATH" ]
then
echo " ThirdParty : gmp"
configGmp=$(cat <<CMAKE_OPTIONS
-DGMP_INCLUDE_DIR=$GMP_ARCH_PATH/include
-DGMP_LIBRARIES_DIR=$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
-DGMP_LIBRARIES=$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libgmp.so
-DGMPXX_INCLUDE_DIR=$GMP_ARCH_PATH/include
-DGMPXX_LIBRARIES=$GMP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libgmpxx.so
CMAKE_OPTIONS
)
else
echo " system : gmp (did not find $GMP_ARCH_PATH)"
fi
if _foamIsSystem $MPFR_ARCH_PATH
then
echo " system : mpfr"
elif _foamIsNone $MPFR_ARCH_PATH
then
echo " disabled : mpfr"
configGmp="-DCGAL_DISABLE_GMP=TRUE" # Also used for mpfr
elif [ -d "$MPFR_ARCH_PATH" ]
then
echo " ThirdParty : mpfr"
configMpfr=$(cat <<CMAKE_OPTIONS
-DMPFR_INCLUDE_DIR=$MPFR_ARCH_PATH/include
-DMPFR_LIBRARIES_DIR=$MPFR_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
-DMPFR_LIBRARIES=$MPFR_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmpfr.so
CMAKE_OPTIONS
)
else
echo " system : mpfr (did not find $MPFR_ARCH_PATH)"
fi
cmake=$(findCMake)
# For CGAL < 4.9, for installation into lib64/, not lib/
# Name only (not path) for CGAL_INSTALL_LIB_DIR
echo "----"
set -x
$cmake \
-DCMAKE_INSTALL_PREFIX=$CGAL_ARCH_PATH \
-DCGAL_INSTALL_LIB_DIR=lib$WM_COMPILER_LIB_ARCH \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_CGAL_ImageIO=OFF \
-DWITH_CGAL_Qt5=OFF \
${optHeadersOnly:+-DCGAL_HEADER_ONLY=TRUE} \
$configBoost $configGmp $configMpfr \
${WM_QUIET:+-DCMAKE_RULE_MESSAGES=OFF} \
$CGAL_SOURCE_DIR \
&& set +x \
&& make -j $WM_NCOMPPROCS \
&& make install || exit 1
echo "----"
echo "create '\$CGAL_ARCH_PATH/share/files'"
echo "----"
mkdir -p $CGAL_ARCH_PATH/share/src
rm -f $CGAL_ARCH_PATH/share/files
for i in assertions.cpp io.cpp MP_Float.cpp Random.cpp
do
if [ -e "$CGAL_SOURCE_DIR/src/CGAL/$i" ]
then
\cp $CGAL_SOURCE_DIR/src/CGAL/$i $CGAL_ARCH_PATH/share/src/
echo "\${CGAL_ARCH_PATH}/share/src/$i" >> $CGAL_ARCH_PATH/share/files
fi
done
# record our build-status
recordCGALinfo
echo "Done CGAL"
)
#------------------------------------------------------------------------------