[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] getting the rpath right on osx
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2015-11-02 13:44:23
Message-ID: CAExHGmS42pT3zU7kvoL3MJ0Z1q5ToMpbZhdinjTy5=ZG_zgXAA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

On Mon, Nov 2, 2015 at 10:26 AM, Boudewijn Rempt <boud@valdyas.org> wrote:

> I checked the manual and the blog post about rpath on osx, but I'm still
> confused, and still not getting it right...
>
> I build and installed Qt 5.6 alpha like this:
>
> ./configure -prefix /Users/boudewijnrempt/kf5/i
>
> Then I made a small test project, consisting of nothing but a main that
> links to QtCore.
>
> If I build that with qmake, with this .pro file:
>
> QT       += core
> QT       -= gui
> TARGET = rpathqmake
> CONFIG   += console
> CONFIG   -= app_bundle
> TEMPLATE = app
> SOURCES += main.cpp
>
> The r-path is set:
>
> Boudewijns-Mac-mini:test boudewijnrempt$ otool -L rpathqmake
> rpathqmake:
>     @rpath/QtCore.framework/Versions/5/QtCore (compatibility version
> 5.6.0, current version 5.6.0)
>
> /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration
> (compatibility version 1.0.0, current version 1.0.0)
>     /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
> (compatibility version 1.0.0, current version 275.0.0)
>     /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version
> 120.0.0)
>     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
> version 1213.0.0)
>
> Boudewijns-Mac-mini:test boudewijnrempt$ otool -L rpathqmake | grep -i
> rpath
> rpathqmake:
>     @rpath/QtCore.framework/Versions/5/QtCore (compatibility version
> 5.6.0, current version 5.6.0
>

Thats not the rpath in your executable, thats just the install name of the
QtCore library. And the install name indicates that you need to set an
rpath in your executable that points to the installation directory of Qt.
In order to see the rpath entries of your executable you'll need to check
for the LC_RPATH command in the output of this:

otool -l rpathqmake

It will show the absolute path to the Qt installation on your system.


> If I try a minimal cmakelists.txt, the rpath isn't set, I tried with and
> without all those RPATH related lines,
> they don't seem to make a difference. I'm using cmake 3.3.2.
>
> cmake_minimum_required(VERSION 2.8.12)
> cmake_policy(SET CMP0042 NEW)
> set(CMAKE_MACOSX_RPATH ON)
> SET(CMAKE_SKIP_BUILD_RPATH TRUE)
> SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
> SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
> set(REQUIRED_QT_VERSION 5.3.0)
> find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core)
> add_executable(rpathcmake main.cpp)
> target_link_libraries(rpathcmake Qt5::Core)
> install(TARGETS rpathcmake DESTINATION /Users/boudewijnrempt/kf5/i/bin)
>
> Only adding something like this makes it work:
>
> set_target_properties(rpathcmake PROPERTIES INSTALL_RPATH
> "/Users/boudewijnrempt/kf5/i/lib")
>

I guess thats where your Qt is installed to? Then yes, that is exactly what
you want since thats where Qt is and the Qt libraries require an rpath to
be set to be found since 5.5 on OSX. You just don't want to hardcode this,
but rather calculate it off of the path of the QtCore library. Or even
better would be if the Qt5 cmake modules would provide some provision to
add the necessary linker commandline argument to inject the rpath during
linking into the executable. Thats how qmake makes things 'work out of the
box', it knows Qt has been built with the rpath-flag (default since 5.5)
and then adds something like -Wl,-rpath,<qtlibdir> to the linker
commandline of the generated Makefile.

I think the idea of using @rpath as install name of the Qt libraries is
geared towards the usecase of shipping Qt within the application bundle of
the application. In that case all you need is set the rpath
@executable_path/../Frameworks or so in the executable and thus the
app-bundle is relocatable. In order to get that with CMake you'll likely
need to use the BundleUtilities, though its been so long since I used those
I don't know if they can handle this scenario out of the box.

Andreas

