Merge pull request #1733 from enetheru/single_target_test

CMake: Revert to single cmake target
This commit is contained in:
David Snopek
2025-03-13 11:42:15 -05:00
committed by GitHub
11 changed files with 239 additions and 269 deletions

View File

@@ -202,8 +202,8 @@ jobs:
run: | run: |
mkdir cmake-build mkdir cmake-build
cd cmake-build cd cmake-build
cmake ../ -DGODOTCPP_ENABLE_TESTING=YES cmake ../ -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_TARGET=template_release
cmake --build . --verbose -j $(nproc) -t godot-cpp.test.template_release --config Release cmake --build . --verbose -j $(nproc) --target godot-cpp-test --config Release
windows-msvc-cmake: windows-msvc-cmake:
name: 🏁 Build (Windows, MSVC, CMake) name: 🏁 Build (Windows, MSVC, CMake)
@@ -218,5 +218,5 @@ jobs:
run: | run: |
mkdir cmake-build mkdir cmake-build
cd cmake-build cd cmake-build
cmake ../ -DGODOTCPP_ENABLE_TESTING=YES cmake ../ -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_TARGET=template_release
cmake --build . --verbose -t godot-cpp.test.template_release --config Release cmake --build . --verbose --target godot-cpp-test --config Release

View File

@@ -43,7 +43,7 @@ endfunction()
#[===========================[ Target Generation ]===========================] #[===========================[ Target Generation ]===========================]
function(android_generate) function(android_generate)
target_compile_definitions(${TARGET_NAME} PUBLIC ANDROID_ENABLED UNIX_ENABLED) target_compile_definitions(godot-cpp PUBLIC ANDROID_ENABLED UNIX_ENABLED)
common_compiler_flags() common_compiler_flags()
endfunction() endfunction()

View File

