Skip to content

yehuthi/godot_cpp_cmake_template

Repository files navigation

Godot C++ CMake Template ⚙️🎮

A minimal, no-cruft template for creating a Godot project paired with a C++ GDExtension, built using CMake.

✨ Features

  • 🧼 Clean and minimal
  • 🛠️ Single-command setup for quick start
  • 🌍 Cross-platform (tested on 🪟 Windows, 🐧 Linux, and 🍎 macOS)
  • 🧩 VSCode Snippets for Godot boilerplate

🚀 Getting Started

git clone git@github.com:yehuthi/godot_cpp_cmake_template.git PROJECT_DIRECTORY

On 🪟 Windows: run init.ps1
On 🐧 Linux and 🍎 macOS: run ./init

Tip

The init script has no magic in it, it will simply ask you for a project name, get an initial build going, and do some clean-up.

📁 The Godot project lives in game, and the GDExtension source files live in src.

👷 Manual Setup

git clone git@github.com:yehuthi/godot_cpp_cmake_template.git PROJECT_DIRECTORY
cd PROJECT_DIRECTORY
git submodule update --init --recursive
mkdir build
cd build
cmake ..
cmake --build .

And then to clean up:

  • 🗑️ Remove src/gdexample.cpp, its header src/gdexample.hpp, and its reference inside src/register_types.cpp (though you might want to use it first to test the build works).
  • 🔍 Find & Replace godot_cpp_cmake_template with your project name.
  • 📝 Replace this README file with your own.

🧩 VSCode Snippets

Although the goal of this template is to be minimal, it includes VSCode snippets*. The rationale is that deleting a top-level directory (.vscode) is easy and fast, and the value of good snippets in a Godot project is great, as there is a lot of ritualistic boilerplate that has nothing to do with your project, and everything to do with data plumbing between your GDExtension and the Godot Engine.

All snippets start with gd, so you can simply begin to type it in a C++ file to explore your options, but here's an overview:

  • gdclass: creates a class declaration (place in .hpp).
    • gdclass_impl: implements gdclass methods (place in .cpp).
    • gdregister: registers your class (place in register_types.cpp's initialize_gdextension_module).
  • gdprop: creates a property declaration (place in .hpp).
    • gdprop_impl: implements gdprop declarations (place in .cpp).
    • gdprop_register: registers a property (place in _bind_methods in .cpp).
  • gdmethod: registers a method (place in _bind_methods in .cpp).

* In the future it will be a toggle in the init script.

🙏 Credits

Big thanks to mieko for testing on 🍎 macOS.

About

Godot 4 C++ GDExtension template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published