[CMake] Mac @loader_path for @rpath questions

clinton at elemtech.com clinton at elemtech.com
Sat May 24 14:41:15 EDT 2014



----- Original Message -----
> I have a bunch of libraries and frameworks that properly use @rpath.
> Now I am trying to build an application that uses those library and
> frameworks via CMake.
> 
> From this blog:
> http://www.kitware.com/blog/home/post/510
> I see I am supposed to do:
> set(CMAKE_MACOSX_RPATH 1)

The above should be set before declaring an @rpath target, which is one that has an install name with @rpath.

> set_target_properties(bar PROPERTIES INSTALL_RPATH "@loader_path/../lib")

The above should be set for any targets that use an @rpath target.  So those 2 lines don't necessarily go together.

> 
> So now, I am trying to improve my user experience with this. So a
> couple of questions:
> 
> 1) I noticed it only applies the @loader_path stuff when I "install"
> with CMake. I would like this applied during build because "install"
> is very unnatural on Mac where drag-and-drop is king. I was expecting
> set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) to help, but it doesn't seem
> to have an affect.

Setting CMAKE_BUILD_WITH_INSTALL_RPATH should have an effect, if set before any targets that link with the @rpath libraries.
Can you provide an example of what you are doing, so we can find out why its not working for you?

I understand drag-and-drop, but it doesn't work for my situations.  I have several 3rd party libraries that are not in system locations, and are not part of the build tree, so setting CMAKE_BUILD_WITH_INSTALL_RPATH breaks my builds.  Install time is where I get a complete .app bundle.

> 
> 
> 2) I have both .dylibs and .frameworks. It is customary to bundle
> frameworks in .app/Contents/Frameworks/ and somewhat customary to
> bundle .dylibs in ./app/Contents/lib
> This means I need to specify multiple "Runtime Search Path"
> (LD_RUNPATH_SEARCH_PATHS) which Apple/Xcode fully allows, i.e. I need
> both:
> set_target_properties(bar PROPERTIES INSTALL_RPATH
> "@loader_path/../Frameworks")
> set_target_properties(bar PROPERTIES INSTALL_RPATH "@loader_path/../lib")
> How do I declare this for CMake?
> 

With a list.
set_target_properties(bar PROPERTIES INSTALL_RPATH
 "@loader_path/../Frameworks;@loader_path/../lib")


> 
> 3) What is the common way people copy their frameworks into their .app
> bundle now-a-days?

I do it at install time by setting the install destination to be inside the .app bundle.


> I was hoping I could get away with:
> 
> 	SET_SOURCE_FILES_PROPERTIES(
> 		${MY_LIBRARIES}
> 		PROPERTIES
> 		MACOSX_PACKAGE_LOCATION Frameworks
> 	)
> But CMake just creates an empty directory like:
> .app/Contents/Frameworks/ALmixer.framework
> with none of the stuff inside the framework. (It doesn't recursively
> copy the directory.)

I've never used MACOSX_PACKAGE_LOCATION, so I'm not sure how it works.

Clint


More information about the CMake mailing list