Build GDExtension with CMake.
Thanks to vorlac for the detailed guide how to build GDExtensions with CMake.
Check his work here: https://github.com/vorlac/godot-gdextension-demo-cmake
- Open the project folder in Visual Studio.
- Select the configuration
x64 Release. - Let Visual Studio configure the project.
- Select the Startup Item
TemplateName.dll. - Build the project.
- Copy the contents of the
demo/addonsfolder into your project.
The extension will be built against the Godot 4.2 release and it should work just fine with Godot 4.3 but not 4.1.
Open CMakeLists.txt and replace godot-4.2-stable to build against a different version of Godot.
You can debug GDExtension with the released version of Godot or with the custom build. The latter helps trace bugs directly into the engine.
The routine is also a bit different whether you want to debug the tools code or the game code. Godot runs the game code in a separate process so you need to attach the debugger to that process.
- Open
.vs/launch.vs.jsonfile and replaceC:\\Development\\Godot\\Godot_v4.2.1-stable_win64_console.exewith your path. - Open the project folder in Visual Studio.
- Select the configuration
x64 Debug. - Let Visual Studio configure the project.
- Select the Startup Item
TemplateName (Godot 4.2).
TO DEBUG TOOLS
- Start Debugging (F5).
If everything worked correctly, the editor should automatically open the demo project.
TO DEBUG GAME
- Start Without Debugging (Ctrl+F5). The editor should open the demo project.
- Play the Project in Godot (F5).
- Return to Visual Studio and select
Debug > Attach to Process (Ctrl + Alt + P). - Select the process
Godot_v4.2.1-stable_win64.exe, the first one, and press the Attach button.
- Open the project folder in Visual Studio.
- Select the configuration
x64 Debug. - Let Visual Studio configure the project.
- Select the Startup Item
TemplateName (Custom 4.2).
TO DEBUG TOOLS
- Start Debugging (F5).
If everything worked correctly, the editor should automatically open the demo project.
TO DEBUG GAME
- Start Without Debugging (Ctrl+F5). The editor should open the demo project.
- Play the Project in Godot (F5).
- Return to Visual Studio and select
Debug > Attach to Process (Ctrl + Alt + P). - Select the process
Godot_v4.2.1-stable_win64.exe, the first one, and press the Attach button.
To debug with the custom build of Godot, you need to build Godot first. Don't worry, that is easy and it takes just 5 minutes to build the entire engine.
- Install Python 3.
- Run
x86_x64 Cross Tools Command Prompt for VS 2022as administrator. - Change directory to Godot folder. E.g.
cd /d E:\gdextension-cmake-template\godot - Install scons:
pip install scons - Edit
.gitmodulesif you want to use a different branch of the engine. The current one is 4.2. - Initialize Godot submodule:
git submodule update --init - Build Godot:
scons --directory=godot platform=windows target=editor arch=x86_64 debug_symbols=yes optimize=debug
- mkdir myextension
- cd myextension
- git init
- git submodule add -b 4.2 https://github.com/godotengine/godot
- git config -f .gitmodules submodule.godot.shallow true
- git submodule update --init
- copy .vs, demo, src, .gitignore, CMakeLists.txt, CMakePresets.json, LICENSE, README.md