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:
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 +.
Step 9 Configure
cmake -B build -G "MinGW Makefiles"
Step 10 Build
cmake --build build
Step 11 Run
./build/MySketch.exe
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
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