As noted at the bottom of the page here: Filesystem library - cppreference.com, using
std::filesystem from C++17 with GCC 8 requires adding
-lstdc++fs to the linker options. GCC 8 is the system compiler for Debian 10.
What is the cleanest/correct way to deal with this within CMake?
After digging around on Github, I have seen projects that deal with this simply by matching on
CMAKE_CXX_COMPILER_ID and adding the relevant library, which I have tried here: riesling/CMakeLists.txt at stdfs · spinicist/riesling · GitHub. I am concerned that this may not be optimal/robust, hence I’m wondering if there is a better way. Thanks.