Skip to content

Commit 307d4ea

Browse files
authored
Merge pull request #15 from Spartan322/merge/47f11bc
Merge commit godotengine/godot-cpp@47f11bc
2 parents a089d37 + 14a856d commit 307d4ea

33 files changed

+2015
-528
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Setup godot-cpp
2+
description: Setup build dependencies for godot-cpp.
3+
4+
inputs:
5+
platform:
6+
required: true
7+
description: Target platform.
8+
em-version:
9+
default: 3.1.62
10+
description: Emscripten version.
11+
windows-compiler:
12+
required: true
13+
description: The compiler toolchain to use on Windows ('mingw' or 'msvc').
14+
type: choice
15+
options:
16+
- mingw
17+
- msvc
18+
default: mingw
19+
mingw-version:
20+
default: 12.2.0
21+
description: MinGW version.
22+
ndk-version:
23+
default: r23c
24+
description: Android NDK version.
25+
scons-version:
26+
default: 4.4.0
27+
description: SCons version.
28+
29+
runs:
30+
using: composite
31+
steps:
32+
- name: Setup Python (for SCons)
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: 3.x
36+
37+
- name: Setup Android dependencies
38+
if: inputs.platform == 'android'
39+
uses: nttld/setup-ndk@v1
40+
with:
41+
ndk-version: ${{ inputs.ndk-version }}
42+
link-to-sdk: true
43+
44+
- name: Setup Web dependencies
45+
if: inputs.platform == 'web'
46+
uses: mymindstorm/setup-emsdk@v14
47+
with:
48+
version: ${{ inputs.em-version }}
49+
no-cache: true
50+
51+
- name: Setup MinGW for Windows/MinGW build
52+
if: inputs.platform == 'windows' && inputs.windows-compiler == 'mingw'
53+
uses: egor-tensin/setup-mingw@v2
54+
with:
55+
version: ${{ inputs.mingw-version }}
56+
57+
- name: Setup SCons
58+
shell: bash
59+
run: |
60+
python -c "import sys; print(sys.version)"
61+
python -m pip install scons==${{ inputs.scons-version }}
62+
scons --version

.github/workflows/ci.yml

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,11 @@ jobs:
108108
cache-name: ${{ matrix.cache-name }}
109109
continue-on-error: true
110110

111-
- name: Set up Python (for SCons)
112-
uses: actions/setup-python@v5
111+
- name: Setup godot-cpp
112+
uses: ./.github/actions/setup-godot-cpp
113113
with:
114-
python-version: 3.x
115-
116-
- name: Android dependencies
117-
if: matrix.platform == 'android'
118-
uses: nttld/setup-ndk@v1
119-
with:
120-
ndk-version: r23c
121-
link-to-sdk: true
122-
123-
- name: Web dependencies
124-
if: matrix.platform == 'web'
125-
uses: mymindstorm/setup-emsdk@v14
126-
with:
127-
version: ${{ env.EM_VERSION }}
128-
no-cache: true
129-
130-
- name: Setup MinGW for Windows/MinGW build
131-
if: matrix.platform == 'windows' && matrix.flags == 'use_mingw=yes'
132-
uses: egor-tensin/setup-mingw@v2
133-
with:
134-
version: 12.2.0
135-
136-
- name: Install scons
137-
run: |
138-
python -m pip install scons==4.0.0
114+
platform: ${{ matrix.platform }}
115+
windows-compiler: ${{ contains(matrix.flags, 'use_mingw=yes') && 'mingw' || 'msvc' }}
139116

140117
- name: Generate redot-cpp sources only
141118
run: |
@@ -207,30 +184,6 @@ jobs:
207184
path: ${{ matrix.artifact-path }}
208185
if-no-files-found: error
209186

210-
linux-cmake:
211-
name: 🐧 Build (Linux, GCC, CMake)
212-
runs-on: ubuntu-22.04
213-
steps:
214-
- name: Checkout
215-
uses: actions/checkout@v4
216-
with:
217-
submodules: recursive
218-
219-
- name: Install dependencies
220-
run: |
221-
sudo apt-get update -qq
222-
sudo apt-get install -qqq build-essential pkg-config cmake
223-
224-
- name: Build redot-cpp
225-
run: |
226-
cmake -DCMAKE_BUILD_TYPE=Release .
227-
make -j $(nproc) VERBOSE=1
228-
229-
- name: Build test GDExtension library
230-
run: |
231-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../redot-headers" -DCPP_BINDINGS_PATH=".." .
232-
make -j $(nproc) VERBOSE=1
233-
234187
linux-cmake-ninja:
235188
name: 🐧 Build (Linux, GCC, CMake Ninja)
236189
runs-on: ubuntu-22.04
@@ -245,15 +198,12 @@ jobs:
245198
sudo apt-get update -qq
246199
sudo apt-get install -qqq build-essential pkg-config cmake ninja-build
247200
248-
- name: Build redot-cpp
249-
run: |
250-
cmake -DCMAKE_BUILD_TYPE=Release -GNinja .
251-
cmake --build . -j $(nproc) --verbose
252-
253201
- name: Build test GDExtension library
254202
run: |
255-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../redot-headers" -DCPP_BINDINGS_PATH=".." -GNinja .
256-
cmake --build . -j $(nproc) --verbose
203+
mkdir cmake-build
204+
cd cmake-build
205+
cmake ../ -DTEST_TARGET=template_release
206+
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
257207
258208
windows-msvc-cmake:
259209
name: 🏁 Build (Windows, MSVC, CMake)
@@ -264,12 +214,9 @@ jobs:
264214
with:
265215
submodules: recursive
266216

