← Back to Downloads

CMake Setup

Use this if your project already uses CMake, or if you want something more structured that scales to many source files. If you just want to get something running fast, try the Drag-and-Drop setup first.

Pick your operating system:

Windows
macOS
Linux

Steps 1-3 MSYS2 setup

Same as the drag-and-drop guide. If you already did that setup, just also install CMake while you're in the MSYS2 MinGW 64-bit terminal:

pacman -S --needed mingw-w64-x86_64-cmake

If you haven't done that setup yet, follow steps 1-3 there first, then come back here.

Step 4 Get the CMake package

Download processing-cpp-cmake.zip from the Downloads page. Extract it. Rename the folder to processing-cpp.

Step 5 Set up your project folder

Create a MySketch folder. Your structure should look like this:

MySketch/
├── CMakeLists.txt     ← you will create this
├── main.cpp           ← your sketch
└── processing-cpp/    ← the folder you extracted

Step 6 Write main.cpp

Same sketch code as in the drag-and-drop guide:

#include "Processing.h"

struct Sketch : public Processing::PApplet {
    void settings() override { size(640, 360); }
    void setup()    override { background(0); }
    void draw()     override {
        background(0);
        fill(255, 140, 0);
        circle(mouseX, mouseY, 40);
    }
};

int main() {
    Sketch sketch;
    sketch.run();
}

Uses circle(), fill(), background(), mouseX / mouseY. See the full reference for everything else.

Step 7 Write CMakeLists.txt

Open Notepad. Paste this exactly. Save it as CMakeLists.txt inside MySketch. Watch out: Notepad sometimes sneaks a .txt extension on the end. Make sure it's just CMakeLists.txt with no extra extension.

cmake_minimum_required(VERSION 3.16)
project(MySketch CXX)

add_subdirectory(processing-cpp)

add_executable(MySketch main.cpp)
target_link_libraries(MySketch PRIVATE processing_cpp)

Step 8 Open VS Code and the terminal

Open VS Code, go to File → Open Folder and select your MySketch folder. Open the integrated terminal with Ctrl+` and switch it to MSYS2 / MinGW64 using the dropdown arrow next to the +.

Important: Use the MinGW64 terminal, not PowerShell. The prompt should say MINGW64.

Step 9 Configure

cmake -B build -G "MinGW Makefiles"

Step 10 Build

cmake --build build

Step 11 Run

./build/MySketch.exe
MSYS2 terminal running cmake build, MySketch.exe open
assets/screenshot13.png MSYS2 terminal running cmake --build, MySketch.exe running
If anything says "command not found": you are in the wrong terminal. Close it, find MSYS2 MinGW 64-bit in your Start menu (look for MINGW64 in the title), and try again. This is the reason almost every time on Windows.

Install CMake if you don't have it

brew install cmake

Steps 4-7 Same as Windows

Get the CMake package, rename the folder to processing-cpp, write main.cpp and CMakeLists.txt with the same content as above.

Configure, build, and run

Skip the -G "MinGW Makefiles" part on macOS. Just:

cmake -B build
cmake --build build
./build/MySketch
macOS Terminal running cmake build, sketch window open
assets/screenshot14.png macOS Terminal running cmake --build, sketch window running

Install CMake if you don't have it

# Ubuntu / Debian
sudo apt install cmake

# Arch
sudo pacman -S cmake

Also install the graphics libraries if you haven't yet:

# Ubuntu / Debian
sudo apt install g++ libglfw3-dev libglew-dev

# Arch
sudo pacman -S gcc glfw glew

Steps 4-7 Same as Windows

Get the CMake package, rename the folder to processing-cpp, write main.cpp and CMakeLists.txt with the same content as above.

Configure, build, and run

cmake -B build
cmake --build build
./build/MySketch