Skip to content

Commit

Permalink
Modernise Existing CMakeLists.txt
Browse files Browse the repository at this point in the history
- 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 cmake/sources.cmake to collect all the pre-existing source files, because globing is a source of bugs.
- 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
  • Loading branch information
enetheru committed Nov 4, 2024
1 parent 259c757 commit 723e82e
Show file tree
Hide file tree
Showing 14 changed files with 924 additions and 464 deletions.
73 changes: 35 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,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 @@ -246,15 +222,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 ../
cmake --build . --verbose -j $(nproc) -t godot-cpp-test
windows-msvc-cmake:
name: 🏁 Build (Windows, MSVC, CMake)
Expand All @@ -265,12 +238,36 @@ 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 ../
cmake --build . --verbose -t godot-cpp-test --config Release
# - name: Download latest Godot artifacts
# uses: dsnopek/action-download-artifact@1322f74e2dac9feed2ee76a32d9ae1ca3b4cf4e9
# with:
# repo: godotengine/godot
# branch: master
# event: push
# workflow: windows_builds.yml
# workflow_conclusion: success
# name: windows-x86_64-msvc
# search_artifacts: true
# check_artifacts: true
# ensure_latest: true
# path: godot-artifacts

# FIXME Error: no matching workflow run found with any artifacts?

# - name: Run tests
# run: |
# # Run the test project
# $godot="./godot-artifacts/godot.windows.editor.x86_64.exe"
# &$godot -e --path test\project\ --headless --quit *>$null
# $godot_tr = C:\build\godot\msvc.master\bin\godot.windows.template_release.x86_64.exe
# $godot_tr --path ..\test\project\ --headless --quit
# $output=&$godot --path test\project\ --headless --quit *>&1 | Out-String
# !$output.Contains("==== TESTS FINISHED ====")
# $output.Contains("******** FAILED ********")
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,6 @@ venv
# Clion Configuration
.idea/
cmake-build-*

# CMake related
CMakeUserPresets.json
56 changes: 41 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
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})

# As we are attempting to maintain feature parity, and ease of maintenance,
# these CMake scripts are built to resemble the structure of the SCons build system.
# The closer the two build systems look the easier they will be to maintain.

# include pulls in the code from godotcpp.cmake
# the equivalent in scons:
# cpp_tool = Tool("godotcpp", toolpath=["tools"])
include( cmake/godotcpp.cmake )

godotcpp_options()

# godot-cpp targets three main configurations, editor, template_release and template_debug.
# These are all built in "Release" mode unless GODOT_DEV_BUILD is enabled, then the build type is "Debug".
# WARNING: If using Visual Studio Generators the build type is 'Debug' unless specified on the command line like so:
# cmake --build . --config Release
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 ()

include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
# Get Python
find_package(Python3 3.4 REQUIRED) # pathlib should be present

# 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.
IF(APPLE)
set( CMAKE_OSX_SYSROOT $ENV{SDKROOT} )
find_library( COCOA_LIBRARY REQUIRED
NAMES Cocoa
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
ENDIF (APPLE)

# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake

godotcpp_options()
# 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 )
14 changes: 14 additions & 0 deletions cmake/android.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 723e82e

Please sign in to comment.