openmpi compiler wrappers do not obey CMAKE_SKIP_RPATH
Background Observations / Context
While working with CMake 3.15.1
and openmpi compiler wrappers I noticed that I couldn't get INSTALL_RPATH_USE_LINK_PATH
to embed link paths into the rpath
of the executable target, verifying with i.e., objdump -x program | grep -i 'rpath'
. So, I decided to step back and tell CMake to completely disable setting RPATH in the executable with a top-level CMakeLists.txt
set(CMAKE_SKIP_RPATH TRUE)
. Again, the embedded rpath was identical (still present) using objdump
command above again to check--and that seemed strange to me.
So, I took a step back and tested this on both HPC resources and on a local Ubuntu Linux desktop in a variety of scenarios and noticed that for several versions of openmpi (2.x series & 3.x series), regardless of whether they wrap over intel or gcc compilers, they do not obey set(CMAKE_SKIP_RPATH TRUE)
. If the openmpi wrappers are not used and only the plain gcc or intel compiler are used, set(CMAKE_SKIP_RPATH TRUE)
is obeyed as documented and the above objdump | grep
will produce no results.
How to Reproduce This for Assessment
I've produced a minimum working reproducer for a simple program in pure C along with relatively simple CMake code: https://github.com/tylerjereddy/rpath_abrogation
Here is the approximate sequence of commands that could be used to reproduce the issue locally, with some variations possible depending on your shell and platform of choice & path to mpicc using CMake 3.15.1
:
git clone https://github.com/tylerjereddy/rpath_abrogation
cd rpath_abrogation
mkdir build && cd build
CC=mpicc cmake ../source/
cmake --build .
objdump -x program | grep -i 'rpath'
That last command will produce output with an openmpi compiler wrapper--for example locally with the exact sequence of commands above:
RPATH /home/tyler/github_projects/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.4.0/hwloc-1.11.11-427xlli63t5wlbtwyidmtrwdg4ua4v3o/lib:/home/tyler/github_projects/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.4.0/openmpi-3.1.4-asctus2nru5i655tzdrphxa7mtmbg7uw/lib
But if you set CC
to a non-mpi compiler like plain gcc or intel equivalent it should be as expected (blank). No exceptions for openmpi compiler wrappers are noted in the docs or in the 3rd Edition of Craig Scott's recent book, as far as I can tell.