CONFIG: fixes for MacOS (#2555)

- introduce a FOAM_LD_LIBRARY_PATH variable to shadow
  DYLD_LIBRARY_PATH on MacOS.

  The DYLD_LIBRARY_PATH and LD_LIBRARY_PATH cannot be modified via sub
  shells etc when SIP is active. This helps circumvent these
  restrictions, which is obviously a hack, but seems to be required.

COMP: disable -ftrapping-math in geompack for MacOS
This commit is contained in:
Alexey Matveichev 2022-08-16 15:50:12 +02:00 committed by Mark Olesen
parent 5218bfd721
commit e827c117e3
14 changed files with 161 additions and 87 deletions

View File

@ -7,7 +7,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2021 OpenCFD Ltd.
# Copyright (C) 2017-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -48,26 +48,29 @@
# - Similarly for c-shell
# eval `foamCleanPath -csh-path dir1:dir2`
#
# For library paths, it is suggested to use -sh-lib, or -csh-lib.
# The will use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH on Darwin.
# For library paths, it is suggested to use -sh-lib, -env=-lib etc.
#
# On Darwin it uses FOAM_LD_LIBRARY_PATH instead of LD_LIBRARY_PATH.
# This should actually be DYLD_LIBRARY_PATH on Darwin, but setting that
# or LD_LIBRARY_PATH via a shell-script is disallowed when SIP is active.
#
#------------------------------------------------------------------------------
printHelp() {
cat<<USAGE
Usage: foamCleanPath [OPTION] ENV [filter] .. [filter]
Usage: foamCleanPath [OPTION] ENVNAME [filter] .. [filter]
foamCleanPath [OPTION] -env=name [filter] .. [filter]
options:
-env=NAME Evaluate NAME to obtain initial content,
Accepts "-env=-path", "-env=-lib" shortcuts for PATH
and LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on Darwin)
and LD_LIBRARY_PATH (FOAM_LD_LIBRARY_PATH on Darwin)
-sh=NAME Produce 'NAME=...' output for sh eval
-csh=NAME Produce 'setenv NAME ...' output for csh eval
-sh-env=NAME Same as -sh=NAME -env=NAME
-csh-env=NAME Same as -csh=NAME -env=NAME
-sh-path | -csh-path Same as -[c]sh-env=PATH
-sh-lib | -csh-lib Same as -[c]sh-env=LD_LIBRARY_PATH
or DYLD_LIBRARY_PATH on Darwin
(FOAM_LD_LIBRARY_PATH on Darwin)
-debug Print debug information to stderr
-strip Remove inaccessible directories
-verbose Report some progress (input, output, ...)
@ -81,7 +84,7 @@ Prints its argument (which should be a ':' separated list) cleansed from
Exit status
0 on success
1 general error
2 initial value of 'path' is empty
2 initial value of ENVNAME is empty
USAGE
exit 0 # A clean exit
@ -103,63 +106,69 @@ die()
#-------------------------------------------------------------------------------
# Input and outputs
unset dirList shellOutput shellFlavour
unset dirList shellFlavour shellOutput
unset optDebug optEnvName optStrip optVerbose
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
(-h | -help*)
printHelp
;;
-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '$1' missing an ENVNAME"
# Accept aliases
case "$name" in
(-path) name='PATH';;
(-lib)
case "$(uname -s 2>/dev/null)" in
(Darwin) name='DYLD_LIBRARY_PATH';;
(*) name='LD_LIBRARY_PATH';;
esac
(-csh-lib | -csh-path | -sh-lib | -sh-path)
shellFlavour="$1"
case "$1" in
(*-lib)
name='LD_LIBRARY_PATH'
if [ "$(uname -s 2>/dev/null)" = Darwin ]
then
name='FOAM_LD_LIBRARY_PATH' # Shadow DYLD_LIBRARY_PATH
fi
;;
(*-path)
name='PATH'
;;
esac
optEnvName="$name" # Use for input evaluation
;;
-csh-path | -sh-path)
shellFlavour="$1"
name='PATH'
optEnvName="$name" # Use for input evaluation
shellOutput="$name" # Use for output
;;
-csh-lib | -sh-lib)
shellFlavour="$1"
case "$(uname -s 2>/dev/null)" in
(Darwin) name='DYLD_LIBRARY_PATH';;
(*) name='LD_LIBRARY_PATH';;
esac
optEnvName="$name" # Use for input evaluation
shellOutput="$name" # Use for output
;;
-csh=* | -sh=* | -csh-env=* | -sh-env=*)
(-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '$1' missing an ENVNAME"
# Handle (-lib | -path) aliases
case "$1" in
(*=-lib)
name='LD_LIBRARY_PATH'
if [ "$(uname -s 2>/dev/null)" = Darwin ]
then
name='FOAM_LD_LIBRARY_PATH' # Shadow DYLD_LIBRARY_PATH
fi
;;
(*=-path)
name='PATH'
;;
esac
optEnvName="$name" # Use for input evaluation
;;
(-csh=* | -csh-env=* | -sh=* | -sh-env=*)
shellFlavour="$1"
name="${1#*=}"
[ -n "$name" ] || die "Option '$1' missing an ENVNAME"
# Accept aliases
case "$name" in
(-path) name='PATH';;
(-lib)
case "$(uname -s 2>/dev/null)" in
(Darwin) name='DYLD_LIBRARY_PATH';;
(*) name='LD_LIBRARY_PATH';;
esac
# Handle (-lib | -path) aliases
case "$1" in
(*=-lib)
name='LD_LIBRARY_PATH'
if [ "$(uname -s 2>/dev/null)" = Darwin ]
then
name='FOAM_LD_LIBRARY_PATH' # Shadow DYLD_LIBRARY_PATH
fi
;;
(*=-path)
name='PATH'
;;
esac
shellOutput="$name" # Use for output
@ -167,16 +176,16 @@ do
case "$1" in (*-env=*) optEnvName="$name";; esac
;;
-debug)
(-debug)
optDebug=true
;;
-strip)
(-strip)
optStrip=true
;;
-verbose)
(-verbose)
optVerbose=true
;;
*)
(*)
break
;;
esac

