New in 10.2.3: Using CMake with Ninja

Posted by on in Blogs

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 Generators

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

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:

.
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.

Overview

Using Ninja is very easy - in fact, all our examples use it, and our documentation includes the steps to install.

It is a fast, lightweight build system that is a great addition to using CMake in general, for parallel building on your local machine.

 

 



About
Gold User, No rank,
C++ Product Manager, looking after C++Builder as well as the IDE.

Comments

  • Craig S47682
    Craig S47682 Friday, 4 May 2018

    Hi David, I have installed 10.2.3 and CMake 3.10 and Ninja and followed your example post ( ). Everything works fine using bcc32c.exe, however when I try to use bcc64.exe it all falls apart with an error message 'Fatal: Unable to execute command: \registry\bin\bcc64.exe'
    I followed the steps 'to prevent errors in the build process, you need to move one file manually. Follow the steps below to do this:'
    I have also changed the cmake batch file to specify the full path to bcc64.exe, but still receive the error. Any suggestions?

  • Emanuele Coli
    Emanuele Coli Wednesday, 21 March 2018

    Hi David,
    the posts about cmake are very useful and well done! I've seen only a little error in these documentation: links for examples and documentation is not accessible ("all our examples use it" and "our documentation"). Access denied in these pages with this error:
    ---------------
    Permission error
    You do not have permission to read this page, for the following reason:

    The action you have requested is limited to users in one of the groups: writer, l10n, RADBeta, ConnectBeta, Employee.
    ----------------

  • David Millington
    David Millington Wednesday, 21 March 2018

    Thanks! The doc links should work now - I linked to the wrong URL.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: