Skip to content

Commit d75e7cd

Browse files
committed
Update CMake docs
1 parent c41b852 commit d75e7cd

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed

docs/godot_docs/cmake.md

+64-36
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,92 @@ This method requires a local RISC-V compiler installed on your system. If you do
1010

1111
CMake is completely optional. Normally, you can use Docker which compiles for you in the Godot editor.
1212

13-
## Setup & Installation
13+
## Build using Zig
1414

15-
There is a [CMake project in the Godot Sandbox](https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/cmake) repository that can be used to create ELFs with the API pre-included.
15+
In order to build programs you will need to install: CMake, git, Zig
1616

17-
The easiest way to access it is to create a symlink to the cmake folder above in your project so that you can directly reference it in CMake:
17+
[Download Zig](https://ziglang.org/download/) and add the extracted folder to PATH so that it becomes globally accessible. This means that typing `zig` from anywhere should work.
18+
19+
The easiest way to use CMake is to have a look at what [Godot Sandbox Programs](https://github.com/libriscv/godot-sandbox-programs) is doing. It has build scripts for Linux, macOS and Windows, and builds several projects for you.
20+
21+
Either fork the godot-sandbox-programs repository or copy it into a new one that you just created. Then go into the programs folder and remove everything except hello-world. Also edit `programs/CMakeLists.txt` to remove the other projects that you just deleted. You can rename hello-world, if you want.
22+
23+
Now you have two options:
24+
1. If you commit changes and push them, Github Actions will build programs for you and upload them to a draft release. These are ready-to-use and will be very small.
25+
2. You can build programs yourself using any of the root-level scripts. Linux/macOS: `./build.sh` Windows: `./build.cmd`
26+
27+
28+
## Manual CMake setup
29+
30+
There is a [CMake project in the Godot Sandbox](https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/cmake) repository that can be used to create ELFs with the API pre-included. This CMake script supports both RISC-V cross-compilers and Zig cross-compilation.
1831

1932
```cmake
2033
cmake_minimum_required(VERSION 3.10)
2134
project(example LANGUAGES CXX)
2235
23-
# Add the Godot Sandbox build functions
24-
add_subdirectory(cmake)
36+
# Fetch godot-sandbox repository (add_subdirectory is implicitly called)
37+
include(FetchContent)
38+
FetchContent_Declare(
39+
godot-sandbox
40+
GIT_REPOSITORY https://github.com/libriscv/godot-sandbox.git
41+
GIT_TAG main
42+
SOURCE_SUBDIR "program/cpp/cmake"
43+
)
44+
FetchContent_MakeAvailable(godot-sandbox)
2545
2646
add_sandbox_program(example
2747
example.cpp
2848
)
2949
```
3050

31-
Here `example` is a regular CMake target that you can use like normal. You can have as many programs as you want.
51+
Here `example` becomes a program that you can load in the sandbox. You can add as many programs as you want.
3252

33-
In order to build this project, we will use a simple build script:
53+
In order to build this project, we can use one of the scripts from the godot-sandbox-programs repository:
3454

35-
```sh
36-
#!/bin/bash
55+
1. [Linux 64-bit RISC-V cross compiler script](https://github.com/libriscv/godot-sandbox-programs/blob/main/build.sh)
3756

38-
# Change this to reflect your RISC-V toolchain
39-
export CC="riscv64-linux-gnu-gcc-14"
40-
export CXX="riscv64-linux-gnu-g++-14"
57+
2. [Linux/macOS Zig cross-compiler script](https://github.com/libriscv/godot-sandbox-programs/blob/main/zig.sh)
4158

42-
# Create build directory, configure and compile
43-
mkdir -p .build
44-
pushd .build
45-
cmake .. -DCMAKE_BUILD_TYPE=Release
46-
make -j4
47-
popd
48-
```
59+
3. [Windows Zig cross-compiler script](https://github.com/libriscv/godot-sandbox-programs/blob/main/zig.sh)
4960

50-
Remember to make the script executable:
5161

52-
```sh
53-
chmod +x build.sh
54-
```
62+
### macOS
63+
64+
You can use Zig as a cross-compiler. Have a look at the first chapter.
65+
66+
The [macOS github action](https://github.com/libriscv/godot-sandbox-programs/blob/main/.github/workflows/zig-macos.yml) shows you what dependencies to install and how to build on macOS.
67+
68+
The [Linux/macOS Zig cross-compiler script](https://github.com/libriscv/godot-sandbox-programs/blob/main/zig.sh) will also come in handy.
69+
70+
71+
### Windows
72+
73+
You can use Zig as a cross-compiler. Have a look at the first chapter.
74+
75+
The [Windows github action](https://github.com/libriscv/godot-sandbox-programs/blob/main/.github/workflows/zig-windows.yml) shows you how to build on Windows.
76+
5577

5678
### Ubuntu and Windows WSL2
5779

5880
On Linux and Windows WSL2 we can install a RISC-V compiler like so:
5981

6082
```sh
61-
sudo apt install g++-14-riscv64-linux-gnu cmake ninja-build git
83+
sudo apt install g++-14-riscv64-linux-gnu cmake git
6284
```
6385

64-
On some systems you may only have access to g++ version 12 or 13. Modify the `build.sh` below accordingly.
86+
This compiler can be referred to by setting CC and CXX:
87+
```sh
88+
export CC="riscv64-linux-gnu-gcc-14"
89+
export CXX="riscv64-linux-gnu-g++-14"
90+
```
91+
92+
On some systems you may only have access to compiler version 12 or 13. Modify your `build.sh` script accordingly.
93+
6594

6695
### Windows MSYS2
6796

97+
MSYS2 has a RISC-V compiler that is not capable of compiling all kinds of programs. But it's enough to compile most C++.
98+
6899
```sh
69100
pacman -Sy mingw-w64-x86_64-riscv64-unknown-elf-gcc ninja cmake git
70101
mkdir -p build
@@ -76,10 +107,6 @@ cmake --build .
76107
You can find a working [MSYS2 build example here](https://github.com/libriscv/godot-sandbox-demo/tree/master/json_diff_sample/json_diff). For `unknown-elf`-type toolchains a toolchain file is needed.
77108

78109

79-
### macOS
80-
81-
On macOS there are RISC-V toolchains in brew. Let us know which ones worked for you.
82-
83110
### Arch Linux
84111

85112
```sh
@@ -90,13 +117,13 @@ CXX=riscv64-linux-gnu-g++ CC=riscv64-linux-gnu-gcc cmake .. -G Ninja -DCMAKE_BUI
90117
ninja
91118
```
92119

93-
## CMake from Godot editor
120+
## Build with CMake from Godot editor
94121

95122
If there is a `CMakeLists.txt` in the project root or in a `cmake` folder, when saving C++ code in the editor, `cmake --build` will be executed instead as if the CMake build folder was `.build`. Docker is ignored.
96123

97124
If the CMake script is in project root, the build folder is also in project root: `./.build`, and if the CMake script is in `./cmake`, the build folder is in `./cmake/.build`. The CMake invocation is verbose, so pay attention to it in the Godot console.
98125

99-
This feature allows you to use your own CMake project and RISC-V toolchain to build all the programs with.
126+
This feature allows you to use your own CMake project and RISC-V toolchain to build all the programs with, all from within the Godot editor.
100127

101128
:::note
102129

@@ -111,13 +138,14 @@ Docker can be disabled per project.
111138

112139
Go to Project -> Project Settings and enable Advanced settings on the right. Scroll to Editor -> Script and disable Docker Enabled. You should no longer see any attempts at using Docker in this project.
113140

114-
## Auto-completion in editor
115141

116-
Auto-completion should automatically work if you symlink the `cmake` folder from Godot Sandbox to your project. If not, you can always add this path to your editor workspace:
142+
## Auto-completion in external editor
143+
144+
Auto-completion should automatically work when using the pre-made CMake script from Godot Sandbox. The CMake script gives your editor access to the C++ API and the run-time generated API. Combined this covers 100% of the Godot API.
117145

118-
https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/api
146+
### Manually accessing the C++ APIs
119147

120-
Adding the API path to your workspace should give you access to the C++ API.
148+
If it doesn't work, you can add this folder to your workspace: https://github.com/libriscv/godot-sandbox/tree/main/program/cpp/docker/api
121149

122150
The API has a run-time generated portion that is auto-created when saving in the editor. It can also be created manually from GDScript:
123151

@@ -167,6 +195,6 @@ If we now run `autobuild.sh` in a terminal window, it will automatically build o
167195

168196
:::note
169197

170-
Let us know if you have an autobuilder script for another platform!
198+
Let us know if you have made an autobuild script for another platform!
171199

172200
:::

docs/godot_intro/cppprogram.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The default C++ template should look something like this:
2121
```cpp
2222
#include "api.hpp"
2323

24-
extern "C" Variant public_function(String arg) {
24+
PUBLIC Variant public_function(String arg) {
2525
print("Arguments: ", arg);
2626
return "Hello from the other side";
2727
}

0 commit comments

Comments
 (0)