|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>CMake Setup - C++ Mode for Processing</title> |
| 7 | + <style> |
| 8 | + * { margin: 0; padding: 0; box-sizing: border-box; } |
| 9 | + body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #111; background: #fff; } |
| 10 | + a { color: #111; text-decoration: none; } |
| 11 | + nav { border-bottom: 1px solid #e0e0e0; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; height: 60px; position: sticky; top: 0; background: #fff; z-index: 100; } |
| 12 | + .layout { display: flex; min-height: calc(100vh - 60px); } |
| 13 | + .sidebar-outer { width: 220px; min-width: 220px; border-right: 1px solid #e0e0e0; display: flex; flex-direction: column; position: sticky; top: 60px; height: calc(100vh - 60px); } |
| 14 | + #site-sidebar { padding: 1.5rem 1.5rem 1rem; border-bottom: 1px solid #e0e0e0; display: flex; flex-direction: column; } |
| 15 | + #site-sidebar a { font-size: 14px; color: #555; padding: 0.4rem 0; display: block; } |
| 16 | + #site-sidebar a:hover { color: #111; } |
| 17 | + #site-sidebar a.active { color: #111; font-weight: 500; } |
| 18 | + .content { flex: 1; padding: 4rem; max-width: 860px; } |
| 19 | + .content h1 { font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 0.5rem; } |
| 20 | + .content .subtitle { color: #888; font-size: 0.95rem; margin-bottom: 2.5rem; } |
| 21 | + .content .back-link { font-size: 13px; color: #888; display: inline-block; margin-bottom: 2rem; } |
| 22 | + .content .back-link:hover { color: #111; } |
| 23 | + .content h2 { font-size: 1.25rem; font-weight: 600; margin: 2.5rem 0 0.75rem; } |
| 24 | + .content h3 { font-size: 1rem; font-weight: 600; margin: 1.75rem 0 0.6rem; } |
| 25 | + .content p { color: #444; line-height: 1.8; margin-bottom: 1rem; font-size: 0.95rem; } |
| 26 | + .content ul, .content ol { color: #444; line-height: 1.9; font-size: 0.95rem; margin: 0 0 1rem 1.25rem; } |
| 27 | + .content li { margin-bottom: 0.3rem; } |
| 28 | + .content code { font-family: "SF Mono","Fira Code",monospace; font-size: 13px; background: #f4f4f4; padding: 2px 6px; border-radius: 4px; } |
| 29 | + .content pre { font-family: "SF Mono","Fira Code",monospace; font-size: 13px; background: #0d0d0d; color: #ddd; padding: 1rem 1.25rem; border-radius: 8px; overflow-x: auto; margin-bottom: 1.25rem; line-height: 1.6; } |
| 30 | + .content pre code { background: none; padding: 0; color: inherit; } |
| 31 | + |
| 32 | + .platform-tabs { display: flex; gap: 0; margin: 2rem 0 0; border-bottom: 2px solid #e0e0e0; } |
| 33 | + .platform-tab { padding: 0.6rem 1.25rem; font-size: 14px; font-weight: 600; color: #888; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; } |
| 34 | + .platform-tab.active { color: #111; border-bottom-color: #111; } |
| 35 | + .platform-tab:hover { color: #111; } |
| 36 | + .platform-section { display: none; padding-top: 1.5rem; } |
| 37 | + .platform-section.active { display: block; } |
| 38 | + |
| 39 | + .warning-box { background: #fff8e0; border: 1px solid #f0dca0; border-radius: 8px; padding: 0.9rem 1.1rem; margin: 1rem 0; font-size: 14px; color: #6b5a1f; } |
| 40 | + .warning-box strong { font-weight: 700; } |
| 41 | + |
| 42 | + .ref-link { display: inline-block; font-size: 13px; font-weight: 600; border-bottom: 1px solid #ccc; padding-bottom: 1px; margin-top: 0.25rem; } |
| 43 | + .ref-link:hover { border-bottom-color: #111; } |
| 44 | + |
| 45 | + .next-steps { border-top: 1px solid #e0e0e0; margin-top: 3rem; padding-top: 2rem; display: flex; gap: 1.5rem; flex-wrap: wrap; } |
| 46 | + .next-steps a { font-size: 14px; font-weight: 600; border-bottom: 1px solid #ccc; padding-bottom: 2px; } |
| 47 | + .next-steps a:hover { border-bottom-color: #111; } |
| 48 | + |
| 49 | + .shot-placeholder { background: #f7f7f7; border: 1px dashed #ccc; border-radius: 8px; aspect-ratio: 16/9; max-width: 560px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #999; font-size: 12.5px; text-align: center; padding: 1rem; margin: 0.5rem 0 1.5rem; } |
| 50 | + .shot-placeholder .shot-filename { font-family: "SF Mono","Fira Code",monospace; font-weight: 700; margin-bottom: 0.35rem; color: #777; } |
| 51 | + .shot-img { width: 100%; max-width: 560px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; display: block; margin: 0.5rem 0 1.5rem; } |
| 52 | + .shot-img[hidden] { display: none; } |
| 53 | + |
| 54 | + footer { border-top: 1px solid #e0e0e0; padding: 2rem; text-align: center; font-size: 13px; color: #888; } |
| 55 | + @media (max-width: 768px) { |
| 56 | + .hamburger { display: block; } |
| 57 | + .sidebar-outer { position: fixed; top: 60px; left: -240px; width: 240px; height: calc(100vh - 60px); background: #fff; z-index: 200; transition: left 0.25s ease; box-shadow: 2px 0 12px rgba(0,0,0,0.08); } |
| 58 | + .sidebar-outer.open { left: 0; } |
| 59 | + .content { padding: 2rem 1.25rem; } |
| 60 | + } |
| 61 | + </style> |
| 62 | +</head> |
| 63 | +<body> |
| 64 | +<nav id="site-nav"></nav> |
| 65 | +<div class="layout"> |
| 66 | + <div class="sidebar-outer"> |
| 67 | + <div id="site-sidebar"></div> |
| 68 | + </div> |
| 69 | + <div class="content"> |
| 70 | + <a class="back-link" href="/downloads">← Back to Downloads</a> |
| 71 | + <h1>CMake Setup</h1> |
| 72 | + <p class="subtitle">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 <a href="/downloads/dragdrop-setup.html" style="border-bottom:1px solid #ddd;">Drag-and-Drop setup</a> first.</p> |
| 73 | + |
| 74 | + <p>Pick your operating system:</p> |
| 75 | + <div class="platform-tabs"> |
| 76 | + <div class="platform-tab active" onclick="switchTab('windows', this)">Windows</div> |
| 77 | + <div class="platform-tab" onclick="switchTab('macos', this)">macOS</div> |
| 78 | + <div class="platform-tab" onclick="switchTab('linux', this)">Linux</div> |
| 79 | + </div> |
| 80 | + |
| 81 | + <!-- WINDOWS --> |
| 82 | + <div class="platform-section active" id="tab-windows"> |
| 83 | + <h2>Steps 1-3 MSYS2 setup</h2> |
| 84 | + <p>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:</p> |
| 85 | + <pre><code>pacman -S --needed mingw-w64-x86_64-cmake</code></pre> |
| 86 | + <p>If you haven't done that setup yet, <a href="/downloads/dragdrop-setup.html" style="border-bottom:1px solid #ddd;">follow steps 1-3 there first</a>, then come back here.</p> |
| 87 | + |
| 88 | + <h2>Step 4 Get the CMake package</h2> |
| 89 | + <p>Download <strong>processing-cpp-cmake.zip</strong> from the <a href="/downloads" style="border-bottom:1px solid #ddd;">Downloads page</a>. Extract it. Rename the folder to <code>processing-cpp</code>.</p> |
| 90 | + |
| 91 | + <h2>Step 5 Set up your project folder</h2> |
| 92 | + <p>Create a <code>MySketch</code> folder. Your structure should look like this:</p> |
| 93 | + <pre><code>MySketch/ |
| 94 | +├── CMakeLists.txt ← you will create this |
| 95 | +├── main.cpp ← your sketch |
| 96 | +└── processing-cpp/ ← the folder you extracted</code></pre> |
| 97 | + |
| 98 | + <h2>Step 6 Write main.cpp</h2> |
| 99 | + <p>Same sketch code as in the drag-and-drop guide:</p> |
| 100 | + <pre><code>#include "Processing.h" |
| 101 | + |
| 102 | +struct Sketch : public Processing::PApplet { |
| 103 | + void settings() override { size(640, 360); } |
| 104 | + void setup() override { background(0); } |
| 105 | + void draw() override { |
| 106 | + background(0); |
| 107 | + fill(255, 140, 0); |
| 108 | + circle(mouseX, mouseY, 40); |
| 109 | + } |
| 110 | +}; |
| 111 | + |
| 112 | +int main() { |
| 113 | + Sketch sketch; |
| 114 | + sketch.run(); |
| 115 | +}</code></pre> |
| 116 | + <p> |
| 117 | + Uses <a class="ref-link" href="/reference/circle.html">circle()</a>, |
| 118 | + <a class="ref-link" href="/reference/fill.html">fill()</a>, |
| 119 | + <a class="ref-link" href="/reference/background.html">background()</a>, |
| 120 | + <a class="ref-link" href="/reference/mouseX.html">mouseX</a> / |
| 121 | + <a class="ref-link" href="/reference/mouseY.html">mouseY</a>. |
| 122 | + See the full <a class="ref-link" href="/reference">reference</a> for everything else. |
| 123 | + </p> |
| 124 | + |
| 125 | + <h2>Step 7 Write CMakeLists.txt</h2> |
| 126 | + <p>Open Notepad. Paste this exactly. Save it as <code>CMakeLists.txt</code> inside <code>MySketch</code>. Watch out: Notepad sometimes sneaks a <code>.txt</code> extension on the end. Make sure it's just <code>CMakeLists.txt</code> with no extra extension.</p> |
| 127 | + <pre><code>cmake_minimum_required(VERSION 3.16) |
| 128 | +project(MySketch CXX) |
| 129 | + |
| 130 | +add_subdirectory(processing-cpp) |
| 131 | + |
| 132 | +add_executable(MySketch main.cpp) |
| 133 | +target_link_libraries(MySketch PRIVATE processing_cpp)</code></pre> |
| 134 | + |
| 135 | + <h2>Step 8 Open MSYS2 MinGW 64-bit and navigate to your project</h2> |
| 136 | + <div class="warning-box"><strong>Important:</strong> Use MSYS2 MinGW 64-bit, not PowerShell or Command Prompt. The prompt should say MINGW64.</div> |
| 137 | + <pre><code>cd /c/Users/YourName/Desktop/MySketch</code></pre> |
| 138 | + |
| 139 | + <h2>Step 9 Configure</h2> |
| 140 | + <pre><code>cmake -B build -G "MinGW Makefiles"</code></pre> |
| 141 | + |
| 142 | + <h2>Step 10 Build</h2> |
| 143 | + <pre><code>cmake --build build</code></pre> |
| 144 | + |
| 145 | + <h2>Step 11 Run</h2> |
| 146 | + <pre><code>./build/MySketch.exe</code></pre> |
| 147 | + |
| 148 | + <img class="shot-img" src="../assets/screenshot13.png" alt="MSYS2 terminal running cmake build, MySketch.exe open" |
| 149 | + onerror="this.hidden=true; this.nextElementSibling.hidden=false;"> |
| 150 | + <div class="shot-placeholder" hidden> |
| 151 | + <span class="shot-filename">assets/screenshot13.png</span> |
| 152 | + <span>MSYS2 terminal running cmake --build, MySketch.exe running</span> |
| 153 | + </div> |
| 154 | + |
| 155 | + <div class="warning-box"><strong>If anything says "command not found":</strong> 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.</div> |
| 156 | + </div> |
| 157 | + |
| 158 | + <!-- MACOS --> |
| 159 | + <div class="platform-section" id="tab-macos"> |
| 160 | + <h2>Install CMake if you don't have it</h2> |
| 161 | + <pre><code>brew install cmake</code></pre> |
| 162 | + |
| 163 | + <h2>Steps 4-7 Same as Windows</h2> |
| 164 | + <p>Get the CMake package, rename the folder to <code>processing-cpp</code>, write <code>main.cpp</code> and <code>CMakeLists.txt</code> with the same content as above.</p> |
| 165 | + |
| 166 | + <h2>Configure, build, and run</h2> |
| 167 | + <p>Skip the <code>-G "MinGW Makefiles"</code> part on macOS. Just:</p> |
| 168 | + <pre><code>cmake -B build |
| 169 | +cmake --build build |
| 170 | +./build/MySketch</code></pre> |
| 171 | + |
| 172 | + <img class="shot-img" src="../assets/screenshot14.png" alt="macOS Terminal running cmake build, sketch window open" |
| 173 | + onerror="this.hidden=true; this.nextElementSibling.hidden=false;"> |
| 174 | + <div class="shot-placeholder" hidden> |
| 175 | + <span class="shot-filename">assets/screenshot14.png</span> |
| 176 | + <span>macOS Terminal running cmake --build, sketch window running</span> |
| 177 | + </div> |
| 178 | + </div> |
| 179 | + |
| 180 | + <!-- LINUX --> |
| 181 | + <div class="platform-section" id="tab-linux"> |
| 182 | + <h2>Install CMake if you don't have it</h2> |
| 183 | + <pre><code># Ubuntu / Debian |
| 184 | +sudo apt install cmake |
| 185 | + |
| 186 | +# Arch |
| 187 | +sudo pacman -S cmake</code></pre> |
| 188 | + <p>Also install the graphics libraries if you haven't yet:</p> |
| 189 | + <pre><code># Ubuntu / Debian |
| 190 | +sudo apt install g++ libglfw3-dev libglew-dev |
| 191 | + |
| 192 | +# Arch |
| 193 | +sudo pacman -S gcc glfw glew</code></pre> |
| 194 | + |
| 195 | + <h2>Steps 4-7 Same as Windows</h2> |
| 196 | + <p>Get the CMake package, rename the folder to <code>processing-cpp</code>, write <code>main.cpp</code> and <code>CMakeLists.txt</code> with the same content as above.</p> |
| 197 | + |
| 198 | + <h2>Configure, build, and run</h2> |
| 199 | + <pre><code>cmake -B build |
| 200 | +cmake --build build |
| 201 | +./build/MySketch</code></pre> |
| 202 | + </div> |
| 203 | + |
| 204 | + <div class="next-steps"> |
| 205 | + <a href="/downloads/dragdrop-setup.html">Want something simpler? Try Drag-and-Drop →</a> |
| 206 | + <a href="/downloads/vscode.html">Using VS Code? →</a> |
| 207 | + <a href="/reference">Browse the reference →</a> |
| 208 | + <a href="/examples">See more examples →</a> |
| 209 | + </div> |
| 210 | + </div> |
| 211 | +</div> |
| 212 | +<footer><p>C++ Mode for Processing</p></footer> |
| 213 | +<script> |
| 214 | +function switchTab(name, el) { |
| 215 | + document.querySelectorAll('.platform-tab').forEach(t => t.classList.remove('active')); |
| 216 | + document.querySelectorAll('.platform-section').forEach(s => s.classList.remove('active')); |
| 217 | + el.classList.add('active'); |
| 218 | + document.getElementById('tab-' + name).classList.add('active'); |
| 219 | +} |
| 220 | +</script> |
| 221 | +<script src="../assets/nav.js"></script> |
| 222 | +</body> |
| 223 | +</html> |
0 commit comments