|
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 () |
| 1 | +cmake_minimum_required(VERSION 3.17) |
| 2 | + |
| 3 | +#[=======================================================================[.rst: |
| 4 | +
|
| 5 | +CMake Version requirements |
| 6 | +-------------------------- |
| 7 | +
|
| 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 |
| 11 | +
|
| 12 | +Scons Compatibility |
| 13 | +------------------- |
| 14 | +
|
| 15 | +As we are attempting to maintain feature parity, and ease of maintenance, these |
| 16 | +CMake scripts are built to resemble the SCons build system. |
13 | 17 |
|
14 |
| -include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake ) |
| 18 | +The file structure and file content are made to match, if not in content then |
| 19 | +in spirit. The closer the two build systems look the easier they will be to |
| 20 | +maintain. |
15 | 21 |
|
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. |
| 22 | +Where the SCons additional scripts in the tools directory, The CMake scripts |
| 23 | +are in the cmake directory. |
19 | 24 |
|
20 |
| -# The typical target definitions are in ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake |
| 25 | +For example, the tools/godotcpp.py is sourced into SCons, and the 'options' |
| 26 | +function is run. |
21 | 27 |
|
| 28 | +.. highlight:: python |
| 29 | +
|
| 30 | + cpp_tool = Tool("godotcpp", toolpath=["tools"]) |
| 31 | + cpp_tool.options(opts, env) |
| 32 | +
|
| 33 | +
|
| 34 | +The CMake equivalent is below. |
| 35 | +]=======================================================================] |
| 36 | + |
| 37 | +include( cmake/godotcpp.cmake ) |
22 | 38 | godotcpp_options()
|
23 | 39 |
|
| 40 | +#[=======================================================================[.rst: |
| 41 | +
|
| 42 | +Configurations |
| 43 | +-------------- |
| 44 | +
|
| 45 | +There are two build main configurations, 'Debug' and 'Release', these are not |
| 46 | +related to godot's DEBUG_FEATURES flag. Build configurations change the default |
| 47 | +compiler and linker flags present when building the library, things like debug |
| 48 | +symbols, optimization. |
| 49 | +
|
| 50 | +The Scons build scripts don't have this concept, you can think of it like the |
| 51 | +SCons solution has a single default configuration. In both cases overriding the |
| 52 | +defaults is controlled by options on the command line, or in preset files. |
| 53 | +
|
| 54 | +Because of this added configuration and that it can be undefined, it becomes |
| 55 | +important to set a default, considering the SCons solution that does not enable |
| 56 | +debug symbols by default, it seemed appropriate to set the default to 'Release' |
| 57 | +if unspecified. This can always be overridden like below. |
| 58 | +
|
| 59 | +.. highlight:: shell |
| 60 | +
|
| 61 | + cmake <source> -DCMAKE_BUILD_TYPE:STRING=Debug |
| 62 | +
|
| 63 | +.. caution:: |
| 64 | +
|
| 65 | +A complication arises from `Multi-Config Generators`_ that cannot have |
| 66 | +their configuration set at configure time. This means that the configuration |
| 67 | +must be set on the build command. This is especially important for Visual |
| 68 | +Studio Generators which default to 'Debug' |
| 69 | +
|
| 70 | +.. highlight:: shell |
| 71 | +
|
| 72 | + cmake --build . --config Release |
| 73 | +
|
| 74 | +.. _Multi-Config Generators:https://cmake.org/cmake/help/latest/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html |
| 75 | +]=======================================================================] |
| 76 | +get_property( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG ) |
| 77 | +if( NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE ) |
| 78 | + if( GODOT_DEV_BUILD ) |
| 79 | + set( CMAKE_BUILD_TYPE Debug ) |
| 80 | + else () |
| 81 | + set( CMAKE_BUILD_TYPE Release ) |
| 82 | + endif () |
| 83 | +endif () |
| 84 | + |
| 85 | +#[[ Python is required for code generation ]] |
| 86 | +find_package(Python3 3.4 REQUIRED) # pathlib should be present |
| 87 | + |
| 88 | +# Define our project. |
| 89 | +project( godot-cpp |
| 90 | + VERSION 4.4 |
| 91 | + DESCRIPTION "C++ bindings for the Godot Engine's GDExtensions API." |
| 92 | + HOMEPAGE_URL "https://github.com/godotengine/godot-cpp" |
| 93 | + LANGUAGES CXX) |
| 94 | + |
24 | 95 | godotcpp_generate()
|
| 96 | + |
| 97 | +# Test Example |
| 98 | +add_subdirectory( test ) |
0 commit comments