Skip to content
Snippets Groups Projects
Commit fb2b3a6f authored by Alexey Matveichev's avatar Alexey Matveichev Committed by Mark OLESEN
Browse files

COMP: add rpath information to MacOS compilation rules (#2948)

- Since the Apple SIP (System Integrity Protection) clears environment
  variables such as DYLD_LIBRARY_PATH env variable, a number of
  workarounds have been used to provide shadow values.

  However, for a more robust installation using the -rpath at
  compilation time appears to be the best solution.

  Add MacOS-specific rpath handling (@loader_path, @executable_path)
  to the wmake rules.

  Library paths handled:
    - FOAM_USER_LIBBIN
    - FOAM_SITE_LIBBIN
    - FOAM_FOAM_EXT_LIBBIN, FOAM_EXT_LIBBIN/FOAM_MPI
    - FOAM_LIBBIN (implicitly)

  The executable rpaths are handled assuming a structure of
     install-path/bin
     install-path/lib

- no rpath added for c-only compilations since there are currently
  no c-only libraries or executables with dynamic loading

  The current default for MacOS is the link with rpath information.
  This can be disabled by including `~rpath` in the WM_COMPILE_CONTROL
parent 779c3fe1
Branches
Tags
No related merge requests found
......@@ -16,10 +16,16 @@ cctoo = $(Ctoo)
cpptoo = $(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
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
LINK_LIBS = $(c++DBUG)
LINKLIBSO = $(CC) $(c++FLAGS) -Wl,-dylib,-undefined,dynamic_lookup
LINKEXE = $(CC) $(c++FLAGS) -Wl,-execute,-undefined,dynamic_lookup
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
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
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Compile-time rpath information:
PROJECT_RPATH :=
ifneq (,$(strip $(FOAM_USER_LIBBIN)))
PROJECT_RPATH += -rpath $(FOAM_USER_LIBBIN)
endif
ifneq (,$(strip $(FOAM_SITE_LIBBIN)))
PROJECT_RPATH += -rpath $(FOAM_SITE_LIBBIN)
endif
ifneq (,$(strip $(FOAM_EXT_LIBBIN)))
PROJECT_RPATH += -rpath $(FOAM_EXT_LIBBIN)
ifneq (,$(strip $(FOAM_MPI)))
PROJECT_RPATH += -rpath $(FOAM_EXT_LIBBIN)/$(FOAM_MPI)
endif
endif
# MacOS relative rpath:
# Encode as @loader_path and recompose as @executable_path as needed
PROJECT_RPATH += -rpath @loader_path
ifneq (,$(strip $(FOAM_MPI)))
PROJECT_RPATH += -rpath @loader_path/$(FOAM_MPI)
endif
# Fallback for stubs (eg, missing MPI)
PROJECT_RPATH += -rpath @loader_path/dummy
#------------------------------------------------------------------------------
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment