COMP: add rpath information to MacOS compilation rules (#2948)
- since the Apple SIP (System Integrity Protection) clears environment variables such as DYLD_LIBRARY_PATH, a number of workarounds have been used to provide shadow values. However, for a more robust installation using -rpath at compilation time appears to be the better solution. In addition to the usual -rpath specification with absolute file paths, MacOS supports (@loader_path, @executable_path) as well. Now default to link with rpath information for MacOS, which can be disabled by adding `~rpath` in WM_COMPILE_CONTROL Explicit library paths handled: - FOAM_FOAM_EXT_LIBBIN, FOAM_EXT_LIBBIN/FOAM_MPI The executable rpaths are handled assuming a structure of install-path/bin install-path/lib/$(FOAM_MPI) install-path/lib Absolute compile-time paths for FOAM_USER_LIBBIN, FOAM_SITE_LIBBIN and FOAM_LIBBIN are not handled since these are either too fragile (FOAM_USER_LIBBIN and FOAM_SITE_LIBBIN values) or covered via @loader_path anyhow (FOAM_LIBBIN). Since the value of FOAM_MPI is a compile-time value, this rpath treatment makes the installation less suitable for runtime changes to the MPI vendor/version. Note: no rpath added for c-only compilations since there are currently no c-only libraries or executables with dynamic loading
This commit is contained in:
parent
3630333526
commit
e4f2efec18
@ -6,7 +6,7 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# Copyright (C) 2016-2022 OpenCFD Ltd.
|
# Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
@ -87,6 +87,7 @@ export WM_COMPILE_OPTION=Opt
|
|||||||
# +lld : with lld linker (with clang)
|
# +lld : with lld linker (with clang)
|
||||||
# +mold : with mold linker (with clang)
|
# +mold : with mold linker (with clang)
|
||||||
# ~libz : without libz compression
|
# ~libz : without libz compression
|
||||||
|
# ~rpath : without rpath handling [MacOS]
|
||||||
# +openmp : with openmp
|
# +openmp : with openmp
|
||||||
# ~openmp : without openmp
|
# ~openmp : without openmp
|
||||||
# +ccache : use ccache
|
# +ccache : use ccache
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# Copyright (C) 2016-2022 OpenCFD Ltd.
|
# Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
@ -87,6 +87,7 @@ setenv WM_COMPILE_OPTION Opt
|
|||||||
# +lld : with lld linker (with clang)
|
# +lld : with lld linker (with clang)
|
||||||
# +mold : with mold linker (with clang)
|
# +mold : with mold linker (with clang)
|
||||||
# ~libz : without libz compression
|
# ~libz : without libz compression
|
||||||
|
# ~rpath : without rpath handling [MacOS]
|
||||||
# +openmp : with openmp
|
# +openmp : with openmp
|
||||||
# ~openmp : without openmp
|
# ~openmp : without openmp
|
||||||
# +ccache : use ccache
|
# +ccache : use ccache
|
||||||
|
@ -16,10 +16,16 @@ cctoo = $(Ctoo)
|
|||||||
cpptoo = $(Ctoo)
|
cpptoo = $(Ctoo)
|
||||||
cxxtoo = $(Ctoo)
|
cxxtoo = $(Ctoo)
|
||||||
|
|
||||||
LINK_LIBS = $(c++DBUG)
|
|
||||||
|
|
||||||
LINKLIBSO = $(CC) $(c++FLAGS) -Wl,-dylib,-undefined,dynamic_lookup
|
# Linking:
|
||||||
|
# with or without rpath components on MacOS
|
||||||
|
# - current default is with rpath unless explicitly disabled
|
||||||
|
|
||||||
LINKEXE = $(CC) $(c++FLAGS) -Wl,-execute,-undefined,dynamic_lookup
|
ifneq (,$(findstring ~rpath,$(WM_COMPILE_CONTROL)))
|
||||||
|
include $(DEFAULT_RULES)/link-c++
|
||||||
|
|
||||||
|
else
|
||||||
|
include $(DEFAULT_RULES)/link-rpath-c++
|
||||||
|
endif
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
9
wmake/rules/darwin64Clang/link-c++
Normal file
9
wmake/rules/darwin64Clang/link-c++
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
LINK_LIBS = $(c++DBUG)
|
||||||
|
|
||||||
|
LINKLIBSO = $(CC) $(c++FLAGS) -Wl,-dylib,-undefined,dynamic_lookup
|
||||||
|
|
||||||
|
LINKEXE = $(CC) $(c++FLAGS) -Wl,-execute,-undefined,dynamic_lookup
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
15
wmake/rules/darwin64Clang/link-rpath-c++
Normal file
15
wmake/rules/darwin64Clang/link-rpath-c++
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#------------------------------------------------------------------------------
|
||||||
|
include $(DEFAULT_RULES)/rpath
|
||||||
|
|
||||||
|
LINK_LIBS = $(c++DBUG)
|
||||||
|
|
||||||
|
LINKLIBSO = $(CC) $(c++FLAGS) \
|
||||||
|
$(PROJECT_RPATH) -dynamiclib \
|
||||||
|
-install_name @rpath/$(notdir $(LIB)$(EXT_SO)) \
|
||||||
|
-Wl,-dylib,-undefined,dynamic_lookup
|
||||||
|
|
||||||
|
LINKEXE = $(CC) $(c++FLAGS) \
|
||||||
|
$(subst @loader_path,@executable_path/../lib,$(PROJECT_RPATH)) \
|
||||||
|
-Wl,-execute,-undefined,dynamic_lookup
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
30
wmake/rules/darwin64Clang/rpath
Normal file
30
wmake/rules/darwin64Clang/rpath
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Compile-time rpath information:
|
||||||
|
|
||||||
|
FOAM_MPI ?= dummy
|
||||||
|
ifeq (,$(strip $(FOAM_MPI)))
|
||||||
|
FOAM_MPI = dummy
|
||||||
|
endif
|
||||||
|
|
||||||
|
PROJECT_RPATH :=
|
||||||
|
|
||||||
|
# ThirdParty libraries (FOAM_EXT_LIBBIN) : mpi-specific and serial
|
||||||
|
ifneq (,$(strip $(FOAM_EXT_LIBBIN)))
|
||||||
|
ifneq (dummy,$(strip $(FOAM_MPI)))
|
||||||
|
PROJECT_RPATH += -rpath $(FOAM_EXT_LIBBIN)/$(FOAM_MPI)
|
||||||
|
endif
|
||||||
|
PROJECT_RPATH += -rpath $(FOAM_EXT_LIBBIN)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# project libraries (FOAM_LIBBIN) : mpi-specific and serial
|
||||||
|
# encode as @loader_path and recompose as @executable_path as needed
|
||||||
|
ifneq (dummy,$(strip $(FOAM_MPI)))
|
||||||
|
PROJECT_RPATH += -rpath @loader_path/$(FOAM_MPI)
|
||||||
|
endif
|
||||||
|
PROJECT_RPATH += -rpath @loader_path
|
||||||
|
|
||||||
|
# Fallback for stubs libraries (largely for missing MPI) - to be found last
|
||||||
|
PROJECT_RPATH += -rpath @loader_path/dummy
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
Loading…
Reference in New Issue
Block a user