All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
@ 2011-05-04 15:50 Simon Busch
  2011-05-04 16:09 ` Phil Blundell
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Busch @ 2011-05-04 15:50 UTC (permalink / raw)
  To: openembedded-devel

In the default configuration cmake does not set a rpath for its builded binaries. This
leads to errors at runtime when the binaries not find their needed runtime libraries.

Signed-off-by: Simon Busch <morphis@gravedo.de>
---
 classes/cmake.bbclass |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
index 40fadea..5f7066b 100644
--- a/classes/cmake.bbclass
+++ b/classes/cmake.bbclass
@@ -44,6 +44,10 @@ cmake_do_generate_toolchain_file() {
   echo "set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )" >> ${WORKDIR}/toolchain.cmake
 # Use qt.conf settings
   echo "set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )" >> ${WORKDIR}/toolchain.cmake
+
+# We need to set the rpath to the correct directory as cmake does not provide any
+# directory as rpath by default
+  echo "set( CMAKE_INSTALL_RPATH ${libdir} )" >> ${WORKDIR}/toolchain.cmake
 }
 
 addtask generate_toolchain_file after do_patch before do_configure
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-04 15:50 [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir} Simon Busch
@ 2011-05-04 16:09 ` Phil Blundell
  2011-05-04 16:19   ` Simon Busch
  0 siblings, 1 reply; 11+ messages in thread
From: Phil Blundell @ 2011-05-04 16:09 UTC (permalink / raw)
  To: openembedded-devel

On Wed, 2011-05-04 at 17:50 +0200, Simon Busch wrote:
> +# We need to set the rpath to the correct directory as cmake does not provide any
> +# directory as rpath by default
> +  echo "set( CMAKE_INSTALL_RPATH ${libdir} )" >> ${WORKDIR}/toolchain.cmake

Shouldn't this be inside some kind of guard for native?  You don't want
rpath in target binaries, do you?

p.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-04 16:09 ` Phil Blundell
@ 2011-05-04 16:19   ` Simon Busch
  2011-05-04 16:54     ` Phil Blundell
  2011-05-04 16:55     ` [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake Simon Busch
  0 siblings, 2 replies; 11+ messages in thread
From: Simon Busch @ 2011-05-04 16:19 UTC (permalink / raw)
  To: openembedded-devel

On 04.05.2011 18:09, Phil Blundell wrote:
> On Wed, 2011-05-04 at 17:50 +0200, Simon Busch wrote:
>> +# We need to set the rpath to the correct directory as cmake does not provide any
>> +# directory as rpath by default
>> +  echo "set( CMAKE_INSTALL_RPATH ${libdir} )" >> ${WORKDIR}/toolchain.cmake
> 
> Shouldn't this be inside some kind of guard for native?  You don't want
> rpath in target binaries, do you?

Thanks for the hint!

You mean something like:

if not bb.data.inherits_class('native', d)
   and not bb.data.inherits_class('cross', d):

[...]

?

regards,
Simon



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-04 16:19   ` Simon Busch
@ 2011-05-04 16:54     ` Phil Blundell
  2011-05-04 17:00       ` Simon Busch
  2011-05-04 16:55     ` [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake Simon Busch
  1 sibling, 1 reply; 11+ messages in thread
From: Phil Blundell @ 2011-05-04 16:54 UTC (permalink / raw)
  To: openembedded-devel

On Wed, 2011-05-04 at 18:19 +0200, Simon Busch wrote:
> On 04.05.2011 18:09, Phil Blundell wrote:
> > On Wed, 2011-05-04 at 17:50 +0200, Simon Busch wrote:
> >> +# We need to set the rpath to the correct directory as cmake does not provide any
> >> +# directory as rpath by default
> >> +  echo "set( CMAKE_INSTALL_RPATH ${libdir} )" >> ${WORKDIR}/toolchain.cmake
> > 
> > Shouldn't this be inside some kind of guard for native?  You don't want
> > rpath in target binaries, do you?
> 
> Thanks for the hint!
> 
> You mean something like:
> 
> if not bb.data.inherits_class('native', d)
>    and not bb.data.inherits_class('cross', d):

I think you have the sense backwards but yes, that's the general idea.
Though I must admit I don't quite understand why the rpath setting from
BUILD_LDFLAGS is not turning up in cmake's final link.  It might be
worth investigating why that isn't working for you in case this patch is
just papering over some deeper problem.

p.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake
  2011-05-04 16:19   ` Simon Busch
  2011-05-04 16:54     ` Phil Blundell
@ 2011-05-04 16:55     ` Simon Busch
  2011-05-04 20:46       ` Simon Busch
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Busch @ 2011-05-04 16:55 UTC (permalink / raw)
  To: openembedded-devel

In the default configuration cmake does not set a rpath for its builded binaries. This
leads to errors at runtime when the binaries not find their needed runtime libraries.
Please note that this is only done for recipes inheriting the native class!

Signed-off-by: Simon Busch <morphis@gravedo.de>
---
 classes/cmake.bbclass |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
index 40fadea..e8e485a 100644
--- a/classes/cmake.bbclass
+++ b/classes/cmake.bbclass
@@ -24,6 +24,13 @@ OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${TARGET_CPPFLAGS} -f
 OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
 OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
 
+OECMAKE_RPATH ?= ""
+python __anonymous() {
+    # Only set OECMAKE_RPATH if we build a native recipe
+    if bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
+        bb.data.setVar('OECMAKE_RPATH', '${libdir}', d)
+}
+
 cmake_do_generate_toolchain_file() {
 # CMake system name must be something like "Linux".
 # This is important for cross-compiling.
@@ -44,6 +51,10 @@ cmake_do_generate_toolchain_file() {
   echo "set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )" >> ${WORKDIR}/toolchain.cmake
 # Use qt.conf settings
   echo "set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )" >> ${WORKDIR}/toolchain.cmake
+
+# We need to set the rpath to the correct directory as cmake does not provide any
+# directory as rpath by default
+  echo "set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )" >> ${WORKDIR}/toolchain.cmake
 }
 
 addtask generate_toolchain_file after do_patch before do_configure
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-04 16:54     ` Phil Blundell
@ 2011-05-04 17:00       ` Simon Busch
  2011-05-05  9:50         ` Phil Blundell
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Busch @ 2011-05-04 17:00 UTC (permalink / raw)
  To: openembedded-devel

