Simon Walker
Simon Walker

Reputation: 5981

Creating binary with CMake removes runtime path

I am using CMake to build a program on linux. The program compiles successfully and runs from the project build directory. The program is linked with a custom library in the directory ${HOME}/build/lib

I have an install stage with:

install(TARGETS ProgName RUNTIME DESTINATION bin)

When I run make install the program gets put in the correct place, but the cmake installer removes the runtime path from the binary.

-- Install configuration: "Debug"
-- Installing: *binary name*
-- Removed runtime path from "*binary name*"

I have read articles on the internet discussing the misuse of the LD_LIBRARY_PATH variable so I like to keep mine limited to system library locations if possible. I am not sysadmin so I cannot add the location to the default linker search path either.

Does anyone know how I can keep the development-time linking paths when installing or at least customising which paths are added to the runtime?

Cheers

Upvotes: 23

Views: 14557

Answers (3)

Mark Lakata
Mark Lakata

Reputation: 20818

This works for CMake 2.8

 set_target_properties(foo PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

where foo is the target you defined earlier:

 project(foo)
 add_executable(foo ...)
  ...
 install(TARGETS foo DESTINATION bin)
  ...

Before

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Removed runtime path from "/opt/mystuff/bin/foo"

After

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Set runtime path of "/opt/mystuff/bin/foo" to "/opt/zzyzx/lib:/opt/bar/lib/x86_64"

Upvotes: 0

VonC
VonC

Reputation: 1323045

Note: if you don't want to modify the cmake scripts themselves, setting property around, you can launch you cmake with a directive asking to not remove the runtime path:
See "Variables that Control the Build", with variable: "CMAKE_SKIP_RPATH"

If true, do not add run time path information.

If this is set to TRUE, then the rpath information is not added to compiled executables.
The default is to add rpath information if the platform supports it. This allows for easy running from the build tree.
To omit RPATH in the install step, but not the build step, use CMAKE_SKIP_INSTALL_RPATH instead.

If the deliveries already contained the right runtime path, that directive will avoid cmake to do any modification to the current runtime path included in said deliveries.

cmake -DCMAKE_SKIP_RPATH=ON xxx.cmake

Upvotes: 14

RobertJMaynard
RobertJMaynard

Reputation: 2247

You should look at set_target_properties command and the property BUILD_WITH_INSTALL_RPATH

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties

Upvotes: 12

Related Questions