Skip to content

Commit fb3895b

Browse files
committed
update module to track 4.4
1 parent 8dcbd90 commit fb3895b

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

CMakeLists.txt

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
# Using the same minimum as the godot-cpp project
22
cmake_minimum_required(VERSION 3.17)
33

4+
#[[ Things to know
5+
6+
The default build type in CMake is 'Debug' which optimises for and generates debugging symbols.
7+
To compile a roughly equivalent build as a default SCons build, further action is required:
8+
* For Ninja, or Makefile; add '-DCMAKE_BUILD_TYPE=Release' to the configure command
9+
* For Ninja-Multi, Visual Studio, or XCode; add '--config Release' to the build command
10+
]]
11+
12+
set(LIBNAME "EXTENSION-NAME" CACHE STRING "The name of the library")
13+
14+
set(GODOT_PROJECT_DIR "demo" CACHE STRING "The directory of a Godot project folder")
15+
16+
set(GODOT_TARGET_TYPE "template_debug" CACHE STRING "Which target type to build against")
17+
set_property(CACHE GODOT_TARGET_TYPE PROPERTY STRINGS "template_debug;template_release;editor")
18+
419
# Specify Options
5-
option(USE_GIT_SUBMODULES ON "")
6-
option(USE_FETCHCONTENT OFF "")
20+
option(USE_GIT_SUBMODULES "Use the git submodules to fetch godot-cpp" ON)
21+
option(USE_FETCHCONTENT "Use CMake's FetchContent to fetch godot-cpp" OFF)
722

823
# Verify Options
924
if(USE_GIT_SUBMODULES AND USE_FETCHCONTENT)
10-
message(FATAL_ERROR "Cannot specify both git submodules and fetchcontent.")
25+
message(FATAL_ERROR "USE_GIT_SUBMODULES and USE_FETCHCONTENT are mutually exclusive options")
1126
endif()
1227

1328
#[[ CMake has a bunch of global properties which get copied to projects and targets at the moment of definition.
@@ -20,25 +35,24 @@ Examples are: CMAKE_OSX_ARCHITECTURES, CMAKE_MSVC_RUNTIME_LIBRARY
2035
if(CMAKE_C_COMPILER)
2136
endif()
2237

23-
2438
# Make sure all the dependencies are satisfied
2539
find_package(Python3 3.4 REQUIRED)
2640

2741
# For godot-cpp we can use the git submodule method, or we can use CMake's fetchcontent module
2842
# In either case it is important to specify any GODOTCPP_ options prior to add_subdirectory
2943
# or fetchcontent_makeavailable
3044

31-
#set(GODOTCPP_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/build_profile.json")
45+
# I highly recommend using a build profile to cut down on the code generation and build time of godot-cpp
46+
# set(GODOTCPP_BUILD_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/build_profile.json")
3247

3348
if(USE_GIT_SUBMODULES)
3449
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/src")
3550
message(NOTICE "godot-cpp bindings source not found")
3651
message(NOTICE "initializing/updating the godot-cpp submodule...")
3752

38-
# update the c++ bindings submodule to populate it with
39-
# the necessary source for the library
53+
# update the c++ bindings submodule to populate it with the necessary source for the library
4054
execute_process(
41-
COMMAND git submodule update --init extern/godot-cpp
55+
COMMAND git submodule update --init godot-cpp
4256
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
4357
COMMAND_ERROR_IS_FATAL ANY
4458
)
@@ -61,32 +75,56 @@ if(USE_FETCHCONTENT)
6175
fetchcontent_makeavailable(godot-cpp)
6276
endif()
6377

64-
# Now we can specify our own project.
78+
# Add godot-cpp's module path and include the exported functions.
79+
# This is made available for documentation generation
80+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/cmake")
81+
include(GodotCPPModule)
82+
83+
# The godot-cpp cmake project specifies three targets to link against.
84+
# godot-cpp.template-debug
85+
# godot-cpp.template_release
86+
# godot-cpp.editor
87+
88+
# Helper variable to prevent typo's
89+
set(GODOTCPP_TARGET godot-cpp.${GODOT_TARGET_TYPE})
90+
91+
# The targets have some of useful properties attached to them that can be retrieved like so.
92+
get_target_property(GODOTCPP_SUFFIX ${GODOTCPP_TARGET} GODOTCPP_SUFFIX)
93+
get_target_property(GODOTCPP_PLATFORM ${GODOTCPP_TARGET} GODOTCPP_PLATFORM)
94+
95+
# Now we can specify our own project which will inherit any global cmake properties or variables that have been defined.
6596
project(godot-cpp-template
6697
VERSION 1.0
6798
DESCRIPTION "This repository serves as a quickstart template for GDExtension development with Godot 4.0+."
6899
HOMEPAGE_URL "https://github.com/enetheru/godot-cpp-template/tree/main"
69100
LANGUAGES CXX
70101
)
71102

72-
# The PROJECT_NAME stores the name of the last called project()
73-
add_library(${PROJECT_NAME} SHARED)
103+
add_library(${LIBNAME} SHARED)
74104

75-
target_sources(${PROJECT_NAME}
105+
target_sources(${LIBNAME}
76106
PRIVATE
77107
src/register_types.cpp
78108
src/register_types.h
79109
)
80110

81-
target_link_libraries(${PROJECT_NAME} PRIVATE godot-cpp.editor)
111+
# Fetch a list of the xml files to use for documentation and add to our target
112+
file(GLOB_RECURSE DOC_XML LIST_DIRECTORIES NO CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml")
82113

83-
# The godot targets have a couple of useful properties attached to them
84-
get_target_property(GODOTCPP_SUFFIX godot-cpp.editor GODOTCPP_SUFFIX)
114+
# conditionally add doc data to compile output
115+
if(DOC_XML)
116+
if(GODOT_TARGET_TYPE MATCHES "editor|template_debug")
117+
target_doc_sources(${LIBNAME} ${DOC_XML})
118+
endif()
119+
endif()
120+
121+
target_link_libraries(${LIBNAME} PRIVATE ${GODOTCPP_TARGET})
85122

86-
set_target_properties(${PROJECT_NAME}
123+
set_target_properties(${LIBNAME}
87124
PROPERTIES
88-
#The generator expression here prevents a subdir from being created.
89-
RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}>"
90-
# name format project.<platform>.<target>[.dev][.double].<arch>[.custom_suffix]
91-
OUTPUT_NAME "${PROJECT_NAME}${GODOTCPP_SUFFIX}"
125+
# The generator expression here prevents msvc from adding a Debug or Release subdir.
126+
RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/${GODOTCPP_PLATFORM}>"
127+
128+
PREFIX lib
129+
OUTPUT_NAME "${LIBNAME}${GODOTCPP_SUFFIX}"
92130
)

godot-cpp

Submodule godot-cpp updated 78 files

0 commit comments

Comments
 (0)