I have a project directory structure of:
++ My 3 source files and header
This is sort of counter to how makefiles and
cmake usually work.
Most users consider it really important that
make performs an incremental build.
The usual way with makefiles is to do
make clean which is supposed to remove any binaries and object files that were created.
However, sometimes I write cmake scripts that use globbing over the source directory to assemble the project. (That means, it says "just grab all
*.cpp files in the
/src folder and make an executable from them".) A makefile cannot check what files in a directory, so the make build will be broken after I add a new file, and
make clean won't fix it -- the whole makefile will need to be regenerated by
Usually what I do is, I write a simple bash script, named
rebuild.sh or something,
#!/bin/bash rm -rf build mkdir build cd build cmake .. make -j3 ./tests
And I put that in the root of my repository, and add
/build to my
.gitignore. I call that when I want to do a full rebuild -- it nukes the build directory, so its foolproof. When I want an incremental rebuild, I just type
make again in the
rebuild.sh script can also serve a double purpose if you use
travis-ci for continuous integration.