Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

New in 10.2.3: CMake Support for iOS and Android

We’ve introduced some great new features for C++Builder in 10.2.3.  Last week, I wrote about CMake support for our compilers. That post covered what CMake is, and how to use it for Windows, both Win32 and Win64.  If you haven’t read it, please do; it’s worth reading before this post.

In this post, we’ll cover CMake for mobile, iOS, and Android.  This is both how to invoke CMake, and how to write mobile-specific information in a CMakeLists.txt file.

CMake for iOS and Android

When building with CMake and targeting Windows, you specify that you want to use our Win32 or Win64 C and C++ compilers. Once CMake knows what compiler you want to use, it takes it from there:

[crayon-67687ffd36f26160660945/]

This is because you are building and targeting the same platform.  You are building on Windows, and targeting Windows.  But for iOS32, iOS64, and Android, you are building on a different platform than you are targeting: that is, you are cross-compiling.

To cross-compile, instead of specifying the compiler you use, you specify a toolchain.  This is a cmake file that tells CMake how to use the compilers and for our mobile platforms, contains full cross-compilation information.  These toolchain files also set up extra deployment options – things like the splash screen images – that are specific to each platform.

Our cross-compile toolchain files share the same name as the compiler they use, eg bccaarm (our compiler) is bccaarm.cmake.  Here are the command lines to use:

iOS32:

[crayon-67687ffd36f2c822383413/]

iOS64:

[crayon-67687ffd36f30568621736/]

Android:

[crayon-67687ffd36f31984430231/]

That’s even less to type than you use for Windows!

Don’t forget, this assumes that you’re invoking CMake from the folder where you CMakeLists.txt file is located.  If it’s somewhere else, you can specify the path at the end of the command line, eg “… -G Ninja ..” or “… -G Ninja c:mypath”.

Mobile-specific info in a CMakeLists.txt

Mobile targets are unlike Windows in that you can deploy your project to a mobile device, and that includes deploying a number of files that end up in the app bundle or package.  You do this through paserver as normal, so make sure paserver is installed and you can deploy through the IDE before you try on the command line.

We have a number of macros and variables you can use to tell CMake mobile-specific things, which include:

iOS:

Android:

Our documentation has a full list.  You can use all the macros and variables; some variables have preset fixed values which you can read in order to make target-specific configuration inside your CMakeLists.txt file.

Configuring CMakeLists.txt based on target

A CMakeLists.txt file is a generic project description, but you will want to have info in it that specifies, say, the Android manifest information that is used when targeting Android.  How do you do this?

The answer is to add an if statement based on the value of the EMBT_TARGET variable.  This is set for the platform, so for Android you would check

[crayon-67687ffd36f32178418647/]

EMBT_TARGET can be:

And you can use this to add info for each platform to your config.

Summary

That’s it!  The core points are:

Next up in this series on CMake: using Ninja!

Do you want to build an app for iOS and Android? Try to watch the Cross-Platform App Builder demos, which will assist you in developing apps in the Delphi or C++ environments.
Exit mobile version