View File

@ -26,9 +26,9 @@
[ -d "$FOAM_TUTORIALS" ] || echo "No OpenFOAM tutorials? : $FOAM_TUTORIALS" 1>&2
# Darwin workaround - SIP clearing DYLD_LIBRARY_PATH variable
if [ -n "$FOAM_DYLD_LIBRARY_PATH" ] && [ -z "$DYLD_LIBRARY_PATH" ]
if [ -n "$FOAM_LD_LIBRARY_PATH" ] && [ -z "$DYLD_LIBRARY_PATH" ]
then
export DYLD_LIBRARY_PATH="$FOAM_DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
fi

View File

@ -49,8 +49,8 @@ then
foamClean="$WM_PROJECT_DIR/bin/foamCleanPath"
if [ -x "$foamClean" ]
then
cleaned=$($foamClean "$PATH" "$foamOldDirs") && PATH="$cleaned"
cleaned=$($foamClean "$LD_LIBRARY_PATH" "$foamOldDirs") \
cleaned=$($foamClean -env=PATH "$foamOldDirs") && PATH="$cleaned"
cleaned=$($foamClean -env=LD_LIBRARY_PATH "$foamOldDirs") \
&& LD_LIBRARY_PATH="$cleaned"
fi

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2017-2020 OpenCFD Ltd.
# Copyright (C) 2017-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -49,8 +49,8 @@ then
foamClean="$WM_PROJECT_DIR/bin/foamCleanPath"
if [ -x "$foamClean" ]
then
cleaned=$($foamClean "$PATH" "$foamOldDirs") && PATH="$cleaned"
cleaned=$($foamClean "$LD_LIBRARY_PATH" "$foamOldDirs") \
cleaned=$($foamClean -env=PATH "$foamOldDirs") && PATH="$cleaned"
cleaned=$($foamClean -env=LD_LIBRARY_PATH "$foamOldDirs") \
&& LD_LIBRARY_PATH="$cleaned"
fi

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd.
# Copyright (C) 2018-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -46,10 +46,10 @@ alias _foamAddMan 'setenv MANPATH \!*\:${MANPATH}'
# Special treatment for Darwin
# - DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
if ("${_foam_uname_s}" == "Darwin") then
alias _foamAddLib 'setenv DYLD_LIBRARY_PATH \!*\:${DYLD_LIBRARY_PATH}'
if ("${_foam_uname_s}" == 'Darwin') then
alias _foamAddLib 'if (-e \!*) setenv DYLD_LIBRARY_PATH \!*\:${DYLD_LIBRARY_PATH}; if (-e \!*) setenv FOAM_LD_LIBRARY_PATH \!*\:${FOAM_LD_LIBRARY_PATH}'
else
alias _foamAddLib 'setenv LD_LIBRARY_PATH \!*\:${LD_LIBRARY_PATH}'
alias _foamAddLib 'setenv LD_LIBRARY_PATH \!*\:${LD_LIBRARY_PATH}'
endif
# Prefix to LD_LIBRARY_PATH with additional checking

View File