On 04.05.2011 18:54, Phil Blundell wrote:
> On Wed, 2011-05-04 at 18:19 +0200, Simon Busch wrote:
>> On 04.05.2011 18:09, Phil Blundell wrote:
>>> On Wed, 2011-05-04 at 17:50 +0200, Simon Busch wrote:
>>>> +# We need to set the rpath to the correct directory as cmake does not provide any
>>>> +# directory as rpath by default
>>>> +  echo "set( CMAKE_INSTALL_RPATH ${libdir} )" >> ${WORKDIR}/toolchain.cmake
>>>
>>> Shouldn't this be inside some kind of guard for native?  You don't want
>>> rpath in target binaries, do you?
>>
>> Thanks for the hint!
>>
>> You mean something like:
>>
>> if not bb.data.inherits_class('native', d)
>>    and not bb.data.inherits_class('cross', d):
> 
> I think you have the sense backwards but yes, that's the general idea.
> Though I must admit I don't quite understand why the rpath setting from
> BUILD_LDFLAGS is not turning up in cmake's final link.  It might be
> worth investigating why that isn't working for you in case this patch is
> just papering over some deeper problem.

I alreay searched through the cmake documentation and it says that the
rpath is set with the content of the CMAKE_INSTALL_RPATH variable. The
default value of CMAKE_INSTALL_RPATH is ""[1]. As currently nothing sets
it to another value the rpath is never set during the build for the
resulting binaries. I send another patch which does the solution
mentioned above the right way.

regards,
Simon

[1]: http://www.cmake.org/Wiki/CMake_RPATH_handling



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake
  2011-05-04 16:55     ` [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake Simon Busch
@ 2011-05-04 20:46       ` Simon Busch
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Busch @ 2011-05-04 20:46 UTC (permalink / raw)
  To: openembedded-devel

