title: How to handle config file path for make build vs make install
body: <p>My project folder looks as follows:</p>
  
  <pre><code>foo/                --&gt; Project name
    CMakeLists.txt
    build/            --&gt; Run cmake.. and make.
    src/
      app.h
      app.cc
      main.cc
    share/
      foo/
        config.txt
  </code></pre>
  
  <p>I want my C++ code to be able to find <code>config.txt</code> when I do a <code>make build</code> and also when I do a <code>make install</code>.</p>
  
  <p>I tried using a relative path to read <code>config.txt</code> as follows:</p>
  
  <pre><code>const std::string CONFIG_FILE_PATH = "../share/foo/config.txt";
  </code></pre>
  
  <p>But I realize this runs relative to the folder from where I run the binary, not relative to where the binary is currently located.</p>
  
  <p>What I want is the path to be as follows:</p>
  
  <pre><code>// make build
  const std::string CONFIG_FILE_PATH = "/home/myuser/foo/share/foo/config.txt";
  
  // make install
  const std::string CONFIG_FILE_PATH = "/usr/share/foo/config.txt";
  </code></pre>
  
  <p>Is there some sorcery I can do to achieve this? I'm certain this has been done before, but I don't know what to search for.</p>