@ -69,6 +69,13 @@ set archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER"
eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-path "$ParaView_DIR $archDir/ParaView- $archDir/qt-"`
eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-lib "$ParaView_DIR $archDir/ParaView- $archDir/qt-"`
# Darwin
switch ("$WM_ARCH")
case darwin*:
setenv DYLD_LIBRARY_PATH "${FOAM_LD_LIBRARY_PATH}"
breaksw
endsw
# Evaluate command-line parameters for ParaView
while ( $#argv > 0 )
switch ($argv[1])
@ -206,10 +213,11 @@ default:
if ( "$pv_libdirs" != "" ) then
switch ("$WM_ARCH")
case darwin*:
setenv DYLD_LIBRARY_PATH "${pv_libdirs}:$DYLD_LIBRARY_PATH"
setenv FOAM_LD_LIBRARY_PATH "${pv_libdirs}:${FOAM_LD_LIBRARY_PATH}"
setenv DYLD_LIBRARY_PATH "${FOAM_LD_LIBRARY_PATH}"
breaksw
default:
setenv LD_LIBRARY_PATH "${pv_libdirs}:$LD_LIBRARY_PATH"
setenv LD_LIBRARY_PATH "${pv_libdirs}:${LD_LIBRARY_PATH}"
breaksw
endsw
endif

View File

@ -148,16 +148,21 @@ endif
# Clean standard environment variables (PATH, MANPATH, [DY]LD_LIBRARY_PATH)
# - avoid local variables shadowing setenv variables
unset PATH MANPATH LD_LIBRARY_PATH DYLD_LIBRARY_PATH
unset PATH MANPATH LD_LIBRARY_PATH DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
if (! $?MANPATH ) setenv MANPATH
if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH
if ("${_foam_uname_s}" == "Darwin" ) then
if ("${_foam_uname_s}" == 'Darwin') then
if (! $?DYLD_LIBRARY_PATH ) setenv DYLD_LIBRARY_PATH
if (! $?FOAM_LD_LIBRARY_PATH ) setenv FOAM_LD_LIBRARY_PATH
else
if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH
endif
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean -lib "$foamOldDirs"
if ("${_foam_uname_s}" == 'Darwin') then
setenv DYLD_LIBRARY_PATH "${FOAM_LD_LIBRARY_PATH}"
endif
#------------------------------------------------------------------------------
@ -213,6 +218,9 @@ endif
_foamClean PATH
_foamClean MANPATH
_foamClean -lib
if ("${_foam_uname_s}" == 'Darwin') then
setenv DYLD_LIBRARY_PATH "${FOAM_LD_LIBRARY_PATH}"
endif
# Add trailing ':' for system manpages
if ( $?MANPATH ) then
@ -224,8 +232,8 @@ if ($?LD_LIBRARY_PATH) then
endif
# Darwin
if ($?DYLD_LIBRARY_PATH) then
if ("${DYLD_LIBRARY_PATH}" == "") unsetenv DYLD_LIBRARY_PATH
if ($?FOAM_LD_LIBRARY_PATH) then
if ("${FOAM_LD_LIBRARY_PATH}" == "") unsetenv DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
endif

View File

@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2016-2021 OpenCFD Ltd.
# Copyright (C) 2016-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -172,8 +172,10 @@ if ( $?foamClean ) then
if ($?LD_LIBRARY_PATH) then
eval `$foamClean -csh-env=LD_LIBRARY_PATH "$foamOldDirs"`
endif
if ($?DYLD_LIBRARY_PATH) then
eval `$foamClean -csh-env=DYLD_LIBRARY_PATH "$foamOldDirs"`
# Darwin
if ($?FOAM_LD_LIBRARY_PATH) then
eval `$foamClean -csh-env=FOAM_LD_LIBRARY_PATH "$foamOldDirs"`
setenv DYLD_LIBRARY_PATH ${FOAM_LD_LIBRARY_PATH}
endif
endif
@ -188,7 +190,7 @@ if ($?DYLD_LIBRARY_PATH) then
endif
# Remove any shadow env variables
unsetenv FOAM_DYLD_LIBRARY_PATH
unsetenv FOAM_DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
#------------------------------------------------------------------------------
# Cleanup aliases

View File

@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2017-2021 OpenCFD Ltd.
# Copyright (C) 2017-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -31,7 +31,7 @@
# _foamEtc : resolve etc files (silent or verbose)
# _foamAddPath : prepend to PATH
# _foamAddMan : prepend to MANPATH
# _foamAddLib : prepend to [DY]LD_LIBRARY_PATH
# _foamAddLib : prepend to {DY,FOAM_}LD_LIBRARY_PATH
# _foamAddLibAuto: prepend to lib64/lib resolved name
#
#------------------------------------------------------------------------------
@ -56,7 +56,7 @@ then
foamVar_name="$1"
shift
eval "$($foamClean -sh-env="$foamVar_name" "$@")"
unset "foamVar_name"
unset foamVar_name
}
# Echo values to stderr when FOAM_VERBOSE is on, no-op otherwise
@ -94,14 +94,18 @@ then
_foamAddLib()
{
case "$1" in (/?*)
export DYLD_LIBRARY_PATH="${1}${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}" ;;
if [ -e "$1" ]
then
export FOAM_LD_LIBRARY_PATH="${1}${FOAM_LD_LIBRARY_PATH:+:}${FOAM_LD_LIBRARY_PATH}"
export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
fi
esac
}
else
_foamAddLib()
{
case "$1" in (/?*)
export LD_LIBRARY_PATH="${1}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" ;;
export LD_LIBRARY_PATH="${1}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
esac
}
fi

