My solution is to have a small script that will execute make, which includes all kinds of other functions, not just the number of processors.
I call my mk script and run ./mk chmod 755 mk to run it from ./mk in the root of my project. I also have several flags so that you can run various things with a simple command line. For example, when working on code and getting a lot of errors, I prefer to direct less output. I can do this with ./mk -l without having to ./mk -l all the heavy stuff of Unix ...
As you can see, I have -j4 in several places where it makes sense. For the -l option, I don't want to, because in this case it will eventually lead to printing several errors at the same time (I tried this before!)
#!/bin/sh -e # # Execute make case "$1" in "-l") make -C ../BUILD/Debug 2>&1 | less -R ;; "-r") make -j4 -C ../BUILD/Release ;; "-d") rm -rf ../BUILD/Debug/doc/lpp-doc-?.*.tar.gz \ ../BUILD/Debug/doc/lpp-doc-?.* make -C ../BUILD/Debug ;; "-t") make -C ../BUILD/Debug ../BUILD/Debug/src/lpp tests/suite/syntax-print.logo g++ -std=c++14 -I rt l.cpp rt
With CMake, this will not work if, as Tsivarev mentioned, you do not create your own script. But I personally do not think it makes sense to call make from your make script. Plus, this can disrupt the build process, which will not expect this strange script. Finally, my script, as I already mentioned, allows me to change the settings depending on the situation.
source share