Skip to content

Commit

Permalink
Merge pull request #1598 from enetheru/modernise
Browse files Browse the repository at this point in the history
Modernise existing cmake options
  • Loading branch information
dsnopek authored Nov 22, 2024
2 parents c20a84e + 8534e21 commit a42b363
Show file tree
Hide file tree
Showing 15 changed files with 1,153 additions and 496 deletions.
46 changes: 8 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,6 @@ jobs:
path: ${{ matrix.artifact-path }}
if-no-files-found: error

linux-cmake:
name: 🐧 Build (Linux, GCC, CMake)
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config cmake
- name: Build godot-cpp
run: |
cmake -DCMAKE_BUILD_TYPE=Release .
make -j $(nproc) VERBOSE=1
- name: Build test GDExtension library
run: |
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." .
make -j $(nproc) VERBOSE=1
linux-cmake-ninja:
name: 🐧 Build (Linux, GCC, CMake Ninja)
runs-on: ubuntu-22.04
Expand All @@ -245,15 +221,12 @@ jobs:
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config cmake ninja-build
- name: Build godot-cpp
run: |
cmake -DCMAKE_BUILD_TYPE=Release -GNinja .
cmake --build . -j $(nproc) --verbose
- name: Build test GDExtension library
run: |
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -GNinja .
cmake --build . -j $(nproc) --verbose
mkdir cmake-build
cd cmake-build
cmake ../ -DTEST_TARGET=template_release
cmake --build . --verbose -j $(nproc) -t godot-cpp-test --config Release
windows-msvc-cmake:
name: 🏁 Build (Windows, MSVC, CMake)
Expand All @@ -264,12 +237,9 @@ jobs:
with:
submodules: recursive

- name: Build godot-cpp
run: |
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
cmake --build . --verbose --config Release
- name: Build test GDExtension library
run: |
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
cmake --build . --verbose --config Release
mkdir cmake-build
cd cmake-build
cmake ../ -DTEST_TARGET=template_release
cmake --build . --verbose -t godot-cpp-test --config Release
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,7 @@ venv

# Clion Configuration
.idea/
cmake-build-*
cmake-build*/

# CMake related
CMakeUserPresets.json
108 changes: 91 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,98 @@
cmake_minimum_required(VERSION 3.13)
project(godot-cpp LANGUAGES CXX)

# Configure CMake
# https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965
# https://stackoverflow.com/questions/74426638/how-to-remove-rtc1-from-specific-target-or-file-in-cmake
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif ()
endif ()
cmake_minimum_required(VERSION 3.17)

#[=======================================================================[.rst:
CMake Version requirements
--------------------------
To enable use of the emscripten emsdk hack for pseudo shared library support
without polluting options for consumers we need to use the
CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE which was introduced in version 3.17
Scons Compatibility
-------------------
As we are attempting to maintain feature parity, and ease of maintenance, these
CMake scripts are built to resemble the SCons build system.
include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
The file structure and file content are made to match, if not in content then
in spirit. The closer the two build systems look the easier they will be to
maintain.
# I know this doesn't look like a typical CMakeLists.txt, but as we are
# attempting mostly feature parity with SCons, and easy maintenance, the closer
# the two build systems look the easier they will be to keep in lockstep.
Where the SCons additional scripts in the tools directory, The CMake scripts
are in the cmake directory.
# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake
For example, the tools/godotcpp.py is sourced into SCons, and the 'options'
function is run.
.. highlight:: python
cpp_tool = Tool("godotcpp", toolpath=["tools"])
cpp_tool.options(opts, env)
The CMake equivalent is below.
]=======================================================================]

include( cmake/godotcpp.cmake )
godotcpp_options()

#[=======================================================================[.rst:
Configurations
--------------
There are two build main configurations, 'Debug' and 'Release', these are not
related to godot's DEBUG_FEATURES flag. Build configurations change the default
compiler and linker flags present when building the library, things like debug
symbols, optimization.
The Scons build scripts don't have this concept, you can think of it like the
SCons solution has a single default configuration. In both cases overriding the
defaults is controlled by options on the command line, or in preset files.
Because of this added configuration and that it can be undefined, it becomes
important to set a default, considering the SCons solution that does not enable
debug symbols by default, it seemed appropriate to set the default to 'Release'
if unspecified. This can always be overridden like below.
.. highlight:: shell
cmake <source> -DCMAKE_BUILD_TYPE:STRING=Debug
.. caution::
A complication arises from `Multi-Config Generators`_ that cannot have
their configuration set at configure time. This means that the configuration
must be set on the build command. This is especially important for Visual
Studio Generators which default to 'Debug'
.. highlight:: shell
cmake --build . --config Release
.. _Multi-Config Generators:https://cmake.org/cmake/help/latest/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html
]=======================================================================]
get_property( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
if( NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE )
if( GODOT_DEV_BUILD )
set( CMAKE_BUILD_TYPE Debug )
else ()
set( CMAKE_BUILD_TYPE Release )
endif ()
endif ()

#[[ Python is required for code generation ]]
find_package(Python3 3.4 REQUIRED) # pathlib should be present

# Define our project.
project( godot-cpp
VERSION 4.4
DESCRIPTION "C++ bindings for the Godot Engine's GDExtensions API."
HOMEPAGE_URL "https://github.com/godotengine/godot-cpp"
LANGUAGES CXX)

godotcpp_generate()

# Test Example
add_subdirectory( test )
41 changes: 41 additions & 0 deletions cmake/android.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#[=======================================================================[.rst:
Android
-------
This file contains functions for options and configuration for targeting the
Android platform
Configuration of the Android toolchain is done using toolchain files,
CMakePresets, or variables on the command line.
The `Android SDK`_ provides toolchain files to help with configuration.
CMake has its own `built-in support`_ for cross compiling to the
Android platforms.
.. warning::
Android does not support or test the CMake built-in workflow, recommend
using their toolchain file.
.. _Android SDK:https://developer.android.com/ndk/guides/cmake
.. _built-in support:https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android
There is further information and examples in the doc/cmake.rst file.
]=======================================================================]
function( android_options )
# Android Options
endfunction()

function( android_generate TARGET_NAME )

target_compile_definitions(${TARGET_NAME}
PUBLIC
ANDROID_ENABLED
UNIX_ENABLED
)

common_compiler_flags( ${TARGET_NAME} )
endfunction()
Loading

0 comments on commit a42b363

Please sign in to comment.