View File

@ -76,6 +76,12 @@ eval \
"$($WM_PROJECT_DIR/bin/foamCleanPath -sh-lib \
$ParaView_DIR $archDir/ParaView- $archDir/qt-)"
# Darwin
case "$WM_ARCH" in
(darwin*)
export DYLD_LIBRARY_PATH="${FOAM_LD_LIBRARY_PATH}" ;;
esac
# Evaluate command-line parameters for ParaView
for i
do
@ -186,8 +192,12 @@ case "$ParaView_VERSION" in
then
case "$WM_ARCH" in
(darwin*)
export DYLD_LIBRARY_PATH="${pv_libdirs}:$DYLD_LIBRARY_PATH" ;;
(*) export LD_LIBRARY_PATH="${pv_libdirs}:$LD_LIBRARY_PATH" ;;
export FOAM_LD_LIBRARY_PATH="${pv_libdirs}:${FOAM_LD_LIBRARY_PATH}"
export DYLD_LIBRARY_PATH="${FOAM_LD_LIBRARY_PATH}"
;;
(*)
export LD_LIBRARY_PATH="${pv_libdirs}:${LD_LIBRARY_PATH}"
;;
esac
fi

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2019-2021 OpenCFD Ltd.
# Copyright (C) 2019-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -34,6 +34,12 @@ eval \
"$($WM_PROJECT_DIR/bin/foamCleanPath -sh-lib \
$ParaView_DIR $archDir/ParaView-)"
# Darwin
case "$WM_ARCH" in
(darwin*)
export DYLD_LIBRARY_PATH="${FOAM_LD_LIBRARY_PATH}" ;;
esac
#------------------------------------------------------------------------------
ParaView_DIR="$(command -v paraview 2>/dev/null)"

View File

@ -5,7 +5,7 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2018-2021 OpenCFD Ltd.
# Copyright (C) 2018-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -178,12 +178,23 @@ else
fi
# Clean standard environment variables
# Clean standard environment variables (PATH, MANPATH, [DY]LD_LIBRARY_PATH)
export PATH MANPATH
if [ "${_foam_uname_s}" = Darwin ]
then
export DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
else
export LD_LIBRARY_PATH
fi
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean -lib "$foamOldDirs"
if [ "${_foam_uname_s}" = Darwin ]
then
export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
fi
#------------------------------------------------------------------------------
# Base setup (OpenFOAM compilation), MPI and third-party packages
@ -237,11 +248,21 @@ fi
#------------------------------------------------------------------------------
# Remove duplicates from environment paths
export PATH MANPATH LD_LIBRARY_PATH
export PATH MANPATH
if [ "${_foam_uname_s}" = Darwin ]
then
export DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
else
export LD_LIBRARY_PATH
fi
_foamClean PATH
_foamClean MANPATH
_foamClean -lib
if [ "${_foam_uname_s}" = Darwin ]
then
export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
fi
# Add trailing ':' for system manpages
if [ -n "$MANPATH" ]

View File

@ -6,7 +6,7 @@
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2016-2021 OpenCFD Ltd.
# Copyright (C) 2016-2022 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@ -164,7 +164,9 @@ then
eval "$($foamClean -sh-env=PATH $foamOldDirs)"
eval "$($foamClean -sh-env=MANPATH $foamOldDirs)"
eval "$($foamClean -sh-env=LD_LIBRARY_PATH $foamOldDirs)"
eval "$($foamClean -sh-env=DYLD_LIBRARY_PATH $foamOldDirs)"
# Darwin
eval "$($foamClean -sh-env=FOAM_LD_LIBRARY_PATH $foamOldDirs)"
export DYLD_LIBRARY_PATH="$FOAM_LD_LIBRARY_PATH"
fi
[ -n "$MANPATH" ] || unset MANPATH
@ -172,7 +174,7 @@ fi
[ -n "$DYLD_LIBRARY_PATH" ] || unset DYLD_LIBRARY_PATH
# Remove any shadow env variables
unset FOAM_DYLD_LIBRARY_PATH
unset FOAM_DYLD_LIBRARY_PATH FOAM_LD_LIBRARY_PATH
#------------------------------------------------------------------------------
# Cleanup aliases and functions

View File

@ -6,6 +6,10 @@
# include <ctime>
# include <cstring>
#if defined(__APPLE__) && defined(__clang__)
#pragma clang fp exceptions(ignore)
#endif
using namespace std;
# include "geompack.H"