Carbonated announces Madworld, a new mobile game built on O3DE | READ THE PR
NEWS & BLOGS | Tech Blog

Simplifying C++ Development in O3DE Using CMake

By O3DE | 06 Sep, 2023 | 4 min read

CMake, the most widely adopted build system in the C++ community, offers significant benefits for C++ development in O3DE, including streamlined project setup and simplified integration with open source projects. This blog series, authored earlier by Tom Hulton-Harrop, provides an overview of essential CMake functionality and how to apply it in O3DE.

The opening installment of this series demonstrates the minimal code required to set up a ‘Hello, World!’ application, which involves creating a new folder and generating empty main.cpp and CMakeLists.txt files. Although this process may appear slightly more involved than using Visual Studio to create a project, the significant advantage lies in creating a fully portable C++ program. This program can be built from source on any operating system supporting CMake, making it easy to share and allowing for swift integration of third-party libraries without the need for complex configuration settings in Visual Studio.

Get the step-by-step instructions here.

In the second part of this series, you’ll learn how to quickly integrate third-party libraries into your CMake projects by adding useful functionality to the ‘Hello, World’ application you created in the first part of this series. A recent addition of CMake addresses the historically challenging issue of dependency management in C++ through FetchContent. Using FetchContent, you can seamlessly incorporate external libraries into your project without the need to manually copy and configure them within your source tree. This approach is particularly effective for small, straightforward libraries that build quickly and become part of your application’s dependencies.

Get the step-by-step instructions here.

While FetchContent is suitable for smaller libraries, it may not be the right choice for larger dependencies like frameworks or packages. In the third part of this blog series, you’ll discover how to integrate larger dependencies into CMake projects and efficiently reuse them across multiple projects by building and installing them separately and then integrating them using the find_package command. This approach promotes code reuse and eliminates the need to rebuild dependencies every time the main codebase is rebuilt, which is particularly advantageous for stable libraries like Google Test, where updates are infrequent.

Get the step-by-step instructions here.

In the final installment of this series, you’ll learn about the essential commands required for installing a library so that it can be utilized in other projects. While previous blogs in this series have covered using CMake and integrating existing libraries, this concluding blog delves into the process of authoring new libraries with the aim of making them easily assimilable and user-friendly. You’ll also learn about each of CMake’s install commands and what’s needed to install a static library for use in other applications.

Get the step-by-step instructions here.

We hope you found this exploration of CMake and its application in O3DE helpful. If you have any questions or would like to discuss topics that weren’t addressed, please feel free to reach out on the O3DE Discord.

Subscribe for the latest updates, events, webinars and community news