title: Cmake: How to set rpath to ${ORIGIN} with cmake
body: <p>According to this SO question, <a href="https://stackoverflow.com/questions/39978762/linux-executable-cant-find-shared-library-in-same-folder">Linux executable can&#39;t find shared library in same folder</a> passing <code>-Wl,-rpath,${ORIGIN}</code> is the way to get a Linux executable to search for <code>.so</code>s in the same directory as the executable.</p>
  
  <p>We're using cmake, so I'm adding a line of the form</p>
  
  <pre><code>target_link_options(Executable PRIVATE -Wl,-rpath=${ORIGIN})
  </code></pre>
  
  <p>to CMakeLists.txt.  The problem with that is that cmake tries to interpret the nine character sequence <code>${ORIGIN}</code> as a variable, and replaces it with nothing.</p>
  
  <p>So far, I've tried:</p>
  
  <pre><code>$${ORIGIN}
  \${ORIGIN}
  $\{ORIGIN\}
  $$\{ORIGIN\}
  \$\{ORIGIN\}
  </code></pre>
  
  <p>none of which have worked.  How can I get this done?</p>
  
  <p>-- Edit --</p>
  
  <p>As noted by @Tsyvarev's comment, it turns out this was an XY problem in my particular case, since cmake has facilities directly designed to manipulate rpath.  Using this, I was able to get a solution.</p>
  
  <p>In my case, adding the following three lines to CMakeLists.txt did the trick.</p>
  
  <pre><code>SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
  SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  SET(CMAKE_INSTALL_RPATH "$\{ORIGIN\}")
  </code></pre>
  
  <p>Note that part of our build process involves copying the <code>.so</code> to the output folder in preparation for building the final tarball artifact.  So using <code>-rpath=${ORIGIN}</code> works for both testing in the build tree, and final installation of the executable in the Docker container.</p>