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.
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.
Table of Contents
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.
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:
- Install CMake from GetIt (in the IDE, go to Tools > GetIt Package Manager, type Cmake and press Enter in the search box, click Install;)
- Download and install ninja (it’s a single EXE; put it somewhere it can be found on your system PATH);
- And make sure you have a copy of git also installed somewhere on your system PATH.
- 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.
To do this:
- Go to the Start Menu, Apps, Embarcadero RAD Studio Command Prompt (x64)
- Navigate to wherever you downloaded the demos: cd “c:pathtoRADStudio12DemosCPPCMake”
- Run any of the make-*.bat files.
That’s it.
The demos
We have inbuilt demos for a wide variety of software. This includes:
- make-vcl.bat: builds a basic VCL application
- make-fmx.bat: builds a basic FireMonkey application
- make-console.bat: a simple console app
- 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.
- 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?
- 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.
- 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.
- make-googletest.bat: Builds Google Test, which is a common C++ unit testing framework.
- make-jsoncpp.bat: Builds a common C++ JSON parsing and serialization library
- 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 🙂
- 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 🙂
- 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”.
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:
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:
- Support dynamic packages, including ones built by Delphi, and building them in C++
- Fast, CPU-saturating multi-core compilation (we’ll blog about this soon)
- 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.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Wow – reads as if Christmas and Easter were at the same time. Will test this in the coming weeks …
So far, the feedback from C++ devs has been very positive. We have further to go but with CLANG support and the CMAKE changes things are definitely heading in a positive direction.
Sì, la versione 12 è stata una svolta definitiva verso la modernità. Grazie per l’impegno!
Yes, version 12 was a definitive turn towards modernity. Thanks for your effort!
This is good news! I can now build and debug my C++ Builder programs using CLion, which sometimes is useful.
Is there a full list of what can be passed to the set_embt_target CMake function? For example, in one of my projects, I have to use this line:
set_embt_target(Project1 VCL Unicode)
otherwise it tries to call non-unicode Windows API functions. I can’t remember how I knew to add Unicode as a parameter for the function – must have been from previous uses of C++ Builder 11 and CMake. Thankfully it worked!
Depending on what I’m doing, I have to add link and include paths to my CMakeLists.txt – I’m not certain that all the ‘usual’ C++ Builder VCL paths get brought into projects automatically. It’s not a big deal, as once present it all builds correctly.
Maybe the documentation could be expanded to recommend the ‘best’ (if there is such a thing as best) way to configure CMake is for C++ Builder with lots of VCL controls and 3rd party libs?
Finally the much awaited good news! Now it’s getting serious!
I have more or less abandoned C++ Builder because of lack of CMake support and modern C++ features lacking.
This sounds promising. When can one try it out using the Community edition?
Hi Totte, right now we don’t have any timescales for the next Community Edition. The current C++Builder CE is roughly equivalent to C++Builder 12.1. You can download the trial of C++Builder 12.2 Architect and try out the new features and see if it gives you what you’re looking for.
Hello, I did install the 12.2 trial and went ahead to try building VTK following the information on this page. Installed the special CMake using Getit, (it says its the version 3.30.2).
However, the build fails (just typing “make” in the “..RADStudio12Demos/CPP/CMake” folder) with errors “Error E4334 D:/projects/RADStudio12Demos/CPP/CMake/vtk/Common/Core\SMP/Sequential/vtkSMPToolsImpl.txx 98(48): explicit specialization of ‘Initialize’ after instantiation
void vtkSMPToolsImpl::Initialize(int);”
It seem to build all other targets okay. Didn’t try OpenCV though.
Any pointers?
-totte
It’s the same problem for me, OpenCV is OK.
I also try to compile PCL library, and it doesn’t work, too much dependencies. It will be easier with the cmakeGui to configure easily the compilation parameters.
Using CMake with C++ Builder 10.2. It works, but the RTL is linked only dynamically, and when running the resulting EXE on a system where C++ Builder is not installed, I get a message about missing files like rtl270.bpl, etc. I’m wondering if there is an ability to link the RTL statically with CMake in the latest C++ Builder version?
Hello! Yes, I need to blog about this soon, but please see https://docwiki.embarcadero.com/RADStudio/Athens/en/Using_CMake_with_C%2B%2B_Builder . In set_embt_target(), add DynamicRuntime, or omit it to link statically.
A script that begins like this will link this VCL app statically:
project(MyProject)
file(GLOB SOURCES “${CMAKE_SOURCE_DIR}/*.cpp”)
add_executable(Project1 WIN32 ${SOURCES})
set_embt_target(Project1 VCL)
Hi David,
The CMakeLists.txt code you are referring to still provides dynamic linking for C++ Builder 10.2. Do you mean that in the latest C++ Builder the default behavior has changed to static linking?
Yes, the new CMake support is different — a fully new implementation. For various reasons static linking is the default unless you specify dynamic (all sorts of random internals around how the toolchain works.) The set_embt_target method is similar but has changed, the first parameter is the target, so please keep an eye out there too.
Hi David, It’s great! The only thing that is missing for me to upgrade my C++ Builder 10.2 to the newest version is the lack of C++20 support. I hope it will be easy to add in the near future since you have moved to the new toolchain.
I have just built VTK 9.3 with bcc64x.
According to recipe given here.
All libs were built 🙂 Great – thank you Embarcadero!
I still have to test these, of course.
dll are build – I prefere static libs – there is maybe a flag in the make-vtk.bat?
So far I have been using VTK 7.1.1 with bcc64.
In 7.1.1 there was still the component vtkBorlandRenderWindowPkg (VTK-7.1.1\Examples\GUI\Win32\vtkBorland\Package)
This is no longer available in VTK 9.3 – you probably have to integrate it yourself.
I’ll see if you can upgrade the code from VTK 7.1 or from VKT 8.2.
Has anyone done that yet?
Or does anyone have other suggestions?