Commit cf5928c3 authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'config-improve-cmake-paraview-handling' into 'master'

ENH: improve cmake/ParaView config handling

See merge request !358
parents 8525d4a2 aafe674f
......@@ -107,6 +107,7 @@ Components specified by absolute path
-adios-path DIR Path for 'ADIOS2_ARCH_PATH' (overrides -adios)
-boost-path DIR Path for 'BOOST_ARCH_PATH' (overrides -boost)
-cgal-path DIR Path for 'CGAL_ARCH_PATH' (overrides -cgal)
-cmake-path DIR Path for 'CMAKE_ARCH_PATH' (overrides -cmake)
-fftw-path DIR Path for 'FFTW_ARCH_PATH' (overrides -fftw)
-kahip-path DIR Path for 'KAHIP_ARCH_PATH' (overrides -kahip)
-metis-path DIR Path for 'METIS_ARCH_PATH' (overrides -metis)
......@@ -662,8 +663,15 @@ CONFIG_CSH
-cmake)
# Replace cmake_version=...
optionValue=$(getOptionValue "$@")
replaceEtc config.sh/paraview cmake_version "$optionValue"
replaceEtc config.csh/paraview cmake_version "$optionValue"
replaceEtc config.sh/cmake cmake_version "$optionValue"
adjusted=true
shift
;;
-cmake-path)
# Replace CMAKE_ARCH_PATH=...
optionValue=$(getOptionValue "$@")
replaceEtc config.sh/cmake CMAKE_ARCH_PATH "$optionValue"
adjusted=true
shift
;;
......
......@@ -78,7 +78,6 @@ example,
ParaView_VERSION=5.6.0
ParaView_QT=qt-system
cmake_version=cmake-system
# END OF (NORMAL) USER EDITABLE PART
#------------------------------------------------------------------------------
......
......@@ -6,24 +6,22 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2016-2019 OpenCFD Ltd.
# Copyright (C) 2016-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
# config.csh/paraview
# - sourced by OpenFOAM-*/etc/cshrc or via foamPV alias
#
# Description
# Setup for PARAVIEW (partially cmake, qt too)
# Setup for PARAVIEW (partially QT too)
#
# To disable use of the PV_PLUGIN_PATH:
# ParaView_VERSION=none
#
# For system-wide installations:
# cmake_version=cmake-system
# ParaView_QT=qt-system
# ParaView_VERSION=system [EXPERIMENTAL]
#
......@@ -53,7 +51,6 @@
set ParaView_VERSION=5.6.3
set ParaView_QT=qt-system
set cmake_version=cmake-system
# END OF (NORMAL) USER EDITABLE PART
#------------------------------------------------------------------------------
......@@ -65,14 +62,13 @@ if (! $?WM_COMPILER_LIB_ARCH ) setenv WM_COMPILER_LIB_ARCH
# Compiler-specific location for ThirdParty installations
set archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER"
# Clean PATH and LD_LIBRARY_PATH
eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt- $archDir/cmake-"`
# Clean path and library path
eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt-"`
eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=LD_LIBRARY_PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt-"`
# Evaluate command-line parameters for ParaView and cmake
# Evaluate command-line parameters for ParaView
while ( $#argv > 0 )
switch ($argv[1])
case cmake*=*:
case ParaView*=*:
# name=value -> set name=value
eval "set $argv[1]"
......@@ -81,13 +77,6 @@ while ( $#argv > 0 )
shift
end
# ThirdParty cmake
set cmake="$archDir/$cmake_version"
if ( -r "$cmake/bin/cmake" ) then
# _foamAddPath not available when foamPV alias is used
setenv PATH "$cmake/bin:${PATH}"
endif
if ($?ParaView_VERSION) then
switch ("$ParaView_VERSION")
case "":
......@@ -106,13 +95,12 @@ case "none":
case "system":
# Obtain major.minor from `paraview --version`
set pv_api=`paraview --version | \
sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'`
set pv_api=`paraview --version | sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'`
if ( "${%pv_api}" ) then
setenv PV_PLUGIN_PATH "$FOAM_LIBBIN/paraview-$pv_api"
else
if ("${pv_api}" == "") then
unsetenv ParaView_DIR PV_PLUGIN_PATH
else
setenv PV_PLUGIN_PATH "$FOAM_LIBBIN/paraview-$pv_api"
endif
if ($?FOAM_VERBOSE && $?prompt) then
......@@ -138,9 +126,8 @@ default:
breaksw
case [0-9]*:
# Extract API from VERSION
set pv_api=`echo "$ParaView_VERSION" | \
sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'`
# Extract API from VERSION.
set pv_api=`echo "$ParaView_VERSION" | sed -ne 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/p'`
breaksw
endsw
......@@ -214,7 +201,6 @@ endif
unsetenv ParaView_VERSION ParaView_QT
unset archDir libDir
unset cmake cmake_version
unset pv_api pvLibDir pvPython qtDir
#------------------------------------------------------------------------------
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
# etc/config.sh/cmake
# - possibly sourced during make process only.
#
# Description
# CMAKE location (ThirdParty or otherwise) when not found via the PATH
# Does not affect the PATH, that is left for the caller
#
# For system-wide installations:
# cmake_version=cmake-system
# define CMAKE_ARCH_PATH
#
# Note
# No csh version. This file is only used during make processes.
#
#------------------------------------------------------------------------------
# USER EDITABLE PART: Changes made here may be lost with the next upgrade
cmake_version=cmake-system
export CMAKE_ARCH_PATH="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake_version"
# END OF (NORMAL) USER EDITABLE PART
#------------------------------------------------------------------------------
......@@ -16,7 +16,7 @@
# - sourced by OpenFOAM-*/etc/bashrc or via foamPV alias
#
# Description
# Setup for PARAVIEW (partially cmake, qt too)
# Setup for PARAVIEW (partially QT too)
#
# To disable use of the PV_PLUGIN_PATH:
# ParaView_VERSION=none
......@@ -55,7 +55,6 @@
ParaView_VERSION=5.6.3
ParaView_QT=qt-system
cmake_version=cmake-system
# END OF (NORMAL) USER EDITABLE PART
#------------------------------------------------------------------------------
......@@ -64,34 +63,26 @@ pv_api=auto # Either auto or pair of (major.minor) digits
# Compiler-specific location for ThirdParty installations
archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER"
# Clean PATH and LD_LIBRARY_PATH
# Clean path and library path
eval \
"$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=PATH \
$ParaView_DIR $archDir/ParaView- $archDir/qt- $archDir/cmake-)"
$ParaView_DIR $archDir/ParaView- $archDir/qt-)"
eval \
"$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=LD_LIBRARY_PATH \
$ParaView_DIR $archDir/ParaView- $archDir/qt-)"
# Evaluate command-line parameters for ParaView and cmake
# Evaluate command-line parameters for ParaView
for i
do
case "$i" in
(cmake*=* | ParaView*=*)
(ParaView*=*)
# name=value -> export name=value
eval "export $i"
;;
esac
done
# ThirdParty cmake
cmake="$archDir/$cmake_version"
if [ -r "$cmake/bin/cmake" ]
then
# _foamAddPath not available when foamPV function is used
PATH="$cmake/bin:$PATH"
fi
case "$ParaView_VERSION" in
('')
# empty - do nothing
......@@ -206,7 +197,6 @@ then
fi
unset archDir libDir
unset cmake cmake_version
unset pv_api pvLibDir pvPython qtDir
#------------------------------------------------------------------------------
......@@ -5,11 +5,10 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2019 OpenCFD Ltd.
# Copyright (C) 2019-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
# etc/config.sh/paraview-system
......@@ -26,7 +25,7 @@
# Compiler-specific location for ThirdParty installations
archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER"
# Clean PATH and LD_LIBRARY_PATH
# Clean path and library path
eval \
"$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=PATH \
$ParaView_DIR $archDir/ParaView-)"
......
......@@ -16,7 +16,16 @@
# Description
# Helper functions for CMake
#
# Environment
# Consider CMAKE_INSTALL_PREFIX as a reserved name, although it is not
# set/unset here.
#
# Files
# Uses etc/config.sh/cmake (if it exists) for the
# CMAKE_ARCH_PATH that may specify a possible cmake/bin directory.
#
#------------------------------------------------------------------------------
. ${WM_PROJECT_DIR:?}/wmake/scripts/have_cmake
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
# Export compiler information for cmake
......@@ -29,64 +38,92 @@ export CXXFLAGS="$(wmake -show-cxxflags)"
#------------------------------------------------------------------------------
#
# Check sentinel file(s) to handle paraview / vtk version changes
# Save build/configure parameter information (dependency) into sentinel file
#
sameDependency()
# 1 - sentinelFile
# 2... build/configure parameters
#
storeDependency()
{
local depend="$1"
local sourceDir="$2"
local objectsDir sentinel prev
local sentinel="$1"
local depend
shift
# Where generated files are stored
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
sentinel="$objectsDir/ThirdParty"
if [ -n "$sentinel" ]
then
mkdir -p "$(dirname "$sentinel")"
echo "$sentinel"
echo '# Build/configure parameters' >| "$sentinel"
if read -r prev 2>/dev/null < $sentinel
then
if [ "$prev" = "$depend" ]
then
return 0
else
echo "${depend%=*} changed between builds" 1>&2
return 1
fi
elif [ -f "$objectsDir/CMakeCache.txt" ]
then
echo "previous build was incomplete" 1>&2
return 1
else
return 0
for depend
do
echo "-- $depend"
done >> "$sentinel"
fi
return 0
}
#
# Save dependency information into sentinel file
# Check sentinel file(s) to handle changed build/configure parameters
# such as paraview / vtk version changes
#
storeDependency()
# 1 - sourceDir
# 2... build/configure parameters
#
sameDependency()
{
local depend="$1"
local sentinel="$2"
local sourceDir="$1"
shift
local depend objectsDir
local compare=0
if [ -n "$sentinel" ]
# Where generated files are stored
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
local sentinel="$objectsDir/ThirdParty"
if [ -f "$sentinel" ]
then
mkdir -p "$(dirname "$sentinel")"
echo "$depend" >| "$sentinel"
# Create an .update version
storeDependency "${sentinel}.update" $@
cmp "${sentinel}" "${sentinel}.update" >/dev/null 2>&1
compare=$?
if [ "$compare" -ne 0 ]
then
echo "build/configure parameters changed between builds" 1>&2
fi
else
# No sentinel file: First time, or failed compilation?
if [ -f "$objectsDir/CMakeCache.txt" ]
then
echo "previous build was incomplete" 1>&2
compare=1
fi
fi
return 0
echo "$sentinel"
return "$compare"
}
# CMake with output suppressed according to WM_QUIET
_cmake()
# Resolve the location of cmake (if needed) and call with output
# suppressed according to WM_QUIET
call_cmake()
{
echo "cmake..."
if [ -n "$WM_QUIET" ]
if have_cmake
then
cmake -DCMAKE_RULE_MESSAGES=OFF $@ >/dev/null
if [ -n "$WM_QUIET" ]
then
echo "cmake..."
"$CMAKE_EXE" -DCMAKE_RULE_MESSAGES=OFF $@ >/dev/null
else
echo "cmake $@"
"$CMAKE_EXE" $@
fi
else
cmake $@
return 1
fi
}
......@@ -109,12 +146,13 @@ cmakeVersioned()
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
# Version changed
sentinel=$(sameDependency "$depend" "$sourceDir") || \
sentinel=$(sameDependency "$sourceDir" "$depend" $@) || \
rm -rf "$objectsDir" 2>/dev/null
mkdir -p "$objectsDir" \
&& (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make) \
&& storeDependency "$depend" "$sentinel"
&& ( cd "$objectsDir" && call_cmake "$@" "$sourceDir" && \
make "-j${WM_NCOMPPROCS:-1}" ) \
&& storeDependency "$sentinel" "$depend" $@
}
......@@ -135,12 +173,13 @@ cmakeVersionedInstall()
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
# Version changed
sentinel=$(sameDependency "$depend" "$sourceDir") || \
sentinel=$(sameDependency "$sourceDir" "$depend" $@) || \
rm -rf "$objectsDir" 2>/dev/null
mkdir -p "$objectsDir" \
&& (cd "$objectsDir" && _cmake "$@" "$sourceDir" && make install) \
&& storeDependency "$depend" "$sentinel"
&& ( cd "$objectsDir" && call_cmake "$@" "$sourceDir" && \
make "-j${WM_NCOMPPROCS:-1}" install ) \
&& storeDependency "$sentinel" "$depend" $@
}
......@@ -162,12 +201,12 @@ wmakeVersioned()
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
# Version changed
sentinel=$(sameDependency "$depend" "$sourceDir") || \
sentinel=$(sameDependency "$sourceDir" "$depend" $@) || \
rm -rf "$objectsDir" 2>/dev/null
mkdir -p "$objectsDir" \
&& wmake "$@" \
&& storeDependency "$depend" "$sentinel"
&& storeDependency "$sentinel" "$depend" $@
}
......
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# have_cmake
#
# Description
# Locate CMAKE executable
#
# Files
# Uses etc/config.sh/cmake (if it exists) for the
# CMAKE_ARCH_PATH that may specify a possible cmake/bin directory.
#
# Functions provided
# have_cmake, no_cmake, echo_cmake
#
# Variables set on success
# HAVE_CMAKE
# CMAKE_EXE
#
# When properly resolved, CMAKE_EXE will be an absolute path to the
# cmake executable. On failure it will point to 'false'
#
#------------------------------------------------------------------------------
# Reset variables
no_cmake()
{
unset HAVE_CMAKE CMAKE_EXE
}
# Report
echo_cmake()
{
echo cmake="${CMAKE_EXE:-false}"
echo version="$("${CMAKE_EXE:-false}" --version | sed -ne '1s/^.*version *//p')"
}
#
# Try to locate cmake according to values specified in <etc/config.sh/cmake>
# or just use what is found on the path.
#
# On success: return the resolved value as output.
# On failure: set executable as "false" and return with 1
#
have_cmake()
{
# Treat previous queries as "sticky"
if [ -n "$CMAKE_EXE" ]
then
test "$CMAKE_EXE" != "false"
return $?
fi
local config="config.sh/cmake"
unset CMAKE_ARCH_PATH
local settings candidate foundExe
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config" 2>/dev/null)"
then
. "$settings"
if [ -d "$CMAKE_ARCH_PATH" ]
then
candidate="$CMAKE_ARCH_PATH"/bin/cmake
if [ -f "$candidate" ] && [ -x "$candidate" ]
then
foundExe="$candidate"
fi
fi
fi
if [ -z "$foundExe" ]
then
# Default: resolve from PATH
if candidate="$(command -v cmake 2>/dev/null)"
then
foundExe="$candidate"
fi
fi
if [ -n "$foundExe" ]
then
# OK
export HAVE_CMAKE=true
export CMAKE_EXE="$foundExe"
else
# Failure
export CMAKE_EXE="false" # Avoid repeated calls?
return 2
fi
}
# Reset variables
no_cmake
# Test/query
case "$1" in
-test)
have_cmake
echo_cmake
;;
-query)
## query_cmake
;;
esac
#------------------------------------------------------------------------------
......@@ -18,8 +18,8 @@
# Setup of variables for creating ParaView plugins
#
# Requires
# ParaView_DIR (unless system)
# PV_PLUGIN_PATH
# ParaView_DIR (unless system)
# PV_PLUGIN_PATH (or rely on automatic mechanism)
#
# Provides Functions
# get_pvplugin_api, have_pvplugin_support, no_paraview, echo_paraview
......@@ -85,22 +85,59 @@ cmakePvInstall()
cmakeVersionedInstall "ParaView_DIR=$ParaView_DIR" "$@"
}
#
# Build library - use sentinel file(s) to handle paraview version changes
# Some difficulty handling different installation options as well
# as wmake options, so only handle build/configure information for now
#
# 1 - libName
# 2... build/configure information
#
# Similar to wmakeVersioned
wmakeLibPv()
{
local depend="ParaView_DIR=$ParaView_DIR"
local sentinel libName
local libName="$1"
shift 1
local sentinel
for libName
do
sentinel=$(sameDependency "$depend" "$libName") || \
wclean $libName
sentinel=$(sameDependency "$libName" "$depend" $@) || \
wclean "$libName"
wmake $targetType $libName \
&& storeDependency "$depend" "$sentinel"
done
wmake $targetType "$libName" \
&& storeDependency "$sentinel" "$depend" $@
}
# Get ParaView API from given path.
# Eg, "/path/paraview-dir/paraview-5.6" -> "5.6"
#
# Or the output from `paraview --version`
# Eg, "paraview version 5.6.3" -> "5.6"
#
# 1 - the input path ending with paraview-x.y, or paraview --version information
#
# On success, return 0 and echo value
#
get_pvapi()
{
local pv_api