Skip to content

Commit 975d794

Browse files
committed
Modernise Existing CMakeLists.txt
- Added to .gitignore CMakeUserPresets.json ### Configuration: - Changed python command to use single quotes to make build output log more legible. - Added GODOT_DEV_BUILD to allow differentiation of debug or Release builds. - Added find logic for macos Cocoa library ### godot-cpp Changes - godot-cpp-test is changed to be incorporated into the cmake build as a target. - Duplicated godot-cpp target into [template_release, template_debug, editor] - Created {platform}.cmake files mirroring the style of the SCons build. CMake has a feature called generator expressions for its configuration variables that are evaluated at build time. This allows multi-configuration build systems to properly evaulate options. for msvc, xcode and nijna multi-config. - Moved configuration options to generator expressions with the notable exclusion of OSX_ARCHITECTURES. - Remove CMAKE_BUILD_TYPE from msvc CI target as Multi-Config generators ignore it ### godot-cpp-test Changes - Removed majority of the cmake code, now that the godot-cpp project is setup, the majority of the flags will be propagated as transient dependencies - Marked with EXCLUDE_FROM_ALL so that it isn't built as part of the 'all' target - Updated ci to build the godot-cpp-test target from the root directory using cmake - Tests passing for Windows, Linux, and Macos builds. ### Documentation Updated with new information Added Emscripten example Added Android example
1 parent c20a84e commit 975d794

File tree

15 files changed

+1098
-495
lines changed

15 files changed

+1098
-495
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,6 @@ jobs:
207207
path: ${{ matrix.artifact-path }}
208208
if-no-files-found: error
209209

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 godot-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="../godot-headers" -DCPP_BINDINGS_PATH=".." .
232-
make -j $(nproc) VERBOSE=1
233-
234210
linux-cmake-ninja:
235211
name: 🐧 Build (Linux, GCC, CMake Ninja)
236212
runs-on: ubuntu-22.04
@@ -245,15 +221,12 @@ jobs:
245221
sudo apt-get update -qq
246222
sudo apt-get install -qqq build-essential pkg-config cmake ninja-build
247223
248-
- name: Build godot-cpp
249-
run: |
250-
cmake -DCMAKE_BUILD_TYPE=Release -GNinja .
251-
cmake --build . -j $(nproc) --verbose
252-
253224
- name: Build test GDExtension library
254225
run: |
255-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -GNinja .
256-
cmake --build . -j $(nproc) --verbose
226+
mkdir cmake-build
227+
cd cmake-build
228+
cmake ../
229+
cmake --build . --verbose -j $(nproc) -t godot-cpp-test
257230
258231
windows-msvc-cmake:
259232
name: 🏁 Build (Windows, MSVC, CMake)
@@ -264,12 +237,9 @@ jobs:
264237
with:
265238
submodules: recursive
266239

267-
- name: Build godot-cpp
268-
run: |
269-
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
270-
cmake --build . --verbose --config Release
271-
272240
- name: Build test GDExtension library
273241
run: |
274-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
275-
cmake --build . --verbose --config Release
242+
mkdir cmake-build
243+
cd cmake-build
244+
cmake ../
245+
cmake --build . --verbose -t godot-cpp-test --config Release

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,6 @@ venv
199199
# Clion Configuration
200200
.idea/
201201
cmake-build-*
202+
203+
# CMake related
204+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,90 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(godot-cpp LANGUAGES CXX)
3-
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 ()
132

14-
include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
3+
#[=======================================================================[.rst:
4+
5+
CMakeLists.txt
6+
==============
7+
8+
As we are attempting to maintain feature parity, and ease of maintenance, these
9+
CMake scripts are built to resemble the SCons build system.
10+
11+
The file structure and file content are made to match, if not in content then
12+
in spirit. The closer the two build systems look the easier they will be to
13+
maintain.
14+
15+
Where the SCons additional scripts in the tools directory, The CMake scripts
16+
are in the cmake directory.
17+
18+
For example, the tools/godotcpp.py is sourced into SCons, and the 'options'
19+
function is run.
1520
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.
21+
.. highlight:: python
1922
20-
# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake
23+
cpp_tool = Tool("godotcpp", toolpath=["tools"])
24+
cpp_tool.options(opts, env)
2125
26+
27+
The CMake equivalent is below.
28+
]=======================================================================]
29+
30+
include( cmake/godotcpp.cmake )
2231
godotcpp_options()
2332

33+
#[=======================================================================[.rst:
34+
35+
Configurations
36+
--------------
37+
There are two build main configurations, 'Debug' and 'Release', these are not
38+
related to godot's DEBUG_FEATURES flag. Build configurations change the default
39+
compiler and linker flags present when building the library, things like debug
40+
symbols, optimization.
41+
42+
The Scons build scripts don't have this concept, you can think of it like the
43+
SCons solution has a single default configuration. In both cases overriding the
44+
defaults is controlled by options on the command line, or in preset files.
45+
46+
Because of this added configuration and that it can be undefined, it becomes
47+
important to set a default, considering the SCons solution that does not enable
48+
debug symbols by default, it seemed appropriate to set the default to 'Release'
49+
if unspecified. This can always be overridden like below.
50+
51+
.. highlight:: shell
52+
53+
cmake <source> -DCMAKE_BUILD_TYPE:STRING=Debug
54+
55+
.. caution::
56+
57+
A complication arises from `Multi-Config Generators`_ that cannot have
58+
their configuration set at configure time. This means that the configuration
59+
must be set on the build command. This is especially important for Visual
60+
Studio Generators which default to 'Debug'
61+
62+
.. highlight:: shell
63+
64+
cmake --build . --config Release
65+
66+
.. _Multi-Config Generators:https://cmake.org/cmake/help/latest/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html
67+
]=======================================================================]
68+
get_property( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
69+
if( NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE )
70+
if( GODOT_DEV_BUILD )
71+
set( CMAKE_BUILD_TYPE Debug )
72+
else ()
73+
set( CMAKE_BUILD_TYPE Release )
74+
endif ()
75+
endif ()
76+
77+
#[[ Python is required for code generation ]]
78+
find_package(Python3 3.4 REQUIRED) # pathlib should be present
79+
80+
# Define our project.
81+
project( godot-cpp
82+
VERSION 4.4
83+
DESCRIPTION "C++ bindings for the Godot Engine's GDExtensions API."
84+
HOMEPAGE_URL "https://github.com/godotengine/godot-cpp"
85+
LANGUAGES CXX)
86+
2487
godotcpp_generate()
88+
89+
# Test Example
90+
add_subdirectory( test )

cmake/android.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[=======================================================================[.rst:
2+
Android
3+
-------
4+
5+
]=======================================================================]
6+
function( android_options )
7+
# Android Options
8+
endfunction()
9+
10+
function( android_generate TARGET_NAME )
11+
12+
target_compile_definitions(${TARGET_NAME}
13+
PUBLIC
14+
ANDROID_ENABLED
15+
UNIX_ENABLED
16+
)
17+
18+
common_compiler_flags( ${TARGET_NAME} )
19+
endfunction()

0 commit comments

Comments
 (0)