Tutorial 02: Setting Up Your Dev Environment
What you’ll learn
- Installing the toolchain and system dependencies CNA needs.
- Cloning CNA together with its sibling repositories and configuring the build.
- Running the test suite to confirm the build is healthy.
- Getting your IDE to resolve CNA headers.
Before you start — Tutorial 01: Introduction to CNA for context, though nothing here depends on it. You need a working C++ compiler and CMake before you begin.
System Requirements
These are the requirements this snapshot can actually back with evidence. CMake enforces a minimum CMake version and the C++23 language standard, but no compiler-version check exists anywhere in CNA’s build files, so the compiler row below records what CNA’s continuous integration builds with rather than a guaranteed minimum.
| Component | Requirement |
|---|---|
| Compiler | A C++23 compiler whose standard library ships <format> (CNA’s always-built content-pipeline module uses it), so a GCC older than 13 will not do. CI builds Linux with GCC 14 on ubuntu-24.04, macOS with AppleClang on macos-26, Windows with MSVC (windows-latest, manual workflows) and mingw-w64 GCC, and WebAssembly with emsdk 6.0.3. Clang on Linux is not exercised by any build workflow. |
| Build system | CMake 3.20 or newer. CMake 3.30 or newer is needed for the default one-libcna.so link layout (CNA_SHARED_LIBRARY) on native Linux/BSD builds with GCC or Clang; older CMake falls back to static archives. |
| Git | Any recent version; CNA needs five submodules (see below). |
| GPU driver | OpenGL ES 3.0 or OpenGL 3.0+ for the OPENGLES3 renderer. SDL_GPU on Linux needs a Vulkan driver at run time (for example mesa-vulkan-drivers). CI runs the GL renderer and SDL_GPU on Mesa software drivers (llvmpipe, lavapipe) under Xvfb, not on physical GPUs. |
| RAM | No minimum is published. Template-heavy translation units are memory-hungry; if the compiler is killed for lack of memory, lower the parallelism (-j2) for that build. |
| Disk | Plan for many gigabytes. The default configuration builds every test and example program; CNA’s own build notes measured about 104 MB per statically linked Debug executable across roughly 800 executables before the shared libcna.so layout existed. Build a specific target (below) rather than everything, and the vendored SDL is cached in the source tree (.sdl-prebuilt-*). |
| OS | Linux (CI: Ubuntu 24.04), Windows (MSVC or MinGW-w64; native Windows lanes are manual), macOS 13.3 or newer (a hard floor: CMake stops below it). iOS and Android are experimental or code-only; see Tutorial 80. |
SDL3 and SDL3_mixer are compiled from vendored submodules. You do not need to install them from your OS package manager — but the development packages for X11, Wayland, OpenGL and audio must already be installed when SDL is first built, or the vendored SDL is built without those drivers (the configure output prints the video drivers it ended up with). Installing packages later does not change an existing .sdl-prebuilt-* cache; delete that directory and reconfigure.
FFmpeg is optional. CNA_ENABLE_VIDEO is AUTO by default: if the libavcodec, libavformat, libavutil and libswresample development packages are found, Video/VideoPlayer get a real decoder; if not, configure still succeeds and those types throw NotSupportedException when used. Pass -DCNA_ENABLE_VIDEO=OFF to skip FFmpeg entirely, or ON to make its absence an error. FFmpeg is never built for Windows, Emscripten, Android or iOS.
Installing Dependencies
Ubuntu / Debian
This is the package set CNA’s own Linux CI installs on Ubuntu 24.04 (the minimal sufficient subset has not been measured). It covers the compiler, the GL/EGL headers the GL renderers need, libcurl and nlohmann-json (Gamer Services and networking, which are on by default, require them on desktop), the X11 and Wayland development packages the vendored SDL3 needs for its x11 and wayland video drivers, and ALSA/PulseAudio for audio:
sudo apt update
sudo apt install -y --no-install-recommends \
g++-14 cmake ninja-build ccache git pkg-config \
libcurl4-openssl-dev nlohmann-json3-dev \
libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev \
libx11-dev libxext-dev libxrandr-dev libxi-dev libxcursor-dev \
libxfixes-dev libxss-dev libxtst-dev \
libwayland-dev wayland-protocols libxkbcommon-dev \
libasound2-dev libpulse-dev libudev-dev libdbus-1-dev \
xvfb x11-utils
Optional: mesa-vulkan-drivers (or your GPU vendor’s Vulkan driver) if you want to run SDL_GPU, libavcodec-dev libavformat-dev libavutil-dev libswresample-dev for FFmpeg video (see the callout above), and libdecor-0-dev if you want the vendored SDL3 to include client-side Wayland decorations. xvfb lets the window-creating tests run on a machine without a display.
Tell CMake which compiler to use on the first configure (the compiler is fixed when a build directory is first configured):
export CC=gcc-14 CXX=g++-14
g++-14 --version # Ubuntu 24.04's default g++ is 13; use the g++-14 package as CI does
Fedora / RHEL
CI runs Ubuntu only, so treat these as the equivalents of the list above, not as a tested recipe:
sudo dnf install -y \
gcc gcc-c++ cmake git ninja-build ccache pkgconf-pkg-config \
mesa-libGL-devel mesa-libEGL-devel mesa-libGLES-devel libcurl-devel json-devel \
libX11-devel libXext-devel libXrandr-devel libXi-devel libXcursor-devel \
libXfixes-devel libXScrnSaver-devel libXtst-devel \
wayland-devel wayland-protocols-devel libxkbcommon-devel \
alsa-lib-devel pulseaudio-libs-devel systemd-devel dbus-devel
For optional FFmpeg video, install the headers and link libraries for libavcodec, libavformat, libavutil and libswresample (ffmpeg-free-devel on Fedora; ffmpeg-devel from RPM Fusion on RHEL and derivatives).
Arch Linux
sudo pacman -Syu base-devel cmake git ninja ccache mesa curl nlohmann-json vulkan-icd-loader \
libx11 libxext libxrandr libxi libxcursor libxfixes libxss libxtst \
wayland wayland-protocols libxkbcommon alsa-lib libpulse dbus
# optional FFmpeg video: sudo pacman -S ffmpeg
macOS
Install Xcode or the Command Line Tools (AppleClang; CI uses macos-26), then brew install cmake ninja ccache (add ffmpeg if you want video — CI installs it, but it is optional). The deployment target defaults to macOS 13.3 and cannot be lowered. The default renderer on macOS is SDL_GPU on SDL’s Metal driver, which is not re-qualified on Apple hardware at this snapshot; SOFTWARE is the renderer macOS CI builds and runs. The bundled preset is cmake --preset macos (Release, SDL_GPU); Tutorial 109 covers the Mac in detail.
Windows (MSVC)
- Install Visual Studio 2022 with the "Desktop development with C++" workload.
- Install CMake 3.20+ and add it to
PATH. - Install Git for Windows.
Open a "Developer Command Prompt for VS 2022" for all subsequent commands. CNA’s native MSVC workflows (Direct3D and the content pipeline) are manual-dispatch only, so treat a Windows build as something you verify yourself. MinGW-w64 cross-builds from Linux use the cmake/toolchains/mingw-w64.cmake toolchain file (see Tutorial 80). Video is not built on Windows.
Cloning CNA and its sibling repositories
CNA's companion libraries are separate checkouts placed next to cna/, not submodules. A default Linux build needs three of them, because the Linux default renderer is OPENGLES3, which is implemented by EasyGL. Two revision rules matter for this snapshot: CNA and sharp-runtime must be on their next branch (a plain clone gives CNA’s default branch, main, which is the 0.1.0 release, and the snapshot uses sharp-runtime changes made after its own 0.1.0 tag), while easy-gl and meta-gl use their release tags v0.1.1 and v0.4.1. Since 0.1.0, CNA’s configure step reads each sibling’s declared version (sharp-runtime 0.1.x, easy-gl 0.1.1 or a later 0.1.x, meta-gl 0.4.1 or a later 0.4.x) and stops with the git checkout that fixes a mismatch; -DCNA_CHECK_DEPENDENCY_VERSIONS=OFF turns that into a warning.
| Sibling | Needed for |
|---|---|
sharp-runtime | Every build, without exception |
easy-gl | The three GL-profile renderers: OPENGLES3, OPENGL33, WEBGL2 |
meta-gl | Required by easy-gl |
mkdir my-cna-workspace
cd my-cna-workspace
# sharp-runtime first (required by every build) -- its next branch
git clone -b next https://github.com/libcna/sharp-runtime.git
# EasyGL and its own dependency -- needed for the default Linux renderer;
# the release tags CNA's configure check accepts
git clone -b v0.1.1 https://github.com/libcna/easy-gl.git
git clone -b v0.4.1 https://github.com/libcna/meta-gl.git
# CNA -- its next branch (this snapshot is commit 3b43bd8687ed46523d873f9bec4b32bd8481dcb5)
git clone -b next https://github.com/libcna/cna.git
# Initialize CNA's five submodules: third_party/SDL, third_party/SDL_mixer,
# third_party/draco, vendor/googletest and the avatar catalog
# modules/gamer-services/assets/avatars.
# Non-recursive is correct here, and much faster: --recursive only pulls
# nested submodules of SDL_mixer and Draco that CNA does not use.
cd cna
git submodule update --init
To reproduce this exact snapshot rather than the moving tip of next, run git checkout 3b43bd8687ed46523d873f9bec4b32bd8481dcb5 in cna/ before the submodule step. sharp-runtime’s next moves too; the version check catches a sibling from another release line, not every later commit on the same one. CNA’s CI clones the siblings shallowly and picks, for each, the first branch that exists among the pushed branch, the target branch, next and develop. For the 0.1.0 release instead, check out the v0.1.0 tag of CNA and of sharp-runtime.
After this, your workspace should look like:
my-cna-workspace/
├── sharp-runtime/ ← C# primitive types and BCL subset for C++ (next branch)
├── easy-gl/ ← the GL-profile renderer implementation (v0.1.1)
├── meta-gl/ ← required by easy-gl (v0.4.1)
└── cna/ ← the main CNA repository (next branch)
├── CMakeLists.txt
├── CMakePresets.json
├── cmake/ ← CMake modules and toolchain files
├── modules/ ← core, math, platform, graphics, audio, content, renderers/, ...
│ (gamer-services/assets/avatars/ is a submodule: the avatar catalog)
├── tools/ ← cna-content and the converters
├── third_party/ ← SDL, SDL_mixer, draco (submodules); enet, stb, dr_libs, cgltf
└── vendor/
└── googletest/ ← submodule, needed while CNA_BUILD_TESTS=ON
Important: the sibling directories must sit next to cna/, not inside it. CMake looks for them at ../sharp-runtime, ../easy-gl and so on, relative to the CNA root (override sharp-runtime’s location with -DCNA_SHARP_RUNTIME_ROOT=<path>). The libcna and openeggbert GitHub organisations host identical copies of cna, sharp-runtime, easy-gl and meta-gl; CNA’s CI clones from libcna.
Building CNA
OPENGLES3 (recommended, full 2D and 3D)
From inside the cna/ directory. This is also what you get on Linux if you pass no renderer flag at all. The first configure builds SDL3 and SDL3_mixer from source into .sdl-prebuilt-<os>-<arch>/ (the key can carry -wayland, -simulator and -min<version> suffixes) inside the CNA checkout; later configures and clean build directories reuse it while its recorded build manifest still matches:
cmake -S . -B build \
-DCNA_GRAPHICS_RENDERER=OPENGLES3 \
-DCMAKE_BUILD_TYPE=Debug
# A small first target -- the math-type tests -- to confirm the toolchain works:
cmake --build build --target CnaMathTests -j$(nproc)
# The whole aggregate test binary is large; build it when you need it:
cmake --build build --target CnaTests -j$(nproc)
On Linux with CMake 3.30 or newer and GCC or Clang, the engine is linked once into libcna.so and every executable links that library instead of carrying its own copy (-DCNA_SHARED_LIBRARY=OFF restores static linking).
SOFTWARE or SDL_GPU (no easy-gl/meta-gl checkout)
These need no easy-gl/meta-gl checkout, which makes them the quickest way to get a first build going with only sharp-runtime beside cna/. SOFTWARE needs no GPU at all (it renders off-screen; read pixels back with GetBackBufferData()); SDL_GPU draws in a window through SDL’s Vulkan driver on Linux:
cmake -S . -B build-software \
-DCNA_GRAPHICS_RENDERER=SOFTWARE \
-DCMAKE_BUILD_TYPE=Debug
cmake --build build-software --target CnaMathTests -j$(nproc)
--target CNA does not work. CNA is an INTERFACE umbrella library with no sources of its own, so it is not a buildable target. Build a real target — CnaTests (or one of the 22 focused test targets such as CnaMathTests), a demo such as cna_demo_2d, or cna_content_tool — or just run cmake --build build with no --target at all (which builds every test and example). You will still find the old command in some upstream documentation.
Release build
cmake -S . -B build-release \
-DCNA_GRAPHICS_RENDERER=OPENGLES3 \
-DCMAKE_BUILD_TYPE=Release
cmake --build build-release -j$(nproc)
Windows (MSVC Developer Prompt)
cmake -S . -B build -DCNA_GRAPHICS_RENDERER=SDL_GPU
cmake --build build --config Debug --target CnaMathTests
SDL_GPU is the Windows default (SDL picks its Direct3D 12 driver); it is not yet validated on native Windows, and it compiles custom ShaderEffect support out of Windows builds. The Windows-only DIRECTX9 (-DCNA_GRAPHICS_RENDERER=DIRECTX9) is the alternative and configures only on a Windows target; Tutorial 103 covers both.
CMake options reference
| Option | Values | Default |
|---|---|---|
CNA_GRAPHICS_RENDERER | Any one of the 10 renderer identities, e.g. OPENGLES3, OPENGL33, SDL_GPU, WEBGPU, SOFTWARE | WEBGL2 under Emscripten, SDL_GPU on Windows, macOS and iOS, OPENGLES3 elsewhere (Linux, Android, the BSDs) |
CNA_PLATFORM | SDL3, HEADLESS, TERMINAL (TERMINAL is POSIX-only) | SDL3 — windows, events, input and host services; it reaches Windows, X11, Wayland and macOS through SDL’s own video drivers. HEADLESS and TERMINAL have no window. |
CNA_AUDIO_PLATFORM | SDL3, NULL, ALSA (Linux only) | SDL3 — only SDL3 and ALSA provide a mixer (SOUND_ENABLED) |
CNA_ENABLE_SDL | AUTO, ON, OFF | AUTO — OFF builds without SDL and refuses any selection that needs it |
CNA_ENABLE_VIDEO | OFF, AUTO, ON | AUTO — FFmpeg video only when its four development packages are found |
CMAKE_BUILD_TYPE | Debug, Release, RelWithDebInfo | (empty) — CNA sets no default, so pass it explicitly (the presets do) |
CNA_BUILD_TESTS | ON, OFF | ON |
CNA_CNAEXT | ON, OFF | OFF — gates the CNAEXT extensions in CNA::Graphics (AsciiPostProcessEffect, CRTEffect, DepthEffect, DebugDraw, and the shader-package types) |
CNA_DEVICES | ON, OFF | OFF — gates the CNAEXT device layer |
CNA_STRICT_XNA_API | compile definition, not a CMake option | not defined — define it on the target you want checked and CNAEXT-marked declarations become [[deprecated]] warnings (errors under -Werror=deprecated-declarations); passing -DCNA_STRICT_XNA_API=ON to the CMake configure step does nothing |
CNA_ENABLE_NET | ON, OFF | ON — networking support (vendored ENet) |
CNA_SHARED_LIBRARY | ON, OFF | ON on native ELF Linux/BSD with GCC/Clang and CMake 3.30+, otherwise OFF — link the engine once as libcna.so |
Instead of naming the renderer with CNA_GRAPHICS_RENDERER you may turn on exactly one -DCNA_RENDERER_<NAME>=ON switch. The two forms are equivalent and must not be mixed. CNA also ships 17 CMake configure presets (build directories are cmake-build-<preset> inside the CNA checkout) — among them tests (Debug, OPENGLES3, tests and examples on), unit (the STUB renderer, tests only), multi-renderer, macos, ios, web (run it as emcmake cmake --preset web) and the sanitizer presets devices-asan, devices-tsan, devices-ubsan — usable with, for example, cmake --preset tests followed by cmake --build --preset tests.
C++ consumers normally bring the framework into their own build with add_subdirectory; see Tutorial 03. An opt-in installed C++ SDK exists too (-DCNA_INSTALL_CXX=ON, consumed with find_package(CNA); see Building CNA). The experimental C layer (CNA_BUILD_C_API=ON, which also requires CNA_ENABLE_NET=ON) declares a separate CNACApi package; no CI job builds it, so it is not a getting-started path.
Running the Test Suite
In this snapshot CNA ships 900 C++ test source files containing 11,927 statically discoverable GoogleTest-family definitions, covering math types, geometry, curves, packed vectors, game loop semantics, renderer cases, and more (alpha.1: 568 and 8,263). The tests compiled into a build depend on the selected renderer, platform, audio implementation, options, and host. Two ways to run them:
# 1. A focused suite: one of the 22 per-module test executables
cmake --build build --target CnaMathTests -j$(nproc)
./build/CnaMathTests
# 2. The aggregate binary, run directly with a GoogleTest filter.
# Window-creating cases need a display; on a headless machine use xvfb-run.
cmake --build build --target CnaTests -j$(nproc)
SDL_AUDIODRIVER=dummy xvfb-run -a ./build/CnaTests --gtest_filter='Vector*'
The focused targets are CnaAudioTests, CnaContentTests, CnaContentPipelineTests, CnaCoreTests, CnaDesignTests, CnaDiagnosticsTests, CnaDevicesTests, CnaDevicesExtTests, CnaGamerServicesTests, CnaGraphicsTests, CnaGraphicsExtTests, CnaInputModuleTests, CnaInspectorTests, CnaIntegrationTests, CnaMathTests, CnaMediaTests, CnaNetTests, CnaPhoneTests, CnaPlatformModuleTests, CnaRendererTests, CnaRuntimeTests and CnaStorageTests; a few exist only when their module is built (for example CnaInspectorTests needs -DCNA_BUILD_INSPECTOR=ON). CNA’s own tests preset describes running the CnaTests binary directly as the authoritative way to run the full suite. CTest also works for individual cases, because every GoogleTest case is registered by name:
# Run one case or family through CTest (window-creating cases need a DISPLAY)
ctest --test-dir build -R Vector2 --output-on-failure
# Run with verbose output, or show only failures
ctest --test-dir build -R Vector2 -V
ctest --test-dir build -R Vector2 --output-on-failure -Q
Do not run a bare ctest after building only CnaTests. CTest starts one process per case, and the registered inventory also includes many separate example and smoke executables that the CnaTests target does not build, so an unfiltered run reports those as failures. Some cases also share fixture paths and can race when run in parallel. Tests inherit the DISPLAY of the shell that launches them (CNA_TEST_DISPLAY is empty by default, and the live desktop display :0 is honoured only with -DCNA_TEST_ALLOW_LIVE_DISPLAY=ON), which is why the commands above use xvfb-run on a headless machine.
A passing run ends with GoogleTest’s summary ([ PASSED ] N tests.) or, under CTest, 100% tests passed, 0 tests failed out of N. The exact count depends on which renderer you configured, because renderer tests are registered only for the family you compiled. If something fails on a clean build, please open an issue with your renderer, platform and audio selections.
CTest labels use the renderer names, so ctest -L DIRECTX9 works on a configuration that includes that renderer, while the older -L D3D9 form matches nothing at all.
IDE Setup
VS Code
- Install the C/C++ extension and the CMake Tools extension.
- Open the
cna/folder in VS Code. - CMake Tools will detect
CMakeLists.txtautomatically. Select your kit (GCC 14, or another C++23 compiler whose standard library ships<format>). - In the status bar, choose the renderer: click "No Configure Preset" and add a configure preset, or use the CMake Tools settings to pass
-DCNA_GRAPHICS_RENDERER=OPENGLES3. - Press
F7to build, or click the build button in the status bar.
For IntelliSense to find CNA headers, CMake Tools uses the compile_commands.json that CNA exports by default (CNA_EXPORT_COMPILE_COMMANDS is ON with the Ninja and Makefile generators). If IntelliSense is confused, run "CMake: Configure" from the command palette.
CLion
- Open the
cna/directory as a CLion project. - CLion auto-detects CMakeLists.txt. Go to Settings → Build, Execution, Deployment → CMake.
- Add a CMake profile and set CMake options:
-DCNA_GRAPHICS_RENDERER=OPENGLES3. - Choose the toolchain (GCC or Clang). Make sure it points to a C++23-capable version.
- Build with
Ctrl+F9.
CLion's indexer will pick up CNA's headers (each module keeps its own modules/<name>/include/ directory) automatically once the CMake project is configured.
Neovim / Emacs (compile_commands.json)
CNA's CMake build exports build/compile_commands.json by default with the Ninja and Makefile generators (CNA_EXPORT_COMPILE_COMMANDS, on by default). Point your LSP (clangd) at it:
# Generate compile_commands.json (Ninja; the Makefile generator works too)
cmake -S . -B build -G Ninja -DCNA_GRAPHICS_RENDERER=OPENGLES3
# Symlink to project root for clangd
ln -s build/compile_commands.json compile_commands.json
clangd will then provide completion and diagnostics across all CNA headers.
The first configure takes several minutes because CMake builds SDL3 from source (no timing has been measured for this snapshot). Subsequent incremental builds are much faster, and if ccache is installed CNA uses it automatically (CNA_USE_CCACHE). Use -j$(nproc) (Linux) or --parallel (Windows/macOS) to parallelize, and lower it if the compiler runs out of memory.
With your environment set up and the tests passing, you are ready to write your first CNA game. Continue to Tutorial 03: Your First CNA Window.