8

I found Cmake: How to set rpath to ${ORIGIN} with cmake but my cmake does not have target_link_options.

I'm not installing the binary, I'm only "installing" it with RUNTIME_OUTPUT_DIRECTORY, so I don't think CMAKE_INSTALL_RPATH will work. Even though, I tried SET(CMAKE_INSTALL_RPATH "$\{ORIGIN\}") as suggested in the question, but I got

  Syntax error in cmake code at

  .../CMakeLists.txt:25

  when parsing string

    $\{ORIGIN\}

  Invalid escape sequence \{

I need to set this rpath which I was using in Makefile:

-rpath=\$$ORIGIN/lib

How to do it in cmake?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150

2 Answers2

8

Following works for me on 3.14

  set(CMAKE_INSTALL_RPATH $ORIGIN)

This is what Craig Scott recommended in his CppCon 2019 talk Deep CMake for Library Authors (Slide 100/110)

Julien Marrec
  • 11,605
  • 4
  • 46
  • 63
itanium
  • 96
  • 1
2

You need to escape $ sign not the brackets please see https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling

This works for me:

SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "\${ORIGIN}")