MantisBT - CMake
View Issue Details
0013560CMakeCMakepublic2012-09-25 11:482013-04-17 08:54
Andreas Langs 
Peter Kuemmel 
highmajoralways
closedfixed 
LinuxUbuntu12.04
CMake 2.8.9 
CMake 2.8.11CMake 2.8.11 
0013560: Ninja: -Wl, -rpath,'$ORIGIN/foobar' not working correctly in CMAKE_EXE_LINKER_FLAGS
I used the testcase from issue 0013069 and added to the CMakeLists.txt file below line 16:
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN/foo'")

Then I used the Ninja generator to generate the ninja build files and built it using ninja 1.0.0.

Inspecting the resulting executable with "objdump -p flags" it shows: "RPATH /foo"

Using the Makefile generator and building it with make gives the expected entry shown by objdump: "RPATH $ORIGIN/foo".

Looking at the build.ninja file generated by cmake I see this line:
LINK_FLAGS = -Wl,-rpath,'$ORIGIN/unitTests'

Changing it to:
LINK_FLAGS = -Wl,-rpath,'$$ORIGIN/unitTests'
(double $$) gives the correct RPATH entry in the executable.

It seems as if there needs to be some escaping done with "$" signs when generating build.ninjs files.


No tags attached.
diff ninja-encode-vars.diff (536) 2012-11-08 15:11
https://public.kitware.com/Bug/file/4559/ninja-encode-vars.diff
gz rpath.tar.gz (8,621) 2012-11-20 16:06
https://public.kitware.com/Bug/file/4572/rpath.tar.gz
Issue History
2012-09-25 11:48Andreas LangsNew Issue
2012-10-03 08:59Peter KuemmelAssigned To => Peter Kuemmel
2012-10-03 08:59Peter KuemmelStatusnew => assigned
2012-11-08 15:11Reid KlecknerFile Added: ninja-encode-vars.diff
2012-11-08 15:12Reid KlecknerNote Added: 0031505
2012-11-14 07:57Andreas LangsNote Added: 0031554
2012-11-20 16:06Peter KuemmelFile Added: rpath.tar.gz
2012-11-20 16:09Peter KuemmelNote Added: 0031631
2012-11-20 16:09Peter KuemmelFixed in Version => CMake 2.8.11
2012-11-20 16:09Peter KuemmelTarget Version => CMake 2.8.11
2012-11-21 04:02Andreas LangsNote Added: 0031639
2012-11-21 04:53Peter KuemmelNote Added: 0031640
2012-11-21 04:53Peter KuemmelStatusassigned => resolved
2012-11-21 04:53Peter KuemmelResolutionopen => fixed
2013-04-17 08:54Robert MaynardNote Added: 0032875
2013-04-17 08:54Robert MaynardStatusresolved => closed

Notes
(0031505)
Reid Kleckner   
2012-11-08 15:12   
Does the attached path fix the problem correctly? I hit this problem, applied it locally, and things worked for me.
(0031554)
Andreas Langs   
2012-11-14 07:57   
The patch by Reid Kleckner (ninja-encode-vars.diff) does fix the described problem.
However it does not completely fix my original problem because the reproduction description was not complete enough.
So the more complete description is as follows:

Follow the original description and then add to line 8:
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

and add to line 28:
SET_TARGET_PROPERTIES(flags PROPERTIES INSTALL_RPATH "$ORIGIN")

When doing the build with a cmake 2.8.10.1 with Reid Kleckners patch and ninja 1.0.0 the result of "objdump -p flags" is:
"RPATH $ORIGIN/foo:$" instead of
"RPATH $ORIGIN/foo:$ORIGIN"

So the rpath setting coming from the CMAKE_EXE_LINKER_FLAGS variable is correct now, but the rpath setting coming from the INSTALL_RAPTH target property is not.
(0031631)
Peter Kuemmel   
2012-11-20 16:09   
rpath.tar.gz contains an updated test.

And I've committed a patch:
http://public.kitware.com/pipermail/cmake-commits/2012-November/013923.html [^]
(0031639)
Andreas Langs   
2012-11-21 04:02   
The committed patch works for my cases. Thank you.
(0031640)
Peter Kuemmel   
2012-11-21 04:53   
Thanks for testing!
(0032875)
Robert Maynard   
2013-04-17 08:54   
Closing resolved issues that have not been updated in more than 4 months.