|
| 1 | +# Using the same minimum as the godot-cpp project |
| 2 | +cmake_minimum_required(VERSION 3.17) |
| 3 | + |
| 4 | +# Silence unused variable warning when specified from toolchain |
| 5 | +if(CMAKE_C_COMPILER) |
| 6 | +endif() |
| 7 | + |
| 8 | +set(LIBNAME "EXTENSION-NAME" CACHE STRING "The name of the library") |
| 9 | +set(GODOT_PROJECT_DIR "demo" CACHE STRING "The directory of a Godot project folder") |
| 10 | + |
| 11 | +# Make sure all the dependencies are satisfied |
| 12 | +find_package(Python3 3.4 REQUIRED) |
| 13 | +find_program(GIT git REQUIRED) |
| 14 | + |
| 15 | +# Ensure godot-cpp submodule has been updated |
| 16 | +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/godot-cpp/src") |
| 17 | + message(NOTICE "godot-cpp bindings source not found") |
| 18 | + message(NOTICE "initializing/updating the godot-cpp submodule...") |
| 19 | + |
| 20 | + # update the c++ bindings submodule to populate it with the necessary source for the library |
| 21 | + execute_process( |
| 22 | + COMMAND git submodule update --init godot-cpp |
| 23 | + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} |
| 24 | + COMMAND_ERROR_IS_FATAL ANY |
| 25 | + ) |
| 26 | +endif() |
| 27 | +add_subdirectory(godot-cpp SYSTEM) |
| 28 | + |
| 29 | +# Add godot-cpp's module path and include the exported functions. |
| 30 | +# This is made available for documentation generation |
| 31 | +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${godot-cpp_SOURCE_DIR}/cmake") |
| 32 | +include(GodotCPPModule) |
| 33 | + |
| 34 | +# The godot-cpp target has some of useful properties attached that can be retrieved like so. |
| 35 | +get_target_property(GODOTCPP_SUFFIX godot::cpp GODOTCPP_SUFFIX) |
| 36 | +get_target_property(GODOTCPP_PLATFORM godot::cpp GODOTCPP_PLATFORM) |
| 37 | + |
| 38 | +# Now we can specify our own project which will inherit any global cmake properties or variables that have been defined. |
| 39 | +project(godot-cpp-template |
| 40 | + VERSION 1.0 |
| 41 | + DESCRIPTION "This repository serves as a quickstart template for GDExtension development with Godot 4.0+." |
| 42 | + HOMEPAGE_URL "https://github.com/enetheru/godot-cpp-template/tree/main" |
| 43 | + LANGUAGES CXX |
| 44 | +) |
| 45 | + |
| 46 | +add_library(${LIBNAME} SHARED) |
| 47 | + |
| 48 | +target_sources(${LIBNAME} |
| 49 | + PRIVATE |
| 50 | + src/register_types.cpp |
| 51 | + src/register_types.h |
| 52 | +) |
| 53 | + |
| 54 | +# Fetch a list of the xml files to use for documentation and add to our target |
| 55 | +file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/doc_classes/*.xml") |
| 56 | + |
| 57 | +# conditionally add doc data to compile output |
| 58 | +if(DOC_XML) |
| 59 | + if(GODOTCPP_TARGET MATCHES "editor|template_debug") |
| 60 | + target_doc_sources(${LIBNAME} ${DOC_XML}) |
| 61 | + endif() |
| 62 | +endif() |
| 63 | + |
| 64 | +target_link_libraries(${LIBNAME} PRIVATE godot-cpp) |
| 65 | + |
| 66 | +set_target_properties(${LIBNAME} |
| 67 | + PROPERTIES |
| 68 | + # The generator expression here prevents msvc from adding a Debug or Release subdir. |
| 69 | + RUNTIME_OUTPUT_DIRECTORY "$<1:${PROJECT_SOURCE_DIR}/bin/${GODOTCPP_PLATFORM}>" |
| 70 | + |
| 71 | + PREFIX "" |
| 72 | + OUTPUT_NAME "${LIBNAME}${GODOTCPP_SUFFIX}" |
| 73 | +) |
| 74 | + |
| 75 | +set(GODOT_PROJECT_BINARY_DIR "${PROJECT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/${GODOTCPP_PLATFORM}") |
| 76 | + |
| 77 | +add_custom_command(TARGET ${LIBNAME} POST_BUILD |
| 78 | + COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${LIBNAME}>" "${GODOT_PROJECT_BINARY_DIR}/$<TARGET_FILE_NAME:${LIBNAME}>" |
| 79 | +) |
0 commit comments