@@ -62,7 +62,7 @@ function(common_compiler_flags)
# gersemi: off # gersemi: off
# These compiler options reflect what is in godot/SConstruct. # These compiler options reflect what is in godot/SConstruct.
target_compile_options( target_compile_options(
${TARGET_NAME} godot-cpp
PUBLIC PUBLIC
# Disable exception handling. Godot doesn't use exceptions anywhere, and this # Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time. # saves around 20% of binary size and very significant build time.
@@ -146,7 +146,7 @@ function(common_compiler_flags)
) )
target_compile_definitions( target_compile_definitions(
${TARGET_NAME} godot-cpp
PUBLIC PUBLIC
GDEXTENSION GDEXTENSION
@@ -165,7 +165,7 @@ function(common_compiler_flags)
) )
target_link_options( target_link_options(
${TARGET_NAME} godot-cpp
PUBLIC PUBLIC
$<${IS_MSVC}: $<${IS_MSVC}:
/WX # treat link warnings as errors. /WX # treat link warnings as errors.

View File

@@ -106,6 +106,13 @@ function(godotcpp_options)
#NOTE: arch is managed by using toolchain files. #NOTE: arch is managed by using toolchain files.
# To create a universal build for macos, set CMAKE_OSX_ARCHITECTURES # To create a universal build for macos, set CMAKE_OSX_ARCHITECTURES
set(GODOTCPP_TARGET
"template_debug"
CACHE STRING
"Which target to generate. valid values are: template_debug, template_release, and editor"
)
set_property(CACHE GODOTCPP_TARGET PROPERTY STRINGS "template_debug;template_release;editor")
# Input from user for GDExtension interface header and the API JSON file # Input from user for GDExtension interface header and the API JSON file
set(GODOTCPP_GDEXTENSION_DIR set(GODOTCPP_GDEXTENSION_DIR
"gdextension" "gdextension"
@@ -305,94 +312,79 @@ function(godotcpp_generate)
set(IS_DEV_BUILD "$<BOOL:${GODOTCPP_DEV_BUILD}>") set(IS_DEV_BUILD "$<BOOL:${GODOTCPP_DEV_BUILD}>")
### Define our godot-cpp library targets ### Define our godot-cpp library targets
foreach(TARGET_ALIAS template_debug template_release editor) # Generator Expressions that rely on the target
set(TARGET_NAME "godot-cpp.${TARGET_ALIAS}") set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${GODOTCPP_TARGET},template_release>>")
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>")
# Generator Expressions that rely on the target # Suffix
set(DEBUG_FEATURES "$<NOT:$<STREQUAL:${TARGET_ALIAS},template_release>>") string(
set(HOT_RELOAD "$<IF:${HOT_RELOAD-UNSET},${DEBUG_FEATURES},$<BOOL:${GODOTCPP_USE_HOT_RELOAD}>>") CONCAT
GODOTCPP_SUFFIX
"$<1:.${SYSTEM_NAME}>"
"$<1:.${GODOTCPP_TARGET}>"
"$<${IS_DEV_BUILD}:.dev>"
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
"$<1:.${ARCH_NAME}>"
# TODO IOS_SIMULATOR
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
)
# Suffix # the godot-cpp.* library targets
string( add_library(godot-cpp STATIC)
CONCAT
GODOTCPP_SUFFIX
"$<1:.${SYSTEM_NAME}>"
"$<1:.${TARGET_ALIAS}>"
"$<${IS_DEV_BUILD}:.dev>"
"$<$<STREQUAL:${GODOTCPP_PRECISION},double>:.double>"
"$<1:.${ARCH_NAME}>"
# TODO IOS_SIMULATOR
"$<$<NOT:${THREADS_ENABLED}>:.nothreads>"
)
# People are compiling godot by itself.
set(EXCLUDE EXCLUDE_FROM_ALL)
if(GODOTCPP_IS_TOP_LEVEL)
if(TARGET_ALIAS STREQUAL template_debug)
set(EXCLUDE "")
endif()
endif()
# the godot-cpp.* library targets
add_library(${TARGET_NAME} STATIC ${EXCLUDE})
add_library(godot-cpp::${TARGET_ALIAS} ALIAS ${TARGET_NAME})
file(GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp)
target_sources(${TARGET_NAME} PRIVATE ${GODOTCPP_SOURCES} ${GENERATED_FILES_LIST})
target_include_directories(
${TARGET_NAME}
${GODOTCPP_SYSTEM_HEADERS_ATTRIBUTE}
PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/gen/include ${GODOTCPP_GDEXTENSION_DIR}
)
# gersemi: off
set_target_properties(
${TARGET_NAME}
PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
COMPILE_WARNING_AS_ERROR ${GODOTCPP_WARNING_AS_ERROR}
POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
PREFIX "lib"
OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}"
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
# Things that are handy to know for dependent targets
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
GODOTCPP_TARGET "${TARGET_ALIAS}"
GODOTCPP_ARCH "${ARCH_NAME}"
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
)
# gersemi: on
if(CMAKE_SYSTEM_NAME STREQUAL Android)
android_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
ios_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
linux_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
macos_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
web_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
windows_generate()
endif()
endforeach()
# Added for backwards compatibility with prior cmake solution so that builds dont immediately break # Added for backwards compatibility with prior cmake solution so that builds dont immediately break
# from a missing target. # from a missing target.
add_library(godot::cpp ALIAS godot-cpp.template_debug) add_library(godot::cpp ALIAS godot-cpp)
file(GLOB_RECURSE GODOTCPP_SOURCES LIST_DIRECTORIES NO CONFIGURE_DEPENDS src/*.cpp)
target_sources(godot-cpp PRIVATE ${GODOTCPP_SOURCES} ${GENERATED_FILES_LIST})
target_include_directories(
godot-cpp
${GODOTCPP_SYSTEM_HEADERS_ATTRIBUTE}
PUBLIC include ${CMAKE_CURRENT_BINARY_DIR}/gen/include ${GODOTCPP_GDEXTENSION_DIR}
)
# gersemi: off
set_target_properties(
godot-cpp
PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
COMPILE_WARNING_AS_ERROR ${GODOTCPP_WARNING_AS_ERROR}
POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
PREFIX "lib"
OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}"
ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_BINARY_DIR}/bin>"
# Things that are handy to know for dependent targets
GODOTCPP_PLATFORM "${SYSTEM_NAME}"
GODOTCPP_TARGET "${GODOTCPP_TARGET}"
GODOTCPP_ARCH "${ARCH_NAME}"
GODOTCPP_PRECISION "${GODOTCPP_PRECISION}"
GODOTCPP_SUFFIX "${GODOTCPP_SUFFIX}"
# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
)
# gersemi: on
if(CMAKE_SYSTEM_NAME STREQUAL Android)
android_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
ios_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
linux_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
macos_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
web_generate()
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
windows_generate()
endif()
endfunction() endfunction()

View File

@@ -30,7 +30,7 @@ endfunction()
#[===========================[ Target Generation ]===========================] #[===========================[ Target Generation ]===========================]
function(ios_generate) function(ios_generate)
target_compile_definitions(${TARGET_NAME} PUBLIC IOS_ENABLED UNIX_ENABLED) target_compile_definitions(godot-cpp PUBLIC IOS_ENABLED UNIX_ENABLED)
common_compiler_flags() common_compiler_flags()
endfunction() endfunction()

View File

@@ -18,7 +18,7 @@ endfunction()
#[===========================[ Target Generation ]===========================] #[===========================[ Target Generation ]===========================]
function(linux_generate) function(linux_generate)
target_compile_definitions(${TARGET_NAME} PUBLIC LINUX_ENABLED UNIX_ENABLED) target_compile_definitions(godot-cpp PUBLIC LINUX_ENABLED UNIX_ENABLED)
common_compiler_flags() common_compiler_flags()
endfunction() endfunction()

View File

@@ -43,11 +43,11 @@ endfunction()
#[===========================[ Target Generation ]===========================] #[===========================[ Target Generation ]===========================]
function(macos_generate) function(macos_generate)
target_compile_definitions(${TARGET_NAME} PUBLIC MACOS_ENABLED UNIX_ENABLED) target_compile_definitions(godot-cpp PUBLIC MACOS_ENABLED UNIX_ENABLED)
target_link_options(${TARGET_NAME} PUBLIC -Wl,-undefined,dynamic_lookup) target_link_options(godot-cpp PUBLIC -Wl,-undefined,dynamic_lookup)
target_link_libraries(${TARGET_NAME} INTERFACE ${COCOA_LIBRARY}) target_link_libraries(godot-cpp INTERFACE ${COCOA_LIBRARY})
common_compiler_flags() common_compiler_flags()
endfunction() endfunction()

View File

@@ -16,10 +16,10 @@ endfunction()
#[===========================[ Target Generation ]===========================] #[===========================[ Target Generation ]===========================]
function(web_generate) function(web_generate)
target_compile_definitions(${TARGET_NAME} PUBLIC WEB_ENABLED UNIX_ENABLED) target_compile_definitions(godot-cpp PUBLIC WEB_ENABLED UNIX_ENABLED)
target_compile_options( target_compile_options(
${TARGET_NAME} godot-cpp
PUBLIC # PUBLIC #
-sSIDE_MODULE -sSIDE_MODULE
-sSUPPORT_LONGJMP=wasm -sSUPPORT_LONGJMP=wasm
@@ -27,7 +27,7 @@ function(web_generate)
) )
target_link_options( target_link_options(
${TARGET_NAME} godot-cpp
INTERFACE # INTERFACE #
-sWASM_BIGINT -sWASM_BIGINT
-sSUPPORT_LONGJMP=wasm -sSUPPORT_LONGJMP=wasm

View File

@@ -88,16 +88,16 @@ endfunction()
function(windows_generate) function(windows_generate)
set(STATIC_CPP "$<BOOL:${GODOTCPP_USE_STATIC_CPP}>") set(STATIC_CPP "$<BOOL:${GODOTCPP_USE_STATIC_CPP}>")
set_target_properties(${TARGET_NAME} PROPERTIES PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>") set_target_properties(godot-cpp PROPERTIES PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>")
target_compile_definitions( target_compile_definitions(
${TARGET_NAME} godot-cpp
PUBLIC WINDOWS_ENABLED $<${IS_MSVC}: TYPED_METHOD_BIND NOMINMAX > PUBLIC WINDOWS_ENABLED $<${IS_MSVC}: TYPED_METHOD_BIND NOMINMAX >
) )
# gersemi: off # gersemi: off
target_link_options( target_link_options(
${TARGET_NAME} godot-cpp
PUBLIC PUBLIC
$<${NOT_MSVC}: $<${NOT_MSVC}:
-Wl,--no-undefined -Wl,--no-undefined

View File

@@ -32,12 +32,28 @@ source code with debug symbols enabled, and compiling a Godot extension with
debug features enabled. The two concepts are not mutually inclusive. debug features enabled. The two concepts are not mutually inclusive.
- debug_features - debug_features
Enables a pre-processor definition to selectively compile code to help Enables a pre-processor definition to selectively compile code to help
users of a Godot extension with their own project. users of a Godot extension with their own project.
debug features are enabled in editor and template_debug builds, which can be specified during the configure phase like so
``cmake -S . -B cmake-build -DGODOTCPP_TARGET=<target choice>``
- Debug - Debug
Sets compiler flags so that debug symbols are generated to help godot Sets compiler flags so that debug symbols are generated to help godot
extension developers debug their extension. extension developers debug their extension.
``Debug`` is the default build type for CMake projects, to select another it depends on the generator used
For single configuration generators, add to the configure command:
``-DCMAKE_BUILD_TYPE=<type>``
For multi-config generators add to the build command:
``--config <type>``
where ``<type>`` is one of ``Debug``, ``Release``, ``RelWithDebInfo``, ``MinSizeRel``
SCons Deviations SCons Deviations
@@ -48,21 +64,23 @@ the notable differences.
- debug_symbols - debug_symbols
No longer has an explicit option, and is enabled via Debug-like CMake No longer has an explicit option, and is enabled via Debug-like CMake
build configurations; Debug, RelWithDebInfo. build configurations; ``Debug``, ``RelWithDebInfo``.
- dev_build - dev_build
Does not define NDEBUG when disabled, NDEBUG is set via Release-like Does not define ``NDEBUG`` when disabled, ``NDEBUG`` is set via Release-like
CMake build configurations; Release, MinSizeRel. CMake build configurations; ``Release``, ``MinSizeRel``.
- arch
CMake sets the architecture via the toolchain files, macos universal is controlled vua the ``CMAKE_OSX_ARCHITECTURES``
property which is copied to targets when they are defined.
- debug_crt
CMake controls linking to windows runtime libraries by copying the value of ``CMAKE_MSVC_RUNTIME_LIBRARIES`` to targets as they are defined.
godot-cpp will set this variable if it isn't already set. so include it before other dependencies to have the value propagate across the projects.
Testing Integration Testing Integration
------------------- -------------------
When consuming a third party CMake project into yours, an unfortunate side The testing target ``godot-cpp-test`` is guarded by ``GODOTCPP_ENABLE_TESTING`` which is off by default.
effect is that the targets of the consumed project appear in the list of
available targets, and are by default included in the ALL meta target
created by most build systems. For this reason, all the targets specified
in godot-cpp are marked with the ``EXCLUDE_FROM_ALL`` tag to prevent
unnecessary compilation. The testing targets ``godot-cpp.test.<target>``
are also guarded by ``GODOTCPP_ENABLE_TESTING`` which is off by default.
To configure and build the godot-cpp project to enable the integration To configure and build the godot-cpp project to enable the integration
testing targets the command will look something like: testing targets the command will look something like:
@@ -70,10 +88,8 @@ testing targets the command will look something like:
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir cmake-build cmake -S . -B cmake-build -DGODOTCPP_ENABLE_TESTING=YES
cd cmake-build cmake --build cmake-build --target godot-cpp-test
cmake .. -DGODOTCPP_ENABLE_TESTING=YES
cmake --build . --target godot-cpp.test.template_debug
Basic walkthrough Basic walkthrough
----------------- -----------------
@@ -87,30 +103,7 @@ Basic walkthrough
... ...
cd godot-cpp cd godot-cpp
.. topic:: Options
.. topic:: Out-of-tree build directory
Create a build directory for CMake to put caches and build artifacts in and
change directory to it. This is typically as a sub-directory of the project
root but can be outside the source tree. This is so that generated files do
not clutter up the source tree.
.. code-block::
mkdir cmake-build
cd cmake-build
.. topic:: Configure the build
CMake doesn't build the code, it generates the files that another tool uses
to build the code. To see the list of generators run ``cmake --help``. The
first phase of which is running through the configuration scripts.
Configure and generate Ninja build files.
.. code-block::
cmake .. -G "Ninja"
To list the available options CMake use the ``-L[AH]`` option. ``A`` is for To list the available options CMake use the ``-L[AH]`` option. ``A`` is for
advanced, and ``H`` is for help strings. advanced, and ``H`` is for help strings.
@@ -119,7 +112,7 @@ Basic walkthrough
cmake .. -LH cmake .. -LH
Options are specified on the command line when configuring Options are specified on the command line when configuring eg.
.. code-block:: .. code-block::
@@ -145,36 +138,38 @@ Basic walkthrough
// Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir ) // Path to a custom directory containing GDExtension interface header and API JSON file ( /path/to/gdextension_dir )
GODOTCPP_GDEXTENSION_DIR:PATH=gdextension GODOTCPP_GDEXTENSION_DIR:PATH=gdextension
// Generate a template version of the Node class's get_node. (ON|OFF)
GODOTCPP_GENERATE_TEMPLATE_GET_NODE:BOOL=ON
// Set the floating-point precision level (single|double) // Set the floating-point precision level (single|double)
GODOTCPP_PRECISION:STRING=single GODOTCPP_PRECISION:STRING=single
// Symbols visibility on GNU platforms. Use 'auto' to apply the default value. (auto|visible|hidden)
GODOTCPP_SYMBOL_VISIBILITY:STRING=hidden
// Expose headers as SYSTEM.
GODOTCPP_SYSTEM_HEADERS:BOOL=ON
// Enable the extra accounting required to support hot reload. (ON|OFF) // Enable the extra accounting required to support hot reload. (ON|OFF)
GODOTCPP_USE_HOT_RELOAD:BOOL= GODOTCPP_USE_HOT_RELOAD:BOOL=
// Treat warnings as errors .. topic:: Configure the build
GODOTCPP_WARNING_AS_ERROR:BOOL=OFF
.. topic:: Compiling
A target and a configuration is required, as the default ``all`` target does
not include anything and when using multi-config generators like ``Ninja
Multi-Config``, ``Visual Studio *`` or ``Xcode`` the build configuration
needs to be specified at build time. Build in Release mode unless you need
debug symbols.
.. code-block:: .. code-block::
cmake --build . -t template_debug --config Debug cmake -S . -B cmake-build -G Ninja
``-S .`` Specifies the source directory
``-B cmake-build`` Specifies the build directory
``-G Ninja`` Specifies the Generator
The source directory in this example is the source code for godot-cpp.
The build directory is so that generated files do not clutter up the source tree.
CMake doesn't build the code, it generates the files that another tool uses
to build the code, in this case Ninja.
To see the list of generators run ``cmake --help``.
.. topic:: Compiling
Tell cmake to invoke the build system it generated in the specified directory.
The default target is template_debug and the default build configuration is Debug.
.. code-block::
cmake --build cmake-build
Examples Examples
-------- --------
@@ -185,25 +180,23 @@ So long as CMake is installed from the `CMake Downloads`_ page and in the PATH,
and Microsoft Visual Studio is installed with c++ support, CMake will detect and Microsoft Visual Studio is installed with c++ support, CMake will detect
the MSVC compiler. the MSVC compiler.
Remembering that Visual Studio is a Multi-Config Generator so the build type Note that Visual Studio is a Multi-Config Generator so the build configuration
needs to be specified at build time. needs to be specified at build time ie ``--config Release``
.. _CMake downloads: https://cmake.org/download/ .. _CMake downloads: https://cmake.org/download/
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-msvc cmake -S . -B cmake-build -DGODOTCPP_ENABLE_TESTING=YES
cd build-msvc cmake --build cmake-build -t godot-cpp-test --config Release
cmake .. -DGODOTCPP_ENABLE_TESTING=YES
cmake --build . -t godot-cpp.test.template_debug --config Debug
MSys2/clang64, "Ninja" - Debug MSys2/clang64, "Ninja" - Debug
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Assumes the ming-w64-clang-x86_64-toolchain is installed Assumes the ming-w64-clang-x86_64-toolchain is installed
Remembering that Ninja is a Single-Config Generator so the build type Note that Ninja is a Single-Config Generator so the build type
needs to be specified at Configure time. needs to be specified at Configure time.
Using the msys2/clang64 shell Using the msys2/clang64 shell
@@ -211,10 +204,8 @@ Using the msys2/clang64 shell
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-clang cmake -S . -B cmake-build -G"Ninja" -DGODOTCPP_ENABLE_TESTING=YES -DCMAKE_BUILD_TYPE=Release
cd build-clang cmake --build cmake-build -t godot-cpp-test
cmake .. -G"Ninja" -DGODOTCPP_ENABLE_TESTING=YES -DCMAKE_BUILD_TYPE=Debug
cmake --build . -t godot-cpp.test.template_debug
MSys2/clang64, "Ninja Multi-Config" - dev_build, Debug Symbols MSys2/clang64, "Ninja Multi-Config" - dev_build, Debug Symbols
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -228,10 +219,8 @@ Using the msys2/clang64 shell
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-clang cmake -S . -B cmake-build -G"Ninja Multi-Config" -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_DEV_BUILD:BOOL=ON
cd build-clang cmake --build cmake-build -t godot-cpp-test --config Debug
cmake .. -G"Ninja Multi-Config" -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_DEV_BUILD:BOOL=ON
cmake --build . -t godot-cpp.test.template_debug --config Debug
Emscripten for web platform Emscripten for web platform
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -244,15 +233,14 @@ I've been using ``C:\emsdk\emsdk.ps1 activate latest`` to enable the
environment from powershell in the current shell. environment from powershell in the current shell.
The ``emcmake.bat`` utility adds the emscripten toolchain to the CMake command The ``emcmake.bat`` utility adds the emscripten toolchain to the CMake command
It can also be added manually, the location is listed inside the emcmake.bat file
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
C:\emsdk\emsdk.ps1 activate latest C:\emsdk\emsdk.ps1 activate latest
mkdir build-wasm32 emcmake.bat cmake -S . -B cmake-build-web -DCMAKE_BUILD_TYPE=Release
cd build-wasm32 cmake --build cmake-build-web
emcmake.bat cmake ../
cmake --build . --target template_release
Android Cross Compile from Windows Android Cross Compile from Windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -279,24 +267,20 @@ is for android sdk platform, (tested with ``android-29``)
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-android cmake -S . -B cmake-build --toolchain my_toolchain.cmake
cd build-android cmake --build cmake-build -t template_release
cmake .. --toolchain my_toolchain.cmake
cmake --build . -t template_release
Doing the equivalent on just using the command line Doing the equivalent on just using the command line
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-android cmake -S . -B cmake-build \
cd build-android
cmake .. \
-DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=<platform> \ -DCMAKE_SYSTEM_VERSION=<platform> \
-DCMAKE_ANDROID_ARCH_ABI=<arch> \ -DCMAKE_ANDROID_ARCH_ABI=<arch> \
-DCMAKE_ANDROID_NDK=/path/to/android-ndk -DCMAKE_ANDROID_NDK=/path/to/android-ndk
cmake --build . -t template_release cmake --build cmake-build
.. topic:: Using the toolchain file from the Android SDK .. topic:: Using the toolchain file from the Android SDK
@@ -305,22 +289,18 @@ is for android sdk platform, (tested with ``android-29``)
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-android cmake -S . -B cmake-build --toolchain $ANDROID_HOME/ndk/<version>/build/cmake/android.toolchain.cmake
cd build-android cmake --build cmake-build
cmake .. --toolchain $ANDROID_HOME/ndk/<version>/build/cmake/android.toolchain.cmake
cmake --build . -t template_release
Specify Android platform and ABI Specify Android platform and ABI
.. code-block:: .. code-block::
# Assuming our current directory is the godot-cpp source root # Assuming our current directory is the godot-cpp source root
mkdir build-android cmake -S . -B cmake-build --toolchain $ANDROID_HOME/ndk/<version>/build/cmake/android.toolchain.cmake \
cd build-android
cmake .. --toolchain $ANDROID_HOME/ndk/<version>/build/cmake/android.toolchain.cmake \
-DANDROID_PLATFORM:STRING=android-29 \ -DANDROID_PLATFORM:STRING=android-29 \
-DANDROID_ABI:STRING=armeabi-v7a -DANDROID_ABI:STRING=armeabi-v7a
cmake --build . -t template_release cmake --build cmake-build
Toolchains Toolchains
@@ -351,23 +331,23 @@ Windows Host
* `LLVM <https://llvm.org/>`_ * `LLVM <https://llvm.org/>`_
* `LLVM-MinGW <https://github.com/mstorsjo/llvm-mingw/releases>`_ * `LLVM-MinGW <https://github.com/mstorsjo/llvm-mingw/releases>`_
* aarch64-w64-mingw32 * aarch64-w64-mingw32
* armv7-w64-mingw32 * armv7-w64-mingw32
* i686-w64-mingw32 * i686-w64-mingw32
* x86_64-w64-mingw32 * x86_64-w64-mingw32
* `AndroidSDK <https://developer.android.com/studio/#command-tools>`_ * `AndroidSDK <https://developer.android.com/studio/#command-tools>`_
* `Emscripten <https://emscripten.org/>`_ * `Emscripten <https://emscripten.org/>`_
* `MinGW-W64-builds <https://github.com/niXman/mingw-builds-binaries/releases>`_ * `MinGW-W64-builds <https://github.com/niXman/mingw-builds-binaries/releases>`_
* `Jetbrains-CLion <https://www.jetbrains.com/clion/>`_ * `Jetbrains-CLion <https://www.jetbrains.com/clion/>`_
Jetbrains builtin compiler is just the MingW64 above. Jetbrains builtin compiler is just the MingW64 above.
* `MSYS2 <https://www.msys2.org/>`_ * `MSYS2 <https://www.msys2.org/>`_
Necessary reading about MSYS2 `environments <https://www.msys2.org/docs/environments/>`_ Necessary reading about MSYS2 `environments <https://www.msys2.org/docs/environments/>`_
* ucrt64 * ucrt64
* clang64 * clang64
* mingw32 * mingw32
* mingw64 * mingw64
* clangarm64 * clangarm64

View File

@@ -10,68 +10,66 @@ message(STATUS "Testing Integration targets are enabled.")
# Generate Doc Data # Generate Doc Data
file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml") file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml")
foreach(TARGET_ALIAS template_debug template_release editor) set(DOC_SOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_source.cpp")
set(TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}")
add_library(${TARGET_NAME} SHARED EXCLUDE_FROM_ALL) generate_doc_source( "${DOC_SOURCE_FILE}" ${DOC_XML} )
target_sources( set(TARGET_NAME "godot-cpp-test")
${TARGET_NAME}
PRIVATE src/example.cpp src/example.h src/register_types.cpp src/register_types.h src/tests.h
)
# conditionally add doc data to compile output add_library(${TARGET_NAME} SHARED EXCLUDE_FROM_ALL)
if(TARGET_ALIAS MATCHES "editor|template_debug")
target_doc_sources( ${TARGET_NAME} ${DOC_XML} )
endif()
set(OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/") target_sources(
${TARGET_NAME}
PRIVATE src/example.cpp src/example.h src/register_types.cpp src/register_types.h src/tests.h
)
# Link to godot-cpp target # conditionally add doc data to compile output
set(LINK_TARGET "godot-cpp::${TARGET_ALIAS}") if(GODOTCPP_TARGET MATCHES "editor|template_debug")
target_link_libraries(${TARGET_NAME} PRIVATE ${LINK_TARGET}) target_sources(${TARGET_NAME} PRIVATE "${DOC_SOURCE_FILE}")
endif()
### Get useful properties from godot-cpp target set(OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/bin/")
get_target_property(GODOTCPP_SUFFIX ${LINK_TARGET} GODOTCPP_SUFFIX)
get_target_property(OSX_ARCH ${LINK_TARGET} OSX_ARCHITECTURES)
# gersemi: off # Link to godot-cpp target
target_link_libraries(${TARGET_NAME} PRIVATE godot-cpp)
### Get useful properties from godot-cpp target
get_target_property(GODOTCPP_SUFFIX godot-cpp GODOTCPP_SUFFIX)
# gersemi: off
set_target_properties(
${TARGET_NAME}
PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
# Try to ensure only static libraries are selected to be linked to.
LINK_SEARCH_START_STATIC ON
LINK_SEARCH_END_STATIC ON
# NOTE: Wrapping the output variables inside a generator expression
# prevents msvc generator from adding addition Config Directories
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
PDB_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>" #MSVC Only, ignored on other platforms
PREFIX "lib"
OUTPUT_NAME "gdexample${GODOTCPP_SUFFIX}"
# TODO rename the file for both CMake and SCons
# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
)
# gersemi: on
# CMAKE_SYSTEM_NAME refers to the target system
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set_target_properties( set_target_properties(
${TARGET_NAME} ${TARGET_NAME}
PROPERTIES PROPERTIES SUFFIX "" OUTPUT_DIR "${OUTPUT_DIR}/libgdexample.macos.${GODOTCPP_TARGET}.framework"
CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET ${GODOTCPP_SYMBOL_VISIBILITY}
POSITION_INDEPENDENT_CODE ON
BUILD_RPATH_USE_ORIGIN ON
# Try to ensure only static libraries are selected to be linked to.
LINK_SEARCH_START_STATIC ON
LINK_SEARCH_END_STATIC ON
# NOTE: Wrapping the output variables inside a generator expression
# prevents msvc generator from adding addition Config Directories
LIBRARY_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
RUNTIME_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>"
PDB_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>" #MSVC Only, ignored on other platforms
PREFIX "lib"
OUTPUT_NAME "gdexample${GODOTCPP_SUFFIX}"
# Some IDE's respect this property to logically group targets
FOLDER "godot-cpp"
) )
# gersemi: on endif()
# CMAKE_SYSTEM_NAME refers to the target system
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set_target_properties(
${TARGET_NAME}
PROPERTIES
SUFFIX ""
OUTPUT_DIR "${OUTPUT_DIR}/libgdexample.macos.${TARGET_ALIAS}.framework"
OSX_ARCHITECTURES "${OSX_ARCH}"
)
endif()
endforeach()