How to get a relative path for CMake unit tests?
问题 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: std::string resource_dir = "TEST_CWD/resources/"; std::ifstream infile{resource_dir + "datafile.txt"} The question is how to properly get the value of TEST_CWD . The directory structure is simple (and not set in stone): my_project/ test/ resources/datafile.txt loader_test.cpp Leaving TEST_CWD blank sometimes works, but breaks when running tests through