Cmake set relative path to binary to 3rd party library

371 Views Asked by At

I'm trying to make my first roject using Cmake and I'm faced with issue with static linking to *.so library.

My binary see libraries only from the build folder.

I've tried to use this statements from "RPATH handling" manual, but it's not working so far:

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(mt libjack.so "${CMAKE_BINARY_DIR}/lib/librtmidi.so")

With qmake in comparison, I can just include this to pro file:

QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/lib

and then, no matter, where I will deploy my binary to, one will be linked to library in /lib folder.

Thank you!

1

There are 1 best solutions below

0
On

With the help of Tsyvarev, I've managed to make my binary linked statically with lib folder no matter, where I copying them. For CMAKE_INSTALL_RPATH I put "lib" (instead of "/lib") Placed this block before add_executable definition

...
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
...
add_executable(mtest main.cpp)
...
target_link_libraries(mtest libjack.so "${CMAKE_BINARY_DIR}/lib/librtmidi.so")
...

Thank you!