One big new feature in 10.2.3 is support for building with CMake. If you haven’t already, read the previous two posts: introduction to CMake and building with Windows, and building for iOS and Android.
Today I’d like to cover using CMake generators, and specifically Ninja for fast parallel builds.
CMake is a compiler- and platform-independent project system, but despite its name it doesn’t actually do any making or building. Instead, it uses the tools already on your system, and converts the CMakeLists.txt file into the data these tools need to build. This conversion is a generator: it generates the files / data for a specific build system. Thus, once you’ve generated these once, you use that tool to build. You only need to re-run CMake itself if your project changes, eg by adding a new file, ro changing config.
Specify the generator with the -G command line switch.
You can, if you want, use old-fashioned makefiles. Do so with -G”BorlandMakeFiles”, if you want to use make. You could use any of the other generators too. However, the one that we specifically support with CMake is Ninja.
Ninja is a very small and fast build system. It comes as a single EXE, just like a traditional Delphi or C++Builder app. It also allows parallel builds. C++Builder already supports parallel compilation, but Ninja has a very nice implementation.
To use it, specify -G Ninja on the command line:
. cmake -DCMAKE_TOOLCHAIN_FILE=bccaarm.cmake -G Ninja
Here, building for Android (using the bccaarm toolchain file.) CMake will do its stuff and, using the Ninja generator, create a few files Ninja uses to build:
Then, once CMake is complete, you can build your project just by invoking ninja:
Simple as that! Ninja will take over and build – and do so in parallel. If you open Task Manager, you can see multiple copies of the compiler:
And the command line serializes the parallel output, and you can see here the status as several steps of seven are completed.
It is a fast, lightweight build system that is a great addition to using CMake in general, for parallel building on your local machine.