Files
ThirdParty-common/makeCGAL
mark 7623d184cd CONFIG: build boost, CGAL into lib64/ (issue #8)
- On 64-bit systems, the library locations for boost, CGAL are changing.

* Boost 1_62_0 and older build into 'lib/'.
* CGAL-4.9 builds into 'lib64/', older versions into 'lib/'.

Future-proof things by using lib$WM_COMPILER_LIB_ARCH for boost and
CGAL targets.
2016-11-04 11:29:47 +01:00

427 lines
12 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 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 <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
#
#------------------------------------------------------------------------------
# Get CGAL, boost and gmp/mpfr versions
. $WM_PROJECT_DIR/etc/config.sh/functions
unset -f _foamAddPath _foamAddLib _foamAddMan # get settings only
_foamSource $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/CGAL)
_foamSource $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/compiler)
boostPACKAGE=${boost_version:-boost-system}
gmpPACKAGE=${gmp_version:-gmp-system}
mpfrPACKAGE=${mpfr_version:-mpfr-system}
cgalPACKAGE=$cgal_version
#------------------------------------------------------------------------------
# Run from third-party directory only
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" || {
echo "Error: Current directory is not \$WM_THIRD_PARTY_DIR"
echo " The environment variables are inconsistent with the installation."
echo " Check the OpenFOAM entries in your dot-files and source them."
exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
Script="${0##*/}"
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
usage: $Script [OPTION] [CGAL-VERSION] [boost-VERSION] [gmp-VERSION] [mpfr-VERSION]
options:
-gcc force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
-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,
$Script boost-system gmp-system
USAGE
exit 1
}
#------------------------------------------------------------------------------
# Ensure CMake gets the correct C/C++ compiler
[ -n "$WM_CC" ] && export CC="$WM_CCX"
[ -n "$WM_CXX" ] && export CXX="$WM_CXX"
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
;;
'')
# discard empty arguments
;;
-gcc)
export CC=gcc # use gcc/g++
export CXX=g++
;;
-sys*)
gmpPACKAGE="gmp-system"
mpfrPACKAGE="mpfr-system"
boostPACKAGE="boost-system"
;;
gmp-[4-9]* | gmp-system)
gmpPACKAGE="${1%%/}"
;;
mpfr-[2-9]* | mpfr-system)
mpfrPACKAGE="${1%%/}"
;;
CGAL-[0-9]*)
cgalPACKAGE="${1%%/}"
;;
boost-[0-9]* | boost_[0-9]* | boost-system )
boostPACKAGE="${1%%/}"
;;
*)
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_SOURCE_DIR : location of the original sources
BOOST_ARCH_PATH=$installBASE/$boostPACKAGE
BOOST_SOURCE_DIR=$WM_THIRD_PARTY_DIR/$boostPACKAGE
boostInc="$BOOST_ARCH_PATH/include"
boostLib="$BOOST_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH"
if _foamIsSystem $BOOST_ARCH_PATH
then
echo "Using boost-system (skip ThirdParty build of BOOST)"
boostInc="/usr/include"
boostLib="/usr/lib$WM_COMPILER_LIB_ARCH"
elif [ -f "$boostInc/boost/version.hpp" -a -d "$boostLib" ]
then
echo "Using $boostPACKAGE"
else
echo "Starting build: $boostPACKAGE"
echo
# Absolute path for --libdir
(
cd $BOOST_SOURCE_DIR || exit 1
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_BINARY_DIR : location of the build
# CGAL_DIR : location of the installed program
CGAL_SOURCE_DIR=$WM_THIRD_PARTY_DIR/$cgalPACKAGE
CGAL_BINARY_DIR=$buildBASE/$cgalPACKAGE
CGAL_ARCH_PATH=$installBASE/$cgalPACKAGE
CGAL_DIR=$CGAL_ARCH_PATH
#
# gmp/mpfr 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
#
# 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
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_BINARY_DIR ]
then
echo "removing old build directory"
echo " $CGAL_BINARY_DIR"
rm -rf $CGAL_BINARY_DIR
fi
mkdir -p $CGAL_BINARY_DIR
cd $CGAL_BINARY_DIR || exit 1
unset configBoost configGmp configMpfr
echo "----"
echo "Configuring $cgalPACKAGE with boost $BOOST_VERSION"
echo " Source : $CGAL_SOURCE_DIR"
echo " Build : $CGAL_BINARY_DIR"
echo " Target : $CGAL_DIR"
if [ -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
)
else
echo " system : boost"
configBoost=$(cat <<CMAKE_OPTIONS
-DBOOST_LIBRARYDIR=$boostLib
CMAKE_OPTIONS
)
fi
if [ -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"
fi
if [ -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"
fi
# 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_Qt5=OFF \
$configBoost $configGmp $configMpfr \
$CGAL_SOURCE_DIR \
&& make -j $WM_NCOMPPROCS \
&& make install || exit 1
set +x
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"
)
#------------------------------------------------------------------------------