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

Practical Info: Using CMake with C++Builder 12.2

Back in October when we released C++Builder and RAD Studio 12.2, we introduced that we have fantastic CMake support.

We have both multiple demos and a lot of documentation on using CMake. This blog is to briefly point you to both.

Installing

The new CMake support, which is for the Windows 64-bit Modern toolchain, the toolchain we recommend you use, contains changes we plan to submit back to CMake. Currently, please install CMake from GetIt; this is our own build. You can then use it plus ninja (which is a single-EXE download, place it somewhere in your path) to build.

Picture of the GetIt package manager dialog with CMake visible

If you don’t use this version, you will see errors (until we merge our changes in.)

Make sure you are using a fully up to date version of C++Builder 12.2. We released two patches. Install both. This is a general good tip, but the second patch solves a regression introduced in the first patch, and you need that fixed in order to compile a super complex library like VTK.

Documentation & Demos

Our RAD Studio 12 demos on Github contain several CMake demos including for VCL and FMX apps and open source libraries OpenCV, VTK, and libsimdpp.

Find these in the CPP/CMake path. Make sure you have CMake and ninja installed, and optionally Python for OpenCV, and just run one of the batch files.

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

All the CMake demo scripts from our Github

Here you see ‘make-jsoncpp.bat’, for example, which builds JSON CPP with CMake and C++Builder 12.2. Similar for ZLib, libsimdpp, VTK, Google Test, Drogon, Brotli, and OpenCV.

There are also examples ‘make-vcl’, ‘make-fmx’, ‘make-package’ etc, which builds VCL and FMX apps, packages, and console apps with CMake.

Docs

The batch files are very focused on being literally ‘click and run’ to make the ability to use CMake as obvious as possible. But if you want to build yourself, you’ll want to dig in to what they do. Our CMake documentation explains everything you need to know.

You set up some variables (which platform you’re building for, ie Windows, architecture (x86-64), which compiler to use, ie bcc64x, etc. This is set up because in future, maybe there will be other options.) Thereafter, existing CMakeLists.txt configs should work as-is. Everything is listed in the doc page and you can use the demo scripts as examples.

For building VCL and FMX apps or packages, you set up a C++Builder “target”, saying that you’re linking to VCL or FMX, and the app type (eg normal app, package), and if it’s dynamically or statically linked. Again, full info is on the doc page, including sample CMake scripts, and please look at the samples on our Github too.

(If you are building your own C++Builder apps using CMake, we also recommend looking into the –jobs parameter to build via msbuild, since it is more efficient than CMake + ninja. This is on by default for C++Builder 12.2 and the new toolchain, so just doing a commandline ‘msbuild myproject.cbproj’ should use it.)

General Libraries

In general, open source libraries should build without modifications. We have rarely found that some libraries have ifdef-s for BORLANDC which need to be removed (they were workarounds for issues that no longer exist.) If it builds with MinGW, ie if you can find it on msys2, it should build with our toolchain.

If for some reason you do need to add specific support for the new toolchain (if this is a library bug, please send it back to them; if it is a bug in our toolchain, please let us know, this should not be required) then you can test for it following the ifdef suggested here.

Have fun building, and we hope you enjoy everything the new C++Builder 12.2 toolchain gives you!

 

 

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.

Leave a Reply

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

IN THE ARTICLES