Adding another file to the project

221 views
Skip to first unread message

Tedy Grey

unread,
Aug 8, 2016, 10:28:05 AM8/8/16
to ninja-build
If I add another file in the project, how will the dependency mechanism will figure out that I added it? Or should I specify it explicit in the build.ninja file?
What if I add it as an #include for another file, how does Ninja figures out what to do? where exactly, in which module of the code is recreated the deps graph and the deps log?

Nico Weber

unread,
Aug 8, 2016, 10:33:14 AM8/8/16
to Tedy Grey, ninja-build
Hi Tedy,

On Mon, Aug 8, 2016 at 10:27 AM, Tedy Grey <randomvid...@gmail.com> wrote:
If I add another file in the project, how will the dependency mechanism will figure out that I added it? Or should I specify it explicit in the build.ninja file?
What if I add it as an #include for another file, how does Ninja figures out what to do? where exactly, in which module of the code is recreated the deps graph and the deps log?

it depends, on various things.

If you're using an existing generator to generate .ninja files, it depends on the generator. For CMake, gyp, and gn, you usually list source files (.cc) in the build file, so if you add a cc file you'll have to edit a CMakeLists.txt / .gyp / .gn file and add it there. CMake and gn will then figure out that they need to rerun themselves the next time you build, with gyp you manually have to run gyp again to generate new ninja files.

If you're writing ninja files by hand (remember: ninja isn't designed for that) and you're adding a source file that's compiled, you'll have to add a new build rule for that source file.

If you're only adding a header file, you shouldn't have to do anything: If you add a .h file that isn't included by any .cc file, then it won't have an effect in the build. If you then edit an existing cc file to include your new h file, ninja will detect a change to that cc file and rebuild it. All generators that I know of use ninja's depfile feature (https://ninja-build.org/manual.html#ref_headers) to ask the compiler to output the header files that each cc file uses, which ninja then uses to learn which cc files need to be recompiled when a h file is touched.

Nico 

Ben Boeckel

unread,
Aug 8, 2016, 10:44:10 AM8/8/16
to Nico Weber, Tedy Grey, ninja-build
On Mon, Aug 08, 2016 at 10:33:12 -0400, Nico Weber wrote:
> If you're only adding a header file, you shouldn't have to do anything: If
> you add a .h file that isn't included by any .cc file, then it won't have
> an effect in the build.

Nitpicking, but this is not strictly true: adding stdint.h into your
local include directories could certainly change the result of a build
without changing a .c or .cxx file.

--Ben
Reply all
Reply to author
Forward
0 new messages