mirror of
https://github.com/godotengine/godot-cpp-template.git
synced 2025-12-31 21:48:10 +03:00
CMake solution
Update module to track 4.4 branch with latest cherry picks.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -56,3 +56,7 @@ compile_commands.json
|
||||
|
||||
# Jetbrains
|
||||
.idea/
|
||||
|
||||
# Cmake
|
||||
cmake-build*
|
||||
CMakeUserPresets.json
|
||||
79
CMakeLists.txt
Normal file
79
CMakeLists.txt
Normal file
@@ -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 "$<TARGET_FILE:${LIBNAME}>" "${GODOT_PROJECT_BINARY_DIR}/$<TARGET_FILE_NAME:${LIBNAME}>"
|
||||
)
|
||||
Submodule godot-cpp updated: f3a1a2fd45...6388e26dd8
Reference in New Issue
Block a user