Commit f8ef85b7 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: split up internals of wmake/scripts/have_XXX functions

- adds some more flexibility
parent c1561256
......@@ -20,7 +20,8 @@
# ADIOS2_ARCH_PATH
#
# Functions provided
# have_adios2, no_adios2, echo_adios2, hint_adios2, query_adios2
# have_adios2, no_adios2, echo_adios2, query_adios2, search_adios2
# hint_adios2
#
# Variables set on success
# HAVE_ADIOS2
......@@ -33,7 +34,7 @@
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_adios2()
{
unset HAVE_ADIOS2 ADIOS2_INC_DIR ADIOS2_LIB_DIR
......@@ -66,43 +67,18 @@ INFORMATION
}
# Query settings
query_adios2()
{
local config="config.sh/adios2"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$settings"
_process_query adios2 "$ADIOS2_ARCH_PATH"
else
echo "(no $config settings)" 1>&2
echo "adios2=unknown"
fi
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_ADIOS2, ADIOS2_INC_DIR, ADIOS2_LIB_DIR
have_adios2()
search_adios2()
{
local warn # warn="==> skip adios2"
local config="config.sh/adios2"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$settings"
else
[ -n "$warn" ] && echo "$warn (no $config settings)"
return 2
fi
# Expected location, include/library names
local prefix="$ADIOS2_ARCH_PATH"
local incName="adios2.h"
local libName="libadios2"
local prefix="${1:-system}"
local header library
# ----------------------------------
......@@ -147,7 +123,45 @@ have_adios2()
}
# Reset variables
# Output as per search_* function
have_adios2()
{
local warn # warn="==> skip adios2"
local config="config.sh/adios2"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$file"
else
[ -n "$warn" ] && echo "$warn (no $config)"
return 2
fi
search_adios2 "$ADIOS2_ARCH_PATH"
}
# Query settings
query_adios2()
{
local config="config.sh/adios2"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$file"
_process_query adios2 "$ADIOS2_ARCH_PATH"
else
echo "(no $config)" 1>&2
echo "adios2=unknown"
fi
}
#------------------------------------------------------------------------------
# Reset
no_adios2
# Test/query
......
......@@ -21,7 +21,7 @@
# or config.sh/CGAL (when BOOST_ARCH_PATH is empty)
#
# Functions provided
# have_boost, no_boost, echo_boost, query_boost
# have_boost, no_boost, echo_boost, query_boost, search_boost
#
# Variables set on success
# HAVE_BOOST
......@@ -34,7 +34,7 @@
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_boost()
{
unset HAVE_BOOST BOOST_INC_DIR BOOST_LIB_DIR
......@@ -51,47 +51,18 @@ echo_boost()
}
# Query settings (from CGAL setup)
query_boost()
{
local config="config.sh/CGAL"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$settings"
_process_query boost "$BOOST_ARCH_PATH"
else
echo "(no $config settings)" 1>&2
echo "boost=unknown"
fi
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_BOOST, BOOST_INC_DIR, BOOST_LIB_DIR
have_boost()
search_boost()
{
local warn # warn="==> skip boost"
local config="config.sh/CGAL"
local settings
# Setup - current environment if set
if [ -z "$BOOST_ARCH_PATH" ]
then
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$settings"
else
[ -n "$warn" ] && echo "$warn (no $config settings)"
return 2
fi
fi
# Expected location, include/library names
local prefix="$BOOST_ARCH_PATH"
local incName="boost/version.hpp"
local libName="libboost_system"
local prefix="${1:-system}"
local header library
# ----------------------------------
......@@ -138,7 +109,49 @@ have_boost()
}
# Reset variables
# Output as per search_* function
have_boost()
{
local warn # warn="==> skip boost"
local config="config.sh/CGAL"
local file
# Setup - current environment if set
if [ -z "$BOOST_ARCH_PATH" ]
then
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$file"
else
[ -n "$warn" ] && echo "$warn (no $config)"
return 2
fi
fi
search_boost "$BOOST_ARCH_PATH"
}
# Query settings (from CGAL setup)
query_boost()
{
local config="config.sh/CGAL"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$file"
_process_query boost "$BOOST_ARCH_PATH"
else
echo "(no $config)" 1>&2
echo "boost=unknown"
fi
}
#------------------------------------------------------------------------------
# Reset
no_boost
# Test/query
......
......@@ -20,7 +20,7 @@
# config.sh/ccmio
#
# Functions provided
# have_ccmio, no_ccmio, echo_ccmio, query_ccmio
# have_ccmio, no_ccmio, echo_ccmio, query_ccmio, search_ccmio
#
# Variables set on success
# HAVE_CCMIO
......@@ -33,7 +33,7 @@
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_ccmio()
{
unset HAVE_CCMIO CCMIO_INC_DIR CCMIO_LIB_DIR
......@@ -50,44 +50,19 @@ echo_ccmio()
}
# Query settings
query_ccmio()
{
local config="config.sh/ccmio"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$settings"
_process_query ccmio "$CCMIO_ARCH_PATH"
else
echo "(no $config settings)" 1>&2
echo "ccmio=unknown"
fi
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_CCMIO, CCMIO_INC_DIR, CCMIO_LIB_DIR
have_ccmio()
search_ccmio()
{
local warn="==> skip ccmio"
local config="config.sh/ccmio"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$settings"
else
[ -n "$warn" ] && echo "$warn (no $config settings)"
return 2
fi
# Expected location, include/library names
# Link with static libccmio only (fewer issues)
local prefix="$CCMIO_ARCH_PATH"
local incName="libccmio/ccmio.h"
local libName="libccmio.a"
# Link with static libccmio only (fewer issues)
local prefix="${1:-system}"
local header library
# ----------------------------------
......@@ -153,7 +128,45 @@ have_ccmio()
}
# Reset variables
# Output as per search_* function
have_ccmio()
{
local warn="==> skip ccmio"
local config="config.sh/ccmio"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$file"
else
[ -n "$warn" ] && echo "$warn (no $config)"
return 2
fi
search_ccmio "$CCMIO_ARCH_PATH"
}
# Query settings
query_ccmio()
{
local config="config.sh/ccmio"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$file"
_process_query ccmio "$CCMIO_ARCH_PATH"
else
echo "(no $config)" 1>&2
echo "ccmio=unknown"
fi
}
#------------------------------------------------------------------------------
# Reset
no_ccmio
# Test/query
......
......@@ -34,7 +34,7 @@
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_cgal()
{
unset HAVE_CGAL CGAL_INC_DIR CGAL_LIB_DIR
......@@ -51,47 +51,18 @@ echo_cgal()
}
# Query settings (from CGAL setup)
query_cgal()
{
local config="config.sh/CGAL"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$settings"
_process_query cgal "$CGAL_ARCH_PATH"
else
echo "(no $config settings)" 1>&2
echo "cgal=unknown"
fi
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_CGAL, CGAL_INC_DIR, CGAL_LIB_DIR
have_cgal()
search_cgal()
{
local warn # warn="==> skip cgal"
local config="config.sh/CGAL"
local settings
# Setup - current environment if set
if [ -z "$CGAL_ARCH_PATH" ]
then
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$settings"
else
[ -n "$warn" ] && echo "$warn (no $config settings)"
return 2
fi
fi
# Expected location, include/library names
local prefix="$CGAL_ARCH_PATH"
local incName="CGAL/version.h"
local libName="libCGAL"
local prefix="${1:-system}"
local header library
# ----------------------------------
......@@ -132,13 +103,56 @@ have_cgal()
# OK
export HAVE_CGAL=true
export CGAL_FLAVOUR="${flavour:-library}"
export CGAL_ARCH_PATH="$prefix"
export CGAL_INC_DIR="${header%/*}" # Basename
export CGAL_LIB_DIR="${library%/*}" # Basename
}
# Reset variables
# Output as per search_* function
have_cgal()
{
local warn # warn="==> skip cgal"
local config="config.sh/CGAL"
local file
# Setup - current environment if set
if [ -z "$CGAL_ARCH_PATH" ]
then
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$file"
else
[ -n "$warn" ] && echo "$warn (no $config)"
return 2
fi
fi
search_cgal "$CGAL_ARCH_PATH"
}
# Query settings (from CGAL setup)
query_cgal()
{
local config="config.sh/CGAL"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$file"
_process_query cgal "$CGAL_ARCH_PATH"
else
echo "(no $config)" 1>&2
echo "cgal=unknown"
fi
}
#------------------------------------------------------------------------------
# Reset
no_cgal
# Test/query
......
......@@ -21,7 +21,7 @@
# CMAKE_ARCH_PATH that may specify a possible cmake/bin directory.
#
# Functions provided
# have_cmake, no_cmake, echo_cmake
# have_cmake, no_cmake, echo_cmake, search_cmake
#
# Variables set on success
# HAVE_CMAKE
......@@ -32,10 +32,10 @@
#
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_cmake()
{
unset HAVE_CMAKE CMAKE_EXE
unset HAVE_CMAKE CMAKE_EXE CMAKE_ARCH_PATH
}
......@@ -47,14 +47,15 @@ echo_cmake()
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# Try to locate cmake according to values specified in <etc/config.sh/cmake>
# 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()
search_cmake()
{
# Treat previous queries as "sticky"
if [ -n "$CMAKE_EXE" ]
......@@ -63,31 +64,18 @@ have_cmake()
return $?
fi
local config="config.sh/cmake"
unset CMAKE_ARCH_PATH
local settings candidate foundExe
local prefix="$1"
local 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
candidate="$prefix"/bin/cmake
if [ -z "$foundExe" ]
if [ -d "$prefix" ] && [ -f "$candidate" ] && [ -x "$candidate" ]
then
# Default: resolve from PATH
if candidate="$(command -v cmake 2>/dev/null)"
then
foundExe="$candidate"
fi
foundExe="$candidate"
elif candidate="$(command -v cmake 2>/dev/null)"
then
# Resolved from PATH
foundExe="$candidate"
fi
if [ -n "$foundExe" ]
......@@ -103,9 +91,33 @@ have_cmake()
}
# Reset variables
no_cmake
# Output as per search_* function
have_cmake()
{
# Treat previous queries as "sticky"
if [ -n "$CMAKE_EXE" ]
then
test "$CMAKE_EXE" != "false"
return $?
fi
local config="config.sh/cmake"
local file
unset CMAKE_ARCH_PATH
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config" 2>/dev/null)"
then
. "$file"
fi
search_cmake "$CMAKE_ARCH_PATH"
}
#------------------------------------------------------------------------------
# Reset
no_cmake
# Test/query
case "$1" in
......@@ -118,5 +130,4 @@ case "$1" in
;;
esac
#------------------------------------------------------------------------------
......@@ -21,7 +21,7 @@
# or config.sh/FFTW (when FFTW_ARCH_PATH is empty)
#
# Functions provided
# have_fftw, no_fftw, echo_fftw, query_fftw
# have_fftw, no_fftw, echo_fftw, query_fftw, search_fftw
#
# Variables set on success
# HAVE_FFTW
......@@ -34,7 +34,7 @@
#------------------------------------------------------------------------------
# Reset variables
# Reset
no_fftw()
{
unset HAVE_FFTW FFTW_INC_DIR FFTW_LIB_DIR
......@@ -51,47 +51,19 @@ echo_fftw()
}
# Query settings
query_fftw()
{
local config="config.sh/FFTW"
local settings
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$settings"
_process_query fftw "$FFTW_ARCH_PATH"
else
echo "(no $config settings)" 1>&2
echo "fftw=unknown"
fi
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_FFTW, FFTW_INC_DIR, FFTW_LIB_DIR
have_fftw()
search_fftw()
{
local warn # warn="==> skip fftw"
local config="config.sh/FFTW"
local settings
# Setup - current environment if set
if [ -z "$FFTW_ARCH_PATH" ]
then
if settings="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")