Hello! I’m using CMake with C++, whenever I add a new file into the project, CMake doesn’t update , and there’s errors in the other files, saying that the stuff I declared/defined in the new file doesn’t exist, and I have to edit the CMakeLists.txt file to get it to work, I don’t want to edit the CMakeLists.txt every time I need to add a new file.
How do you do that exactly?
This is the standard CMake workflow. You create new file, and you add it to the CMakeLists.txt to the right target.
Don’t be tempted to use globbing as some internet resources suggest - it’ll bite you in the ass sooner or later.
I use globbing in a lot of my projects and it has never once let me down, my cmakelists.txt files are very simple and just have one target, I only set the project name, set the C++ standard, and set the include folder, and glob all the .c and .cpp files in the src/ and include/ folders, and link libraries.
This is exactly why CMake does not not see your new files. With globbing it builds the list of files when the configuration step is run, and this step is only run if the CMake files themselves change.
This is exactly the behaviour that sometimes bites hard.