Cute Framework is a simple, yet powerful C/C++ framework for building 2D games using the modern GPU pipeline. While C or C++ is fine, Swift is a modern language that many developers prefer for its safety and expressiveness. In this post, we will explore how to set up a project using Cute Framework with CMake, enabling you to write your game logic in Swift while leveraging the performance of C/C++ for rendering and other performance-critical tasks.
Prerequisites
Before we begin, ensure you have the following installed:
- Swift (latest version, preferably Swift 6 or later)
- CMake (we are going to use the most recent version 4.0, but 3.20+ should work just fine)
- Ninja (required for building Swift with CMake)
Setting Up the Project Structure
Create a new directory for your project and navigate into it:
Create the following directory structure:
The next step is to configure the CMakeLists.txt file. Open it in your favorite text editor and add the following content:
The CMakeLists.txt file defines few key components:
- It sets the project name and specifies that we will be using C, C++, and Swift. We use C and C++ as Cute Framework is written in C/C++.
- It collects all Swift source files in the src directory.
- It sets up the Cute Framework as a dependency using FetchContent, which allows us to download and include it directly in our project.
- It creates an executable target named MyCuteGame and links it with the Cute Framework.
- It includes the include directory for header files, which will be used for Swift interoperability.
Setting Up Swift Interoperability
To enable Swift to call C functions, we need to create a C header file and a module map. Open include/shim.h and add the following content:
The shim.h file includes the Cute Framework header, allowing Swift to access its functions.
Next, create the module map in include/module.modulemap:
This module map tells Swift how to import the C header file. The extern_c attribute indicates that this module is a C module, which is necessary for Swift interoperability.
With all that in place, we can now write our Swift code in src/main.swift. Open this file and add the following content:
Configure and Build the Project
Now that we have our project structure and code set up, we can configure and build the project using CMake. Open a terminal in the root directory of your project and run the following commands:
All that’s left is to run the executable. You can do this by executing:
This should launch your Cute Framework application, displaying a window with a spinning girl sprite.
And voila! You have successfully set up a Cute Framework project using CMake and Swift. You can now start building your game logic in Swift while leveraging the performance of C/C++ for rendering and other tasks.
I encourage you to explore the documentation, and especially the Getting Started guide.
There is also a Discord server where you can ask questions and share your projects: Cute Framework Discord.
Last modified: 06-Jun-25