|
1 | 1 | 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 () |
13 | 2 |
|
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. |
15 | 20 |
|
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 |
19 | 22 |
|
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) |
21 | 25 |
|
| 26 | +
|
| 27 | +The CMake equivalent is below. |
| 28 | +]=======================================================================] |
| 29 | + |
| 30 | +include( cmake/godotcpp.cmake ) |
22 | 31 | godotcpp_options()
|
23 | 32 |
|
| 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 | + |
24 | 87 | godotcpp_generate()
|
| 88 | + |
| 89 | +# Test Example |
| 90 | +add_subdirectory( test ) |
0 commit comments