Skip to content

Commit 5513ce6

Browse files
authored
Merge pull request #57 from enetheru/cmake
2 parents 3eb2751 + 8cbb15b commit 5513ce6

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ indent_size = 4
1919
[*.{yml,yaml}]
2020
indent_style = space
2121
indent_size = 2
22+
23+
[{*.cmake,CMakeLists.txt}]
24+
indent_style = space
25+
ij_continuation_indent_size = 4
26+
ij_cmake_force_commands_case = 1
27+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ compile_commands.json
5656

5757
# Jetbrains
5858
.idea/
59+
60+
# Cmake
61+
cmake-build*
62+
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
)

godot-cpp

Submodule godot-cpp updated 58 files

0 commit comments

Comments
 (0)