267-
- name: Build redot-cpp
268-
run: |
269-
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
270-
cmake --build . --verbose --config Release
271-
272217
- name: Build test GDExtension library
273218
run: |
274-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../redot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
275-
cmake --build . --verbose --config Release
219+
mkdir cmake-build
220+
cd cmake-build
221+
cmake ../ -DTEST_TARGET=template_release
222+
cmake --build . --verbose -t godot-cpp-test --config Release

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,7 @@ venv
198198

199199
# Clion Configuration
200200
.idea/
201-
cmake-build-*
201+
cmake-build*/
202+
203+
# CMake related
204+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
1-
cmake_minimum_required(VERSION 3.13)
2-
project(godot-cpp LANGUAGES CXX)
1+
cmake_minimum_required(VERSION 3.17)
32

4-
# Configure CMake
5-
# https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965
6-
# https://stackoverflow.com/questions/74426638/how-to-remove-rtc1-from-specific-target-or-file-in-cmake
7-
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
8-
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
9-
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
10-
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
11-
endif ()
12-
endif ()
3+
#[=======================================================================[.rst:
134
14-
include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
5+
CMake Version requirements
6+
--------------------------
157
16-
# I know this doesn't look like a typical CMakeLists.txt, but as we are
17-
# attempting mostly feature parity with SCons, and easy maintenance, the closer
18-
# the two build systems look the easier they will be to keep in lockstep.
8+
To enable use of the emscripten emsdk hack for pseudo shared library support
9+
without polluting options for consumers we need to use the
10+
CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE which was introduced in version 3.17
1911
20-
# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake
12+
Scons Compatibility
13+
-------------------
2114
15+
There is an understandable conflict between build systems as they define
16+
similar concepts in different ways. When there isn't a 1:1 relationship,
17+
compromises need to be made to resolve those differences.
18+
19+
As we are attempting to maintain feature parity, and ease of maintenance, these
20+
CMake scripts are built to resemble the SCons build system wherever possible.
21+
22+
The file structure and file content are made to match, if not in content then
23+
in spirit. The closer the two build systems look the easier they will be to
24+
maintain.
25+
26+
Where the SCons additional scripts in the tools directory, The CMake scripts
27+
are in the cmake directory.
28+
29+
For example, the tools/godotcpp.py is sourced into SCons, and the 'options'
30+
function is run.
31+
32+
.. highlight:: python
33+
34+
cpp_tool = Tool("godotcpp", toolpath=["tools"])
35+
cpp_tool.options(opts, env)
36+
37+
The CMake equivalent is below.
38+
]=======================================================================]
39+
40+
include( cmake/godotcpp.cmake )
2241
godotcpp_options()
2342

43+
#[[ Python is required for code generation ]]
44+
find_package(Python3 3.4 REQUIRED) # pathlib should be present
45+
46+
# Define our project.
47+
project( godot-cpp
48+
VERSION 4.4
49+
DESCRIPTION "C++ bindings for the Godot Engine's GDExtensions API."
50+
HOMEPAGE_URL "https://github.com/godotengine/godot-cpp"
51+
LANGUAGES CXX)
52+
53+
compiler_detection()
2454
godotcpp_generate()
55+
56+
# Test Example
57+
add_subdirectory( test )

cmake/android.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#[=======================================================================[.rst:
2+
Android
3+
-------
4+
5+
This file contains functions for options and configuration for targeting the
6+
Android platform
7+
8+
Configuration of the Android toolchain is done using toolchain files,
9+
CMakePresets, or variables on the command line.
10+
11+
The `Android SDK`_ provides toolchain files to help with configuration.
12+
13+
CMake has its own `built-in support`_ for cross compiling to the
14+
Android platforms.
15+
16+
.. warning::
17+
18+
Android does not support or test the CMake built-in workflow, recommend
19+
using their toolchain file.
20+
21+
.. _Android SDK:https://developer.android.com/ndk/guides/cmake
22+
23+
.. _built-in support:https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android
24+
25+
There is further information and examples in the doc/cmake.rst file.
26+
27+
]=======================================================================]
28+
function( android_options )
29+
# Android Options
30+
endfunction()
31+
32+
function( android_generate TARGET_NAME )
33+
34+
target_compile_definitions(${TARGET_NAME}
35+
PUBLIC
36+
ANDROID_ENABLED
37+
UNIX_ENABLED
38+
)
39+
40+
common_compiler_flags( ${TARGET_NAME} )
41+
endfunction()

0 commit comments

Comments
 (0)