## 3.2.12

### gyp and ninja, hello world

Building software can be very complicated. Not writing the code, but just calling the various tools that will turn it into an executable.

For some time, I have been working on a 20% project that brought me back to the realm of open source development in C / C++. One thing that struck me is how many different build systems exist today. In this post, I just want to share a micro-tutorial on a particular combination.

* gyp - a meta-build system

* ninja - a tiny make-like build tool

These are children of the chromium project. For gyp, we describe targets in a high-level manner, with the option of platform-specific tweaks. Then a gyp "generator" will output platform specific build files (the choice includes xcodebuild, visual studio ...).

Given that gyp needs to have all the information necessary in order to generate build files, one does not really need a complicated lower-level build tool. Consequently, ninja is a minimal build tool that is lacking a lot of make's fanciness and flexibility, but enough to do the job.

Here now a sneak peek at how to use these two: assume I have a helloworld project like this.
 helloworld.gyp src/helloworld.cc 

This is what the gyp file contains:

{
'targets': [
{
'target_name': 'my_target',
'type': 'executable',
'sources': [
'src/helloworld.cc',
],
},
],
}


We can now use this then generates platform specific build files.
 $GYP_GENERATORS=ninja gyp helloworld.gyp --toplevel-dir=pwd --depth=0  Now it is just a matter of running ninja, which takes care of building my target $ ninja -C out/Default/ all ninja: Entering directory out/Default/' [2/2] LINK my_target `

And that was it, helloworld is built.

ninja works for MacOS and Linux today, which is the combination I need, and maybe one day there will be some windows support. Since I have nothing to release yet, this is good enough for my purposes, YMMV.