[CMake] rpath trouble on macosx: cmake 2.8.9 ignores INSTALL_NAME_DIR and INSTALL_RPATH?

Alexander Neundorf a.neundorf-work at gmx.net
Wed Sep 11 15:00:07 EDT 2013


On Wednesday 11 September 2013, Clinton Stimpson wrote:
> On Tuesday, September 10, 2013 04:03:08 PM Dan Kegel wrote:
> > On Tue, Sep 10, 2013 at 10:43 AM, Clinton Stimpson <clinton at elemtech.com>
> 
> wrote:
> > > Using the INSTALL_RPATH property doesn't work correctly unless you use
> > > CMake 2.8.12 with the target property MACOSX_RPATH=1.
> > 
> > Done, example http://kegel.com/macosx/rpath/demo2/CMakeLists.txt
> 
> Actually, you want either of these
> 
> set_target_properties(foo PROPERTIES INSTALL_NAME_DIR "@rpath")
> or
> set_target_properties(foo PROPERTIES MACOSX_RPATH 1)
> 
> There is no need to set it as a property on target x.
> 
> > > If you want it to work with the older version of CMake, then you need
> > > to set the -Wl,-rpath linker flag yourself using the LINK_FLAGS target
> > > property.
> > 
> > Done, example http://kegel.com/macosx/rpath/demo3/CMakeLists.txt
> > 
> > Next question: will cmake support relative rpaths, as in the example at
> > http://kegel.com/macosx/rpath/demo4/demo4.txt ?
> > i.e.
> > 
> >   gcc -shared foo.c -install_name @rpath/lib/foo.so -o foo.so
> >   gcc -Wl,-rpath, at loader_path/.. x.c foo.so
> > 
> > ?  (I know, I should download and build trunk, but I'm pathetically
> > lazy.) - Dan
> 
> Yes, it'll work in 2.8.12 like this.
> 
> set_target_properties(x PROPERTIES INSTALL_RPATH "@loader_path/..")

I have 2 rpath-related features on my wishlist/todolist:
- when using INSTALL_RPATH_USE_LINK_RPATH, also add the install directory of 
shared library built and installed within the project to the install rpath
- after that, for these cases, use relative rpath (@ORIGIN, I guess 
@loader_path is the same) if possible. With absolute rpaths pointing into the 
install dir packages are not really relocatable.

Not sure when I'll get around to have a look at this.

Alex


More information about the CMake mailing list