[cmake-developers] Using CMake generated ninja file as a subninja file

Nicolas Desprès nicolas.despres at gmail.com
Wed Jan 6 05:14:32 EST 2016


Hello,

I would like to be able to use a build.ninja file generated by CMake as a
subninja file of a super build.ninja file generated by a custom generator.
This way I could include a CMake projects in a bigger one.

Currently, I call ninja recursively to build the CMake sub-project. But
this approach goes against ninja philosophy (one file to ease parallel job
handling because recursive makefile are considered harmful, etc...) and the
maintainers are not willing to accept patches to properly support it [1, 2].

Consider the following build directory layout:

top/build.ninja
top/sub/build.ninja

Where:
- top/build.ninja contains, among other things, "subninja sub/build.ninja"
and is generated by a custom generator
- "top/sub/build.ninja" is generated by CMake.

To properly work, build edge outputs in "top/sub/build.ninja" must be
relative to the "top/" directory.

Currently, it is impossible because to generate the "top/sub/build.ninja"
file CMake must be invoked like this: "cd top/sub && cmake -G Ninja
<src_dir>". It has no knowledge of the "top/" directory being special and
generates all the outputs relative to the "top/sub/" directory instead of
the "top/" directory.

For example, we should have this kind of generated build statements for an
helloworld project:

build sub/build.ninja: RERUN_CMAKE ....
build sub/clean: CLEAN
build hello: C_EXECUTABLE_LINKER__hello sub/CMakeFiles/hello.dir/hello.c.o
build sub/all: phony sub/hello
default sub/all

To enable this type of generation, the "top/" directory must be passed to
CMake somehow. An environment variable or a CMake variable called
CMAKE_NINJA_TOP_BUILD_DIR would do the trick.

Note that such a change requires scoped rules which was introduced by ninja
1.6. [3]

I am willing to write the patch if you think there is a chance that it will
be accepted.

Best regards,

[1] https://github.com/ninja-build/ninja/pull/1079
[2] https://github.com/ninja-build/ninja/pull/1078
[3] https://ninja-build.org/manual.html#ref_scope

-- 
Nicolas Desprès
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160106/1c260731/attachment.html>


More information about the cmake-developers mailing list