So I just learned something, thought I'd share.
Check this out:
user@k:~/Desktop/gamedev_progression/0009-avoid_the_walls_v2$ tree -a
.
├── avoid_the_walls_v2
├── avoid_the_walls_v2.html
├── avoid_the_walls_v2.js
├── avoid_the_walls_v2.wasm
├── desktop
│ ├── .clangd
│ ├── loop_desktop.cpp
│ └── Makefile
├── loop.h
├── main.cpp
├── Makefile
└── web
├── .clangd
├── loop_web.cpp
└── Makefile
3 directories, 13 files
I was about to start incorporating the emscripten_set_main_loop_arg()
from yesterday when I started thinking, "Hey, what if my IntelliSense filled in the Emscripten stuff.".
So an hour later I learned more than I wanted to know about clangd (my LSP) and how it knows about header files. I also still don't know enough to explain it properly. But has that stopped me yet?
AI: I could help with this.
Hold on, you'll get a turn.
So for each platform you are targeting I guess it's common practice to separate the code - in my case it's desktop and the web - so I created a desktop folder with its share of the Makefile logic, a web folder with the same, and then each platform gets its own .clangd file.
I bet the desktop one wouldn't have been necessary, but no harm in having it.
So now I can run make
in my user@k:~/Desktop/gamedev_progression/0009-avoid_the_walls_v2
folder and voila, I get everything built, plus I get IntelliSense for each platform. Ask your AI to set you up with this, or steal mine. Here's the web one:
CompileFlags:
Add:
- -DPLATFORM_WEB
- -D__EMSCRIPTEN__
- -I/home/user/Desktop/emsdk/upstream/emscripten/cache/sysroot/include
The only downside is multiple files/directories, which I'm sure is actually a bonus too once a project gets big enough.
Ok AI, your turn.
AI: Great summary! To add a bit more detail: language servers like clangd rely on configuration files (like
.clangd
) and/or compilation databases (compile_commands.json
) to understand how your code is built for each platform. By splitting your code into platform-specific folders and providing a.clangd
file for each, you ensure that clangd (or any language server) knows exactly which include paths, defines, and flags to use for that platform. This avoids confusion from mixed build settings and gives you accurate code completion, diagnostics, and navigation for each target.This approach is especially helpful for C++ projects targeting multiple platforms (like desktop and web with Emscripten), where build flags and dependencies can differ significantly. Keeping things organized at the folder level makes both building and editing smoother as your project grows.
So there it is, another high level overview of what is probably elementary basics. Well I wouldn't have minded this explanation an hour ago. Everything I found online was written for programmers or something.