title: How to get a relative path for CMake unit tests?
body: <p>I have a project built with CMake that uses Catch2 for unit tests. Some of the unit tests exercise code that loads data from a file like this:</p>
  
  <pre><code>std::string resource_dir = "TEST_CWD/resources/";
  std::ifstream infile{resource_dir + "datafile.txt"}
  </code></pre>
  
  <p>The question is how to properly get the value of <code>TEST_CWD</code>.</p>
  
  <p>The directory structure is simple (and not set in stone):</p>
  
  <pre><code>my_project/
      test/
          resources/datafile.txt
          loader_test.cpp
  </code></pre>
  
  <p>Leaving <code>TEST_CWD</code> blank sometimes works, but breaks when running tests through an IDE. Setting an environment variable with the absolute path also works, but will break on others' machines. Similarly forcing all users to manually set environment variables is user unfriendly.</p>
  
  <p>What is a good way to specify relative file paths in CMake projects?</p>