Hacker News new | ask | show | jobs
by amadio 854 days ago
I usually just set the working directory to ${CMAKE_CURRENT_SOURCE_DIR}¹ for tests that only read files, and use configure_file()² for files that could be modified or contain variables expanded by CMake. Note that you don't need to add a dependency, as configure_file() runs during configuration, and if you change the input, will copy the file again. CMake also has the notion of text fixtures for more complicated things as well, like setting up a db or other kind of service that your tests may need to run. See property FIXTURES_SETUP³ for that.

1. https://cmake.org/cmake/help/latest/prop_test/WORKING_DIRECT...

2. https://cmake.org/cmake/help/latest/command/configure_file.h...

3. https://cmake.org/cmake/help/latest/prop_test/FIXTURES_SETUP...