[Attachment #5 (text/html)]

<div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov \
2, 2015 at 10:26 AM, Boudewijn Rempt <span dir="ltr">&lt;<a \
href="mailto:boud@valdyas.org" target="_blank">boud@valdyas.org</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">I checked the manual and the blog post about rpath on \
osx, but I&#39;m still<br> confused, and still not getting it right...<br>
<br>
I build and installed Qt 5.6 alpha like this:<br>
<br>
./configure -prefix /Users/boudewijnrempt/kf5/i<br>
<br>
Then I made a small test project, consisting of nothing but a main that links to \
QtCore.<br> <br>
If I build that with qmake, with this .pro file:<br>
<br>
QT           += core<br>
QT           -= gui<br>
TARGET = rpathqmake<br>
CONFIG     += console<br>
CONFIG     -= app_bundle<br>
TEMPLATE = app<br>
SOURCES += main.cpp<br>
<br>
The r-path is set:<br>
<br>
Boudewijns-Mac-mini:test boudewijnrempt$ otool -L rpathqmake<br>
rpathqmake:<br>
      @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.6.0, current \
                version 5.6.0)<br>
      /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration \
                (compatibility version 1.0.0, current version 1.0.0)<br>
      /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility \
                version 1.0.0, current version 275.0.0)<br>
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version \
                120.0.0)<br>
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version \
1213.0.0)<br> <br>
Boudewijns-Mac-mini:test boudewijnrempt$ otool -L rpathqmake | grep -i rpath<br>
rpathqmake:<br>
      @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.6.0, current \
version 5.6.0<br></blockquote><div><br></div><div>Thats not the rpath in your \
executable, thats just the install name of the QtCore library. And the install name \
indicates that you need to set an rpath in your executable that points to the \
installation directory of Qt. In order to see the rpath entries of your executable \
you&#39;ll need to check for the LC_RPATH command in the output of \
this:</div><div><br></div><div>otool -l rpathqmake</div><div><br></div><div>It will \
show the absolute path to the Qt installation on your system.</div><div>  \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> If I try a minimal cmakelists.txt, the rpath isn&#39;t set, \
I tried with and without all those RPATH related lines,<br> they don&#39;t seem to \
make a difference. I&#39;m using cmake 3.3.2.<br> <br>
cmake_minimum_required(VERSION 2.8.12)<br>
cmake_policy(SET CMP0042 NEW)<br>
set(CMAKE_MACOSX_RPATH ON)<br>
SET(CMAKE_SKIP_BUILD_RPATH TRUE)<br>
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)<br>
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)<br>
set(REQUIRED_QT_VERSION 5.3.0)<br>
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core)<br>
add_executable(rpathcmake main.cpp)<br>
target_link_libraries(rpathcmake Qt5::Core)<br>
install(TARGETS rpathcmake DESTINATION /Users/boudewijnrempt/kf5/i/bin)<br>
<br>
Only adding something like this makes it work:<br>
<br>
set_target_properties(rpathcmake PROPERTIES INSTALL_RPATH \
&quot;/Users/boudewijnrempt/kf5/i/lib&quot;)<br></blockquote><div><br></div><div>I \
guess thats where your Qt is installed to? Then yes, that is exactly what you want \
since thats where Qt is and the Qt libraries require an rpath to be set to be found \
since 5.5 on OSX. You just don&#39;t want to hardcode this, but rather calculate it \
off of the path of the QtCore library. Or even better would be if the Qt5 cmake \
modules would provide some provision to add the necessary linker commandline argument \
to inject the rpath during linking into the executable. Thats how qmake makes things \
&#39;work out of the box&#39;, it knows Qt has been built with the rpath-flag \
(default since 5.5) and then adds something like -Wl,-rpath,&lt;qtlibdir&gt; to the \
linker commandline of the generated Makefile.</div><div><br></div><div>I think the \
idea of using @rpath as install name of the Qt libraries is geared towards the \
usecase of shipping Qt within the application bundle of the application. In that case \
all you need is set the rpath @executable_path/../Frameworks or so in the executable \
and thus the app-bundle is relocatable. In order to get that with CMake you&#39;ll \
likely need to use the BundleUtilities, though its been so long since I used those I \
don&#39;t know if they can handle this scenario out of the \
box.</div><div><br></div><div>Andreas</div></div></div></div>



-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: \
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at \
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic