Skip to content

Commit d986c73

Browse files
committed
Update CMake docs
1 parent c41b852 commit d986c73

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

docs/godot_docs/cmake.md

+42-10
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,53 @@ 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

3353
In order to build this project, we will use a simple build script:
3454

3555
```sh
3656
#!/bin/bash
3757

3858
# Change this to reflect your RISC-V toolchain
59+
# You can also use a Zig toolchain here if you want
3960
export CC="riscv64-linux-gnu-gcc-14"
4061
export CXX="riscv64-linux-gnu-g++-14"
4162

@@ -53,6 +74,19 @@ Remember to make the script executable:
5374
chmod +x build.sh
5475
```
5576

77+
### macOS
78+
79+
You can use Zig as a cross-compiler. Have a look at the first chapter.
80+
81+
The [macOS github action](https://github.com/libriscv/godot-sandbox-programs/blob/main/.github/workflows/zig-macos.yml) shows you how to build on macOS.
82+
83+
### Windows
84+
85+
You can use Zig as a cross-compiler. Have a look at the first chapter.
86+
87+
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.
88+
89+
5690
### Ubuntu and Windows WSL2
5791

5892
On Linux and Windows WSL2 we can install a RISC-V compiler like so:
@@ -65,6 +99,8 @@ On some systems you may only have access to g++ version 12 or 13. Modify the `bu
6599

66100
### Windows MSYS2
67101

102+
MSYS2 has a RISC-V compiler that is not capable of compiling all kinds of programs. But it's enough to compile most C++.
103+
68104
```sh
69105
pacman -Sy mingw-w64-x86_64-riscv64-unknown-elf-gcc ninja cmake git
70106
mkdir -p build
@@ -76,10 +112,6 @@ cmake --build .
76112
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.
77113

78114

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

85117
```sh

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)