[CMake] Relink during install to get correct rpath in the binary?

Chris Scharver scharver at gmail.com
Tue Nov 22 13:10:01 EST 2005


On 11/22/05, Brad King <brad.king at kitware.com> wrote:
> Chris Scharver wrote:
> > On 11/20/05, Brad King <brad.king at kitware.com> wrote:
> >
> >>The rpath feature of CMake is intended to help developers use projects
> >>with shared libraries from the build tree without setting
> >>LD_LIBRARY_PATH or their platform's equivalent.  Many linux/unix people
> >>consider rpaths evil for installed programs, and many linux
> >>distributions ban them altogether.  The idea is that installed shared
> >>libraries should be in the system's shared library search path
> >>(ld.so.conf or equivalent) so they can be shared among applications.
> >
> >
> > So how exactly does this get handled on Mac OS X with install_name?
> > I've tried setting the variable so that CMAKE_SKIP_RPATH is OFF, but I
> > still get libraries with build library locations embedded in them
> > rather than the INSTALL_PREFIX. Is extra work required when writing
> > the CMakeLists.txt in order to get CMake to use the correct
> > install_name?
>
> Use of install_name for rpath was altered in CMake 2.2.  Make sure you
> are using CMake 2.2 and not 2.0.  After setting CMAKE_SKIP_RPATH to ON
> delete the libraries from the build tree to make sure they relink with
> the new install_name.  Then the install_name should be set to just the
> name of the library with no path.

I'm using CMake 2.2 patch 2. I can verify that I'm now getting a
library with only the library name. However, this means that I still
have to set the DYLD_LIBRARY_PATH environment variable to include the
install location. Can I get CMake to automatically include the
CMAKE_INSTALL_PREFIX when it sets the install_name?

Modules/Platform/Darwin.cmake only includes the full build path. It
seems like it should instead use the CMAKE_INSTALL_PREFIX (or maybe a
variable could store whether to use a string like "@executable_path"),
but it doesn't look like that gets expanded. I tried:

  SET(CMAKE_C_CREATE_SHARED_LIBRARY
    "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
<LINK_FLAGS> -o <TARGET> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG>
\"<CMAKE_INSTALL_PREFIX>/<TARGET_SONAME>\" <OBJECTS>
<LINK_LIBRARIES>")
  SET(CMAKE_CXX_CREATE_SHARED_LIBRARY
    "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
<LINK_FLAGS> -o <TARGET> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG>
\"<CMAKE_INSTALL_PREFIX>/<TARGET_SONAME>\" <OBJECTS>
<LINK_LIBRARIES>")

I surmise that the Makefile generator would need patching so that it
could expand CMAKE_INSTALL_PREFIX? This would remove the need to worry
about the load library path.

Thanks,
Chris


More information about the CMake mailing list