When building a project using CMake and Make, you can execute make
from a subdirectory of your build tree (i.e. from a directory below whatever directory contains your top-level Makefile
), and make
will (as far as I can tell) build all targets at or below that directory. This is because CMake generates a Makefile
for every directory that contains targets, so when you're in a directory with targets, make
finds the Makefile
for building those targets.
When CMake generates Ninja files, however, it only generates one build.ninja
file, which is at the top level of the build tree. So calling ninja
from a directory other than the top-level directory fails (even the -f
option doesn't work because ninja
can't find the rules.ninja
file).
Is there any way to emulate the "make-like" behavior of building targets at and below a directory? As far as I can tell, there are no Ninja targets that correspond to "all targets at and below a particular directory." (This could be emulated using phony targets named after each directory that depend on all targets at and below that directory, but CMake does not generate such targets by default.)