From eab8b0000185f06f17f19be712b9a46ad09b4cb9 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Wed, 23 Oct 2024 16:42:31 +1030 Subject: [PATCH 1/5] preliminary cmake file --- CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..481219d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.28) + +# The name of the project is used for the build target +project( godot-cpp-template + VERSION 1.0 + DESCRIPTION "" + LANGUAGES CXX) + +if( CMAKE_C_COMPILER ) + #Silence unused variable when specified from toolchain +endif () + +add_subdirectory( godot-cpp ) + +add_library( ${PROJECT_NAME} SHARED ) + +target_sources( ${PROJECT_NAME} + PRIVATE + src/register_types.cpp + src/register_types.h +) + +target_link_libraries( ${PROJECT_NAME} PRIVATE godot-cpp ) + +set( ARCH_NAME_AMD64 x86_64 ) + +set( PLATFORM_NAME "$>") +set( TARGET_NAME "$>") +set( DOUBLE "$<$:.double>") +set( ARCH_NAME ${ARCH_NAME_${CMAKE_SYSTEM_PROCESSOR}}) + +set_target_properties( ${PROJECT_NAME} + PROPERTIES + #The generator expression here prevents a subdir from being created. + RUNTIME_OUTPUT_DIRECTORY "$<$:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" + # godot..[.dev][.double].[.custom_suffix][.console].exe + OUTPUT_NAME "${PROJECT_NAME}.${PLATFORM_NAME}.${TARGET_NAME}${DOUBLE}.${ARCH_NAME}" +) From 8b11db91e3fb28724ec9caefb7b7e1fdb5c54a26 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Tue, 5 Nov 2024 15:32:16 +1030 Subject: [PATCH 2/5] Update gitignore for clion and cmake --- .gitignore | 4 ++++ godot-cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aa6a744..8367781 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,7 @@ compile_commands.json # Jetbrains .idea/ + +# Cmake +cmake-build* +CMakeUserPresets.json \ No newline at end of file diff --git a/godot-cpp b/godot-cpp index f3a1a2f..fbbf9ec 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit f3a1a2fd458dfaf4de08c906f22a2fe9e924b16f +Subproject commit fbbf9ec4efd8f1055d00edb8d926eef8ba4c2cce From acf80395163a2e29c5f89d8e9ef9ed8163ebcd2a Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Tue, 5 Nov 2024 17:08:40 +1030 Subject: [PATCH 3/5] Added the target alias to godot-cpp to reflect recent changes Also pull naming components from godot target properties --- CMakeLists.txt | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 481219d..8c6bbbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,19 +20,21 @@ target_sources( ${PROJECT_NAME} src/register_types.h ) -target_link_libraries( ${PROJECT_NAME} PRIVATE godot-cpp ) +target_link_libraries( ${PROJECT_NAME} PRIVATE godot-cpp::editor ) -set( ARCH_NAME_AMD64 x86_64 ) +get_target_property( GODOT_PLATFORM godot-cpp::editor GODOT_PLATFORM ) +get_target_property( GODOT_TARGET godot-cpp::editor GODOT_TARGET ) +get_target_property( GODOT_ARCH godot-cpp::editor GODOT_ARCH ) +#get_target_property( GODOT_DEV godot-cpp::editor GODOT_DEV ) +#get_target_property( GODOT_DOUBLE godot-cpp::editor GODOT_DOUBLE ) -set( PLATFORM_NAME "$>") -set( TARGET_NAME "$>") -set( DOUBLE "$<$:.double>") -set( ARCH_NAME ${ARCH_NAME_${CMAKE_SYSTEM_PROCESSOR}}) +#set( DEV ".${GODOT_DEV}" ) +#set( DOUBLE ".${GODOT_DOUBLE}" ) set_target_properties( ${PROJECT_NAME} PROPERTIES #The generator expression here prevents a subdir from being created. - RUNTIME_OUTPUT_DIRECTORY "$<$:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" - # godot..[.dev][.double].[.custom_suffix][.console].exe - OUTPUT_NAME "${PROJECT_NAME}.${PLATFORM_NAME}.${TARGET_NAME}${DOUBLE}.${ARCH_NAME}" + RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" + # name format project..[.dev][.double].[.custom_suffix] + OUTPUT_NAME "${PROJECT_NAME}.${GODOT_PLATFORM}.${GODOT_TARGET}${DEV}${DOUBLE}.${GODOT_ARCH}" ) From 8dcbd90fb0651d70d158bc724ab620143b062c48 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Tue, 4 Mar 2025 13:34:33 +1030 Subject: [PATCH 4/5] mid update --- .editorconfig | 6 +++ CMakeLists.txt | 110 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 29 deletions(-) diff --git a/.editorconfig b/.editorconfig index 23c3f9a..d8a9005 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,9 @@ indent_size = 4 [*.{yml,yaml}] indent_style = space indent_size = 2 + +[{*.cmake,CMakeLists.txt}] +indent_style = space +ij_continuation_indent_size = 4 +ij_cmake_force_commands_case = 1 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c6bbbd..28ff322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,92 @@ -cmake_minimum_required(VERSION 3.28) +# Using the same minimum as the godot-cpp project +cmake_minimum_required(VERSION 3.17) -# The name of the project is used for the build target -project( godot-cpp-template - VERSION 1.0 - DESCRIPTION "" - LANGUAGES CXX) +# Specify Options +option(USE_GIT_SUBMODULES ON "") +option(USE_FETCHCONTENT OFF "") -if( CMAKE_C_COMPILER ) - #Silence unused variable when specified from toolchain -endif () +# Verify Options +if(USE_GIT_SUBMODULES AND USE_FETCHCONTENT) + message(FATAL_ERROR "Cannot specify both git submodules and fetchcontent.") +endif() -add_subdirectory( godot-cpp ) +#[[ CMake has a bunch of global properties which get copied to projects and targets at the moment of definition. +So make any changes to global options which effect all components of the build prior to making any call that +leads to a project or target definition. +Examples are: CMAKE_OSX_ARCHITECTURES, CMAKE_MSVC_RUNTIME_LIBRARY +]] -add_library( ${PROJECT_NAME} SHARED ) +# Silence unused variable warning when specified from toolchain +if(CMAKE_C_COMPILER) +endif() -target_sources( ${PROJECT_NAME} - PRIVATE - src/register_types.cpp - src/register_types.h + +# Make sure all the dependencies are satisfied +find_package(Python3 3.4 REQUIRED) + +# For godot-cpp we can use the git submodule method, or we can use CMake's fetchcontent module +# In either case it is important to specify any GODOTCPP_ options prior to add_subdirectory +# or fetchcontent_makeavailable + +#set(GODOTCPP_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/build_profile.json") + +if(USE_GIT_SUBMODULES) + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/src") + message(NOTICE "godot-cpp bindings source not found") + message(NOTICE "initializing/updating the godot-cpp submodule...") + + # update the c++ bindings submodule to populate it with + # the necessary source for the library + execute_process( + COMMAND git submodule update --init extern/godot-cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) + endif() + add_subdirectory(godot-cpp) +endif() + +if(USE_FETCHCONTENT) + include(FetchContent) + # Godot-cpp + set(GODOTCPP_GIT_URL "http://github.com/godotengine/godot-cpp.git" CACHE STRING "The git url of godot-cpp to fetch") + set(GODOTCPP_GIT_BRANCH "master" CACHE STRING "The git branch of godot-cpp to fetch") + + fetchcontent_declare(godot-cpp + GIT_REPOSITORY ${GODOTCPP_GIT_URL} + GIT_TAG ${GODOTCPP_GIT_BRANCH} + GIT_PROGRESS ON + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp" + ) + fetchcontent_makeavailable(godot-cpp) +endif() + +# Now we can specify our own project. +project(godot-cpp-template + VERSION 1.0 + DESCRIPTION "This repository serves as a quickstart template for GDExtension development with Godot 4.0+." + HOMEPAGE_URL "https://github.com/enetheru/godot-cpp-template/tree/main" + LANGUAGES CXX ) -target_link_libraries( ${PROJECT_NAME} PRIVATE godot-cpp::editor ) +# The PROJECT_NAME stores the name of the last called project() +add_library(${PROJECT_NAME} SHARED) + +target_sources(${PROJECT_NAME} + PRIVATE + src/register_types.cpp + src/register_types.h +) -get_target_property( GODOT_PLATFORM godot-cpp::editor GODOT_PLATFORM ) -get_target_property( GODOT_TARGET godot-cpp::editor GODOT_TARGET ) -get_target_property( GODOT_ARCH godot-cpp::editor GODOT_ARCH ) -#get_target_property( GODOT_DEV godot-cpp::editor GODOT_DEV ) -#get_target_property( GODOT_DOUBLE godot-cpp::editor GODOT_DOUBLE ) +target_link_libraries(${PROJECT_NAME} PRIVATE godot-cpp.editor) -#set( DEV ".${GODOT_DEV}" ) -#set( DOUBLE ".${GODOT_DOUBLE}" ) +# The godot targets have a couple of useful properties attached to them +get_target_property(GODOTCPP_SUFFIX godot-cpp.editor GODOTCPP_SUFFIX) -set_target_properties( ${PROJECT_NAME} - PROPERTIES - #The generator expression here prevents a subdir from being created. - RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" - # name format project..[.dev][.double].[.custom_suffix] - OUTPUT_NAME "${PROJECT_NAME}.${GODOT_PLATFORM}.${GODOT_TARGET}${DEV}${DOUBLE}.${GODOT_ARCH}" +set_target_properties(${PROJECT_NAME} + PROPERTIES + #The generator expression here prevents a subdir from being created. + RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" + # name format project..[.dev][.double].[.custom_suffix] + OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}" ) From fb3895b2981a4e6b75110efc1faee46b7cc1ed73 Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Tue, 4 Mar 2025 13:36:47 +1030 Subject: [PATCH 5/5] update module to track 4.4 --- CMakeLists.txt | 78 +++++++++++++++++++++++++++++++++++++------------- godot-cpp | 2 +- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ff322..ff066c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,28 @@ # Using the same minimum as the godot-cpp project cmake_minimum_required(VERSION 3.17) +#[[ Things to know + +The default build type in CMake is 'Debug' which optimises for and generates debugging symbols. +To compile a roughly equivalent build as a default SCons build, further action is required: + * For Ninja, or Makefile; add '-DCMAKE_BUILD_TYPE=Release' to the configure command + * For Ninja-Multi, Visual Studio, or XCode; add '--config Release' to the build command +]] + +set(LIBNAME "EXTENSION-NAME" CACHE STRING "The name of the library") + +set(GODOT_PROJECT_DIR "demo" CACHE STRING "The directory of a Godot project folder") + +set(GODOT_TARGET_TYPE "template_debug" CACHE STRING "Which target type to build against") +set_property(CACHE GODOT_TARGET_TYPE PROPERTY STRINGS "template_debug;template_release;editor") + # Specify Options -option(USE_GIT_SUBMODULES ON "") -option(USE_FETCHCONTENT OFF "") +option(USE_GIT_SUBMODULES "Use the git submodules to fetch godot-cpp" ON) +option(USE_FETCHCONTENT "Use CMake's FetchContent to fetch godot-cpp" OFF) # Verify Options if(USE_GIT_SUBMODULES AND USE_FETCHCONTENT) - message(FATAL_ERROR "Cannot specify both git submodules and fetchcontent.") + message(FATAL_ERROR "USE_GIT_SUBMODULES and USE_FETCHCONTENT are mutually exclusive options") endif() #[[ CMake has a bunch of global properties which get copied to projects and targets at the moment of definition. @@ -20,7 +35,6 @@ Examples are: CMAKE_OSX_ARCHITECTURES, CMAKE_MSVC_RUNTIME_LIBRARY if(CMAKE_C_COMPILER) endif() - # Make sure all the dependencies are satisfied find_package(Python3 3.4 REQUIRED) @@ -28,17 +42,17 @@ find_package(Python3 3.4 REQUIRED) # In either case it is important to specify any GODOTCPP_ options prior to add_subdirectory # or fetchcontent_makeavailable -#set(GODOTCPP_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/build_profile.json") +# I highly recommend using a build profile to cut down on the code generation and build time of godot-cpp +# set(GODOTCPP_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/build_profile.json") if(USE_GIT_SUBMODULES) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/src") message(NOTICE "godot-cpp bindings source not found") message(NOTICE "initializing/updating the godot-cpp submodule...") - # update the c++ bindings submodule to populate it with - # the necessary source for the library + # update the c++ bindings submodule to populate it with the necessary source for the library execute_process( - COMMAND git submodule update --init extern/godot-cpp + COMMAND git submodule update --init godot-cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY ) @@ -61,7 +75,24 @@ if(USE_FETCHCONTENT) fetchcontent_makeavailable(godot-cpp) endif() -# Now we can specify our own project. +# Add godot-cpp's module path and include the exported functions. +# This is made available for documentation generation +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/cmake") +include(GodotCPPModule) + +# The godot-cpp cmake project specifies three targets to link against. +# godot-cpp.template-debug +# godot-cpp.template_release +# godot-cpp.editor + +# Helper variable to prevent typo's +set(GODOTCPP_TARGET godot-cpp.${GODOT_TARGET_TYPE}) + +# The targets have some of useful properties attached to them that can be retrieved like so. +get_target_property(GODOTCPP_SUFFIX ${GODOTCPP_TARGET} GODOTCPP_SUFFIX) +get_target_property(GODOTCPP_PLATFORM ${GODOTCPP_TARGET} GODOTCPP_PLATFORM) + +# Now we can specify our own project which will inherit any global cmake properties or variables that have been defined. project(godot-cpp-template VERSION 1.0 DESCRIPTION "This repository serves as a quickstart template for GDExtension development with Godot 4.0+." @@ -69,24 +100,31 @@ project(godot-cpp-template LANGUAGES CXX ) -# The PROJECT_NAME stores the name of the last called project() -add_library(${PROJECT_NAME} SHARED) +add_library(${LIBNAME} SHARED) -target_sources(${PROJECT_NAME} +target_sources(${LIBNAME} PRIVATE src/register_types.cpp src/register_types.h ) -target_link_libraries(${PROJECT_NAME} PRIVATE godot-cpp.editor) +# Fetch a list of the xml files to use for documentation and add to our target +file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml") -# The godot targets have a couple of useful properties attached to them -get_target_property(GODOTCPP_SUFFIX godot-cpp.editor GODOTCPP_SUFFIX) +# conditionally add doc data to compile output +if(DOC_XML) + if(GODOT_TARGET_TYPE MATCHES "editor|template_debug") + target_doc_sources(${LIBNAME} ${DOC_XML}) + endif() +endif() + +target_link_libraries(${LIBNAME} PRIVATE ${GODOTCPP_TARGET}) -set_target_properties(${PROJECT_NAME} +set_target_properties(${LIBNAME} PROPERTIES - #The generator expression here prevents a subdir from being created. - RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>" - # name format project..[.dev][.double].[.custom_suffix] - OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}" + # The generator expression here prevents msvc from adding a Debug or Release subdir. + RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/${GODOTCPP_PLATFORM}>" + + PREFIX lib + OUTPUT_NAME "${LIBNAME}${GODOTCPP_SUFFIX}" ) diff --git a/godot-cpp b/godot-cpp index fbbf9ec..714c9e2 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit fbbf9ec4efd8f1055d00edb8d926eef8ba4c2cce +Subproject commit 714c9e2c165db2dcb7e6ea57e62a04204d3cfbfa