Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++News

Introducing Amazing CMake Support in C++Builder 12.2

cmake banner

C++Builder and RAD Studio 12.2 bring a fantastic feature for C++: full CMake support for the new Win64 Modern toolchain.

It’s available in GetIt now, and it comes with some amazing demos. You can build VCL apps, FMX apps, packages, DLLs, console apps, as you’d expect… but, and this demonstrates the power and compatibility and quality of the new toolchain in C++Builder, you can even build OpenCV. Yes, we do in fact include that as one of our demos 🙂

For the many customers who’ve asked about OpenCV, that’s quite a line to casually drop in a blog. I’ve been looking forward to writing it for a while.

Windows Explorer showing just a few of the OpenCV files built by CMake and C++Builder 122

Windows Explorer showing just a few of the OpenCV files built by CMake and C++Builder 12.2

Read on, and I’ll go into detail about the new CMake support and how to use it! Or jump right to the quick start.

What CMake Lets You Do

CMake is a very popular build system for C++ across multiple platforms and compilers. If you’re a library author, you write a CMakeLists.txt file describing your project, source, and settings, and then (in theory) anyone can use that same script to build that project with any compiler.

As a developer, more likely what happens is that you find a library on Github and it ships with a CMakeLists.txt, and you want to be able to run that with whichever toolchain you’re using: for us, C++Builder. Enabling C++Builder to be one of those toolchains was a key goal for our 12.2 release, and it’s one we believe we’ve met today!

The vast majority of all third party C++ libraries come with CMake build scripts, and this support should give you the ability to easily build them.

In other words, CMake support for C++Builder makes it easy to use any C++ library.

Here are three million of them to start.

Tech details: CMake + ninja

CMake is a meta build system: you describe your project once, and then you can use CMake to generate various build scripts, such as makefiles. That is, CMake doesn’t actually build: it creates files for another build system. Our supported scenario is using ninja, which is the world standard for fast parallel builds (though, sadly, it is not as fast as TwineCompile or our inbuilt, on-by-default parallel building in 12.2, which are highly specialised for our toolchain and our measurements show may well beat everyone else in some circumstances. But ninja is the best you’ll get outside the C++Builder ecosystem.)

Thus, we support the CMake+ninja pair, allowing you to use CMake to build C++ libraries, where the build is executed via the fast, parallel ninja build runner.

Picture of the GetIt package manager dialog with CMake visible

We have a custom build of CMake in GetIt (and are working to contribute our changes back to the CMake project.) Install that via Tools > GetIt Package Manager. Ninja is a single-executable download and just needs to be in your system path somewhere. Download and install both these.

Quick Start

Our RAD Studio 12 demos on Github were updated a day ago with a set of examples using CMake. Using your favorite git client, please check these out or download a copy.

Then:

  1. Install CMake from GetIt (in the IDE, go to Tools > GetIt Package Manager, type Cmake and press Enter in the search box, click Install;)
  2. Download and install ninja (it’s a single EXE; put it somewhere it can be found on your system PATH);
  3. And make sure you have a copy of git also installed somewhere on your system PATH.
  4. If you want to build OpenCV, you’ll also need a copy of Python installed on your system PATH.

The demo scripts use these to automatically pull from the various open source projects and build without any manual configuration on your part: they are very much a ‘run and just watch it work’ set of demos.

The Windows Start menu open to show Apps with the Embarcadero RAD Studio folder open and the'RAD Studio Command Prompt (x64)' item highlighted

Where to find the RAD Studio Command Prompt

To do this:

 

  1. Go to the Start Menu, Apps, Embarcadero RAD Studio Command Prompt (x64)
  2. Navigate to wherever you downloaded the demos: cd “c:pathtoRADStudio12DemosCPPCMake
  3. Run any of the make-*.bat files.

That’s it.

Windows Explorer open to the CMake demos folder checked out from Github

All the CMake demo scripts from our Github. Run one! (From a command prompt is better so it doesn’t close when done.)

The demos

