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

Clinton Stimpson clinton at elemtech.com
Tue Sep 10 19:16:12 EDT 2013


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/..")

Clint


More information about the CMake mailing list