[CMake] Install an executable with his libraries

Eric Noulard eric.noulard at gmail.com
Thu Jan 19 07:06:18 EST 2012


2012/1/19 Anthony Todisco <todisco.anthony.06 at gmail.com>:
> Thank you Eric for this link, but I don't really understand how to use RPATH
> with CMake.

The RPATH usage control with CMake is done using
4 variables:

CMAKE_SKIP_BUILD_RPATH
CMAKE_BUILD_WITH_INSTALL_RPATH
CMAKE_INSTALL_RPATH
CMAKE_INSTALL_RPATH_USE_LINK_PATH

you can get the document of each of those vars with

cmake --help-variable <VarName>

> Could you provide me piece of advice for my case?

RPATH is a Unix way to put inside a binary executable
an explicit link to the libraries on which this executable depends.

In your case the "Manager" executable depends on
the "BaseLib, ComposeLib and phtread" as stated by
your
target_link_libraries(
       Manager
       BaseLib
       ComposeLib
       pthread
)

when you run "Manager" the system thus need to load
the BaseLib, ComposeLib and phtread libs.

phtread is [probably] found automatically because it is installed
system-wide and I won't explain that.

BaseLib and ComposeLib are built in your project.

CMake knows all of this, then:

in the build tree it uses RPATH in order to make
Manager run easily without fiddling with LD_LIBRARY_PATH.

At the install location (/usr/local/... in your case)
CMake does not setup RPATH inside the **installed** executable
unless you tell him to do so, by specifying the install rpath:
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

from "http://www.cmake.org/Wiki/CMake_RPATH_handling"
you can read
"when installing all executables and shared libraries will be
relinked, so they will find all libraries they need"

by the way you should NOT do that:

#Define link libraries folder
link_directories(../../Bin/${BUILD_PATH})

this should not be necessary, see:

cmake --help-command link_directories
-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list