Skip to content

Commit 49f50be

Browse files
committed
Merge pull request godotengine#1598 from enetheru/modernise
Modernise existing cmake options Merge pull request godotengine#1647 from enetheru/fix#1459 CMake: Align MSVC runtime (MD[d], MT) options to engine Merge pull request godotengine#1649 from enetheru/fix-backward-break CMake: fix break for build prior to modernisation PR CMake: Fix selection of MSVC Runtime compile flags My last attempt at solving this was not correct. I have left lots of comments in the source detailing the issue as it will effect consumers. Replace empty EXCLUDE variable with EXCLUDE_FROM_ALL This was a mistake left over from the modernise PR CMake: Handle GODOT_DEV_BUILD flag correctly .dev is added to output artifacts Warn users for specifying dev_build and Release build config Update documentation with deviations to SCons Update debug_symbols handling, its rolled into build config Cleanup helper variables and comments CMake: Enable using clang-cl on windows detect clang with MSVC frontend using CMAKE_CXX_COMPILER_FRONTEND_VARIANT Alleviate CMake target name clashes, visibility, and grouping. Simplify <platform>_generate cmake function signature, as TARGET_ALIAS and TARGET_NAME are still in scope and do not need to be passed. Add USE_FOLDERS, and FOLDER properties to group targets in VS and XCode Guard test target with GODOT_ENABLE_TESTING Tidy Small Issues remove RPATH_USE_ORIGIN from static libs add INTERFACE_POSITION_INDEPENDENT_CODE ON reset GODOT_ARCH property to SYSTEM_ARCH for macos because universal add MACOSX_RPATH to test target remove redundant properties from test target remove redundant and PUBLIC cxx_std_17 compile feature Privatise compiler options. CMake: Support using build_profile.json Python: - Redirect stdout for get_file_list to prevent stdout pollution CMake: - add GODOT_BUILD_PROFILE cache option - Split file list generation into its own function - add status and debug messages Python Snippets in CMake: - re-format for better readability Build Profile: - Add missing VisualInstance3D class to build_profile.json Add CMake support for XML documentation Implement generate_doc_source for cmake Implement generate_doc_source for cmake CMake: add lto options add a fake target to expose results of generator expressions move location of genex debug target so that it picks up the target details properly and allows us to generate for each type. first attempt Simplify Code Generation Variables - use generator expressions - use math for bits - simplify if statements Simplify SYSTEM_NAME generator expression. previous version created a list, which is semicolon delimited and then string REPLACED the semicolon to create a single string. New version uses string APPEND to create the string the first time. Update Target Properties - Using rpath for a static library is irrelevant, needs to be seet in consumers. - Add INTERFACE_POSITION_INDEPENDENT_CODE to propogate flag to consumers. Update macos - Add TODO for missing options - Fix formatting - Set GODOT_ARCH in case of arch being 'universal' - Simplify the test project when SYSTEM_NAME is Darwin Refactor common_compiler_flags.cmake - remove incorrectly propagated target_compile_features - remove GNU_ prefix on generic compiler version genex's - remove line breaks for simple genex's - make most flags private - comments Update Comments - Add TODO items for missing options - Add missing toolchain managed options commented out - Homogenise Headings and block comments replace ad-hock name construction with new GODOT_SUFFIX - This replicates how SCons does it. - Modify test project to use GODOT_SUFFIX - Add GODOT_SUFFIX to libgodot-cpp properties set web shared lib suffix to bring web builds into line with SCons
1 parent 56571dc commit 49f50be

21 files changed

+1606
-576
lines changed

.github/workflows/ci.yml

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

