From 8cbb15bcc2d6aec9e5b79a8bc85ac2fe2da632cf Mon Sep 17 00:00:00 2001 From: Samuel Nicholas Date: Wed, 23 Oct 2024 16:42:31 +1030 Subject: [PATCH] CMake solution Update module to track 4.4 branch with latest cherry picks. --- .editorconfig | 6 ++++ .gitignore | 4 +++ CMakeLists.txt | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ godot-cpp | 2 +- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt diff --git a/.editorconfig b/.editorconfig index 23c3f9a5..d8a90053 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/.gitignore b/.gitignore index aa6a7449..8367781e 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/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..d735a6ab --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,79 @@ +# Using the same minimum as the godot-cpp project +cmake_minimum_required(VERSION 3.17) + +# Silence unused variable warning when specified from toolchain +if(CMAKE_C_COMPILER) +endif() + +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") + +# Make sure all the dependencies are satisfied +find_package(Python3 3.4 REQUIRED) +find_program(GIT git REQUIRED) + +# Ensure godot-cpp submodule has been updated +if(NOT EXISTS "${CMAKE_CURRENT_LIST_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 godot-cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) +endif() +add_subdirectory(godot-cpp SYSTEM) + +# 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};${godot-cpp_SOURCE_DIR}/cmake") +include(GodotCPPModule) + +# The godot-cpp target has some of useful properties attached that can be retrieved like so. +get_target_property(GODOTCPP_SUFFIX godot::cpp GODOTCPP_SUFFIX) +get_target_property(GODOTCPP_PLATFORM godot::cpp 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+." + HOMEPAGE_URL "https://github.com/enetheru/godot-cpp-template/tree/main" + LANGUAGES CXX +) + +add_library(${LIBNAME} SHARED) + +target_sources(${LIBNAME} + PRIVATE + src/register_types.cpp + src/register_types.h +) + +# 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 "${PROJECT_SOURCE_DIR}/doc_classes/*.xml") + +# conditionally add doc data to compile output +if(DOC_XML) + if(GODOTCPP_TARGET MATCHES "editor|template_debug") + target_doc_sources(${LIBNAME} ${DOC_XML}) + endif() +endif() + +target_link_libraries(${LIBNAME} PRIVATE godot-cpp) + +set_target_properties(${LIBNAME} + PROPERTIES + # The generator expression here prevents msvc from adding a Debug or Release subdir. + RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/bin/${GODOTCPP_PLATFORM}>" + + PREFIX "" + OUTPUT_NAME "${LIBNAME}${GODOTCPP_SUFFIX}" +) + +set(GODOT_PROJECT_BINARY_DIR "${PROJECT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/${GODOTCPP_PLATFORM}") + +add_custom_command(TARGET ${LIBNAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "$" "${GODOT_PROJECT_BINARY_DIR}/$" +) diff --git a/godot-cpp b/godot-cpp index f3a1a2fd..6388e26d 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit f3a1a2fd458dfaf4de08c906f22a2fe9e924b16f +Subproject commit 6388e26dd8a42071f65f764a3ef3d9523dda3d6e