On 2014-07-26 16:20, Nico Weber wrote:
> On Fri, Jul 25, 2014 at 10:03 AM, Matthew Woehlke wrote:
>> On 2014-07-25 12:32, Nico Weber wrote:
>>> Isn't it possible to set up your build in a way that there's
>>> only a single ninja invocation? That should be more efficient,
>>> solves all sub-ninja process issues (there are no sub-ninja
>>> processes), etc.
>>
>> Given that we're talking about CMake, here, CMake would need to have
>> knowledge of when it is running a custom command that is to build
>> another CMake project,
>
> I don't know CMake well, but if there was some CMake build construct that
> said "build_subproject()", then it seems that the generator should have
> enough information to build the subproject with the same generator that's
> currently selected, no?
That's the problem; there is no such thing. In CMake, this boils down to
add_custom_command (or maybe add_custom_target; I didn't check), which
is a generic mechanism that can be used to run *any* executable (even
the regular compiler if you were feeling especially masochistic). CMake
would either need to be newly taught such a command, or else would need
to be taught how to "recognize" when a custom command/target is in fact
calling 'cmake --build' in order to treat it differently. (The former is
probably preferred.)
Also, as was elsewhere stated, for this to work correctly requires that
ninja be able to build such a project where the .ninja files change in
the middle of the build. (Actually it's worse than that; they may not
even exist at the start of the build!) It seems to me this could be very
hard to implement.
Just to be clear, such a build consists of:
configure ProjectA (i.e. creates .ninja files for same)
build ProjectA
configure ProjectB
build ProjectB
[...]
There can be additional per-project steps, but the important part is
that the .ninja files for ProjectB *do not exist* at the start of the
root build. Worse, *generating* them may well (in fact, often *does*)
depend on the *build* of ProjectB having completed first.
IOW, ninja would need to be able to reload the build graph multiple
times in the middle of a build. I'd also be worried about getting
dependencies right in order to do that reload at a consistent spot.
(There's a good chance this would fall to CMake rather than Ninja, but
it's still likely to be complicated. Worse, now you're asking CMake to
carry a whole lot of code that is specific to only one of its
generators, which may not go over well.)
>> This also does nothing for the potential case of ninja -> make -> ninja.
>
> One of ninja's core features is performance, which you probably sacrifice
> by doing these nested build system invocations.
Possibly... Certainly you would have much better scope for interleaving
rules/targets across projects if ninja knew about the entire build. (As
an example, let's say that ProjectA has LibraryA1 and LibraryA2,
ProjectB has LibraryB which depends on LibraryA1, and ProjectC has
LibraryC which depends on LibraryA2 and LibraryB. Right now, for build
correctness it is necessary for ProjectC to depend on ProjectB which in
turn depends on ProjectA. If Ninja knew about everything, LibraryA2 and
LibraryB could be built in parallel.)
I'm not saying anywhere this wouldn't be better :-). Just that it
requires changes to CMake as well as Ninja.
That said, it's still possible that some superbuild contains a
sub-project that *must* be built with Make. (Or worse, some
project-specific tool, e.g. Qt, Boost, etc.) On it's own this isn't
horrible, but things could get really odd if such a project were to turn
around and used ninja again in its bowels.
--
Matthew