207-
linux-cmake:
208-
name: 🐧 Build (Linux, GCC, CMake)
209-
runs-on: ubuntu-20.04
210-
steps:
211-
- name: Checkout
212-
uses: actions/checkout@v4
213-
with:
214-
submodules: recursive
215-
216-
- name: Install dependencies
217-
run: |
218-
sudo apt-get update -qq
219-
sudo apt-get install -qqq build-essential pkg-config cmake
220-
221-
- name: Build godot-cpp
222-
run: |
223-
cmake -DCMAKE_BUILD_TYPE=Release .
224-
make -j $(nproc) VERBOSE=1
225-
226-
- name: Build test GDExtension library
227-
run: |
228-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." .
229-
make -j $(nproc) VERBOSE=1
230-
231207
linux-cmake-ninja:
232208
name: 🐧 Build (Linux, GCC, CMake Ninja)
233209
runs-on: ubuntu-20.04
@@ -242,15 +218,12 @@ jobs:
242218
sudo apt-get update -qq
243219
sudo apt-get install -qqq build-essential pkg-config cmake ninja-build
244220
245-
- name: Build godot-cpp
246-
run: |
247-
cmake -DCMAKE_BUILD_TYPE=Release -GNinja .
248-
cmake --build . -j $(nproc) --verbose
249-
250221
- name: Build test GDExtension library
251222
run: |
252-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -GNinja .
253-
cmake --build . -j $(nproc) --verbose
223+
mkdir cmake-build
224+
cd cmake-build
225+
cmake ../ -DGODOT_ENABLE_TESTING=YES -DTEST_TARGET=template_release
226+
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
254227
255228
windows-msvc-cmake:
256229
name: 🏁 Build (Windows, MSVC, CMake)
@@ -261,12 +234,9 @@ jobs:
261234
with:
262235
submodules: recursive
263236

264-
- name: Build godot-cpp
265-
run: |
266-
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
267-
cmake --build . --verbose --config Release
268-
269237
- name: Build test GDExtension library
270238
run: |
271-
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
272-
cmake --build . --verbose --config Release
239+
mkdir cmake-build
240+
cd cmake-build
241+
cmake ../ -DGODOT_ENABLE_TESTING=YES -DTEST_TARGET=template_release
242+
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: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
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+
# optionally add the godot-cpp-test integration testing target
57+
if( GODOT_ENABLE_TESTING )
58+
add_subdirectory( test )
59+
endif()
60+
61+
#[[ If this is the top level CMakeLists.txt, Generators which honor the
62+
USE_FOLDERS flag will organize godot-cpp targets under the subfolder
63+
'godot-cpp'. This is enable by default from CMake version 3.26 ]]
64+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

binding_generator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False, profil
268268

269269

270270
def print_file_list(api_filepath, output_dir, headers=False, sources=False, profile_filepath=""):
271-
print(*get_file_list(api_filepath, output_dir, headers, sources, profile_filepath), sep=";", end=None)
271+
import io
272+
from contextlib import redirect_stdout
273+
274+
# suppress stdout messages from get_file_list
275+
with redirect_stdout(io.StringIO()):
276+
file_list = get_file_list(api_filepath, output_dir, headers, sources, profile_filepath)
277+
278+
print(*file_list, sep=";", end=None)
272279

273280

274281
def parse_build_profile(profile_filepath, api):

cmake/android.cmake

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
29+
#[============================[ Android Options ]============================]
30+
function( android_options )
31+
#[[ The options present in the SCons build shown below are managed by
32+
toolchain files, further information can be found in doc/cmake.rst
33+
34+
android_api_level : Target Android API level.
35+
Default = 21
36+
37+
ANDROID_HOME : Path to your Android SDK installation.
38+
Default = os.environ.get("ANDROID_HOME", os.environ.get("ANDROID_SDK_ROOT")
39+
]]
40+
endfunction()
41+
42+
#[===========================[ Target Generation ]===========================]
43+
function( android_generate )
44+
target_compile_definitions(${TARGET_NAME}
45+
PUBLIC
46+
ANDROID_ENABLED
47+
UNIX_ENABLED
48+
)
49+
50+
common_compiler_flags()
51+
endfunction()

0 commit comments

Comments
 (0)