On 04.05.2011 18:55, Simon Busch wrote:
> In the default configuration cmake does not set a rpath for its builded binaries. This
> leads to errors at runtime when the binaries not find their needed runtime libraries.
> Please note that this is only done for recipes inheriting the native class!
> 
> Signed-off-by: Simon Busch <morphis@gravedo.de>
> ---
>  classes/cmake.bbclass |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/classes/cmake.bbclass b/classes/cmake.bbclass
> index 40fadea..e8e485a 100644
> --- a/classes/cmake.bbclass
> +++ b/classes/cmake.bbclass
> @@ -24,6 +24,13 @@ OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${TARGET_CPPFLAGS} -f
>  OECMAKE_C_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
>  OECMAKE_CXX_FLAGS_RELEASE ?= "${SELECTED_OPTIMIZATION} -DNDEBUG"
>  
> +OECMAKE_RPATH ?= ""
> +python __anonymous() {
> +    # Only set OECMAKE_RPATH if we build a native recipe
> +    if bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
> +        bb.data.setVar('OECMAKE_RPATH', '${libdir}', d)
> +}
> +
>  cmake_do_generate_toolchain_file() {
>  # CMake system name must be something like "Linux".
>  # This is important for cross-compiling.
> @@ -44,6 +51,10 @@ cmake_do_generate_toolchain_file() {
>    echo "set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )" >> ${WORKDIR}/toolchain.cmake
>  # Use qt.conf settings
>    echo "set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )" >> ${WORKDIR}/toolchain.cmake
> +
> +# We need to set the rpath to the correct directory as cmake does not provide any
> +# directory as rpath by default
> +  echo "set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )" >> ${WORKDIR}/toolchain.cmake
>  }
>  
>  addtask generate_toolchain_file after do_patch before do_configure


To proof this: I tested it with native and non-native recipes (all
builded with cmake.bbclass) and grep'ed through the resulting binaries
afterwards to be sure there is a rpath in the native ones (and the
correct one) and no one in the non native recipes:

morphis@nirvana ...root/tmp/sysroots/x86_64-linux/usr/bin % objdump -x
generatorrunner | grep RPATH
  RPATH                $ORIGIN/../lib:$ORIGIN/../lib

morphis@nirvana ...libshiboken-1.0.2-r0.0/package/usr/lib % pwd
/home/morphis/oe/buildroot/tmp/work/armv7a-oe-linux-gnueabi/libshiboken-1.0.2-r0.0/package/usr/lib
morphis@nirvana ...libshiboken-1.0.2-r0.0/package/usr/lib % objdump -x
libshiboken-python2.6.so.1.0.2 | grep RPATH
1 morphis@nirvana ...libshiboken-1.0.2-r0.0/package/usr/lib %

[...]

regards,
Simon



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-04 17:00       ` Simon Busch
@ 2011-05-05  9:50         ` Phil Blundell
  2011-05-05 11:21           ` Simon Busch
  0 siblings, 1 reply; 11+ messages in thread
From: Phil Blundell @ 2011-05-05  9:50 UTC (permalink / raw)
  To: openembedded-devel

On Wed, 2011-05-04 at 19:00 +0200, Simon Busch wrote:
> I alreay searched through the cmake documentation and it says that the
> rpath is set with the content of the CMAKE_INSTALL_RPATH variable. The
> default value of CMAKE_INSTALL_RPATH is ""[1]. As currently nothing sets
> it to another value the rpath is never set during the build for the
> resulting binaries. I send another patch which does the solution
> mentioned above the right way.

Oh right, I see.  So cmake is actually stripping the rpaths during the
install step unless you tell it that you want them included?

In that case, yeah, your plan seems reasonable.

p.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-05  9:50         ` Phil Blundell
@ 2011-05-05 11:21           ` Simon Busch
  2011-05-05 11:34             ` Phil Blundell
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Busch @ 2011-05-05 11:21 UTC (permalink / raw)
  To: openembedded-devel

On 05.05.2011 11:50, Phil Blundell wrote:
> On Wed, 2011-05-04 at 19:00 +0200, Simon Busch wrote:
>> I alreay searched through the cmake documentation and it says that the
>> rpath is set with the content of the CMAKE_INSTALL_RPATH variable. The
>> default value of CMAKE_INSTALL_RPATH is ""[1]. As currently nothing sets
>> it to another value the rpath is never set during the build for the
>> resulting binaries. I send another patch which does the solution
>> mentioned above the right way.
> 
> Oh right, I see.  So cmake is actually stripping the rpaths during the
> install step unless you tell it that you want them included?
>
> In that case, yeah, your plan seems reasonable.

Ok, so you are fine with the patch?

regards,
Simon



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-05 11:21           ` Simon Busch
@ 2011-05-05 11:34             ` Phil Blundell
  2011-05-05 11:44               ` Simon Busch
  0 siblings, 1 reply; 11+ messages in thread
From: Phil Blundell @ 2011-05-05 11:34 UTC (permalink / raw)
  To: openembedded-devel

On Thu, 2011-05-05 at 13:21 +0200, Simon Busch wrote:
> On 05.05.2011 11:50, Phil Blundell wrote:
> > On Wed, 2011-05-04 at 19:00 +0200, Simon Busch wrote:
> >> I alreay searched through the cmake documentation and it says that the
> >> rpath is set with the content of the CMAKE_INSTALL_RPATH variable. The
> >> default value of CMAKE_INSTALL_RPATH is ""[1]. As currently nothing sets
> >> it to another value the rpath is never set during the build for the
> >> resulting binaries. I send another patch which does the solution
> >> mentioned above the right way.
> > 
> > Oh right, I see.  So cmake is actually stripping the rpaths during the
> > install step unless you tell it that you want them included?
> >
> > In that case, yeah, your plan seems reasonable.
> 
> Ok, so you are fine with the patch?

Yup.  My only remaining concern was that it seemed a bit unwholesome to
do:

+  echo "set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )" >> ${WORKDIR}/toolchain.cmake

when OECMAKE_RPATH might be empty, and maybe it'd have been better to
bracket that echo with "if [ -n ${OECMAKE_RPATH} ] ...".  But if you've
tested it and cmake does the right thing then I guess it's fine as it
stands.

Acked-by: Phil Blundell <philb@gnu.org>

p.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir}
  2011-05-05 11:34             ` Phil Blundell
@ 2011-05-05 11:44               ` Simon Busch
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Busch @ 2011-05-05 11:44 UTC (permalink / raw)
  To: openembedded-devel

On 05.05.2011 13:34, Phil Blundell wrote:
> On Thu, 2011-05-05 at 13:21 +0200, Simon Busch wrote:
>> On 05.05.2011 11:50, Phil Blundell wrote:
>>> On Wed, 2011-05-04 at 19:00 +0200, Simon Busch wrote:
>>>> I alreay searched through the cmake documentation and it says that the
>>>> rpath is set with the content of the CMAKE_INSTALL_RPATH variable. The
>>>> default value of CMAKE_INSTALL_RPATH is ""[1]. As currently nothing sets
>>>> it to another value the rpath is never set during the build for the
>>>> resulting binaries. I send another patch which does the solution
>>>> mentioned above the right way.
>>>
>>> Oh right, I see.  So cmake is actually stripping the rpaths during the
>>> install step unless you tell it that you want them included?
>>>
>>> In that case, yeah, your plan seems reasonable.
>>
>> Ok, so you are fine with the patch?
> 
> Yup.  My only remaining concern was that it seemed a bit unwholesome to
> do:
> 
> +  echo "set( CMAKE_INSTALL_RPATH ${OECMAKE_RPATH} )" >> ${WORKDIR}/toolchain.cmake
> 
> when OECMAKE_RPATH might be empty, and maybe it'd have been better to
> bracket that echo with "if [ -n ${OECMAKE_RPATH} ] ...".  But if you've
> tested it and cmake does the right thing then I guess it's fine as it
> stands.
> 
> Acked-by: Phil Blundell <philb@gnu.org>

Ok, thanks for your help. Patch is now pushed but somehow cgit got the
line breaks wrong while local git is showing them correctly ...

regards,
Simon



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-05-05 11:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-04 15:50 [PATCH] cmake.bbclass: set the rpath for binaries build with cmake to ${libdir} Simon Busch
2011-05-04 16:09 ` Phil Blundell
2011-05-04 16:19   ` Simon Busch
2011-05-04 16:54     ` Phil Blundell
2011-05-04 17:00       ` Simon Busch
2011-05-05  9:50         ` Phil Blundell
2011-05-05 11:21           ` Simon Busch
2011-05-05 11:34             ` Phil Blundell
2011-05-05 11:44               ` Simon Busch
2011-05-04 16:55     ` [PATCH] cmake.bbclass: set the rpath for native binaries build with cmake Simon Busch
2011-05-04 20:46       ` Simon Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.