We have inbuilt demos for a wide variety of software. This includes:

  1. make-vcl.bat: builds a basic VCL application
  2. make-fmx.bat: builds a basic FireMonkey application
  3. make-console.bat: a simple console app
  4. make-package.bat: builds packages (this is all to demo that we have more than basic CMake support: we added full support for the C++Builder way of doing things too.)Then we get on to third party libraries. Each one of these automatically pulls the latest from the github repo and builds it using CMake & ninja. You don’t need to do anything other than run the script.
  5. make-ninja.bat: yes, this builds the same ninja executable you’re using to build. You can build the C++Builder Cmake builder with the CMake builder to replace the CMake builder for a new C++Builder builder built with C++Builder: how’s that for a sentence, um, ninja! Or, phrased differently, you need ninja to build ninja, but once done you can replace it with this one if you want. Because why not?Building ninja is here to demo the breadth of functionality and compatibility we support, and so why not rebuild one of the very same tools we’re already using?
  6. make-brotli.bat: Brotli is a common compression library from Google, often used by web servers and CDNs. Again, a demo of a range of the kind of random, wide functionality you could add to your app if you want.
  7. make-drogon.bat: Drogon is a fast, modern C++17 web server. It’s a great example of very up to date C++ in a third-party library not written with C++Builder in mind, and it works. This has a couple of dependencies (Brotli and JSONCPP) so it builds those first.
  8. make-googletest.bat: Builds Google Test, which is a common C++ unit testing framework.
  9. make-jsoncpp.bat: Builds a common C++ JSON parsing and serialization library
  10. make-libsimdpp.bat: This is a wonderful library to use vectorisation primitives in a cross-platform way, which is excellent for writing highly performant code at a level higher than assembly though a little more drawn out than normal C++. It’s worth checking out. As a side note, we apply a patch here – not because we have to, but because we support an extra feature so we opt in 🙂
  11. make-opencv.bat: this computer vision library one of the most requested libraries by our customers, so why not include it fully building as a demo 🙂
  12. make-vtk.bat: this is a widely used library for scientific visualisation and image processing. It’s a prerequisite for OpenCV, so will be built automatically. This is the only library that requires a compatibility patch, where you’ll see in workaroundsvtk-v9.3.1.diff that we change a check for BORLANDC, which is defined by our compilers, to also check if it’s not Clang newer than v15, and defining a couple of types that we do indeed support: ie, we’re saying “it’s ok, this compiler can handle it”.

Screenshot of CMake building VTK

Tech details: Building

The combination of OpenCV and VTK might take a couple of hours, even parallelised: they are gigantic projects and there are many thousands of complex C++ files. Ninja will use as many cores as you have:

Task Manager showing many copies of bcc64x due to ninja

Task Manager showing many copies of bcc64x, due to ninja

So, just like our new on-by-default parallel builds, the more cores you put on your developer machine, the faster you will compile.

We’ll blog in a few days on the details of how CMake works. In a sense, the super-easy scripts to demo it make it look more complex than it is: really, you set set a few variables to tell it to us bcc64x, for x86_64, Release, your input and output folders, etc and run. You can distill each script down to just a few lines.

Stay tuned for that more technical post soon!

CMake support!

C++Builder 12.2 aimed for three key release pillars:

  1. Support dynamic packages, including ones built by Delphi, and building them in C++
  2. Fast, CPU-saturating multi-core compilation (we’ll blog about this soon)
  3. CMake support

We’ve shipped all three.

And to explain all three, the first means we are feature-complete with the old Win64 toolchain: 12.2 is a full, and much better, replacement.

The second aims to give you fast compilation, which is key for productivity: we use everything your computer provides, and the more cores, and the more source code, the better it scales – yes, it is better the more of everything you throw at it.

And the third, CMake, makes it really easy to use the industry standard C++ build system and, given how compatible C++Builder is, makes it really easy to use any third party C++ source you need. Yes, that includes the really complex and large libraries, like OpenCV.

In 12.x we’ve been aiming to do it right. We hope you agree we are.

 

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

David is an Australian developer, currently living in far-north Europe. He is the senior product manager for C++ at Idera, looking after C++Builder and Visual Assist.

16 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES