Skip to content

Add CMake file #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ compile_commands.json

# Jetbrains
.idea/

# Cmake
cmake-build*
CMakeUserPresets.json
79 changes: 79 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}>"
)
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 58 files
+18 −45 .github/workflows/ci.yml
+4 −1 .gitignore
+6 −0 .pre-commit-config.yaml
+66 −16 CMakeLists.txt
+224 −75 binding_generator.py
+176 −0 cmake/GodotCPPModule.cmake
+49 −0 cmake/android.cmake
+189 −91 cmake/common_compiler_flags.cmake
+40 −0 cmake/emsdkHack.cmake
+333 −183 cmake/godotcpp.cmake
+36 −0 cmake/ios.cmake
+24 −0 cmake/linux.cmake
+53 −0 cmake/macos.cmake
+39 −0 cmake/web.cmake
+116 −0 cmake/windows.cmake
+0 −57 doc/cmake.md
+353 −0 doc/cmake.rst
+55 −0 doc_source_generator.py
+106,876 −87,456 gdextension/extension_api.json
+133 −12 gdextension/gdextension_interface.h
+3 −12 include/godot_cpp/classes/wrapped.hpp
+19 −10 include/godot_cpp/core/class_db.hpp
+0 −4 include/godot_cpp/core/defs.hpp
+2 −2 include/godot_cpp/core/type_info.hpp
+5 −2 include/godot_cpp/godot.hpp
+1 −1 include/godot_cpp/variant/aabb.hpp
+1 −1 include/godot_cpp/variant/basis.hpp
+1 −1 include/godot_cpp/variant/color.hpp
+1 −1 include/godot_cpp/variant/plane.hpp
+1 −1 include/godot_cpp/variant/projection.hpp
+1 −1 include/godot_cpp/variant/quaternion.hpp
+1 −1 include/godot_cpp/variant/rect2.hpp
+1 −1 include/godot_cpp/variant/rect2i.hpp
+1 −1 include/godot_cpp/variant/transform2d.hpp
+1 −1 include/godot_cpp/variant/transform3d.hpp
+439 −0 include/godot_cpp/variant/typed_dictionary.hpp
+3 −0 include/godot_cpp/variant/variant.hpp
+509 −0 include/godot_cpp/variant/variant_internal.hpp
+1 −1 include/godot_cpp/variant/vector2.hpp
+1 −1 include/godot_cpp/variant/vector2i.hpp
+1 −1 include/godot_cpp/variant/vector3.hpp
+1 −1 include/godot_cpp/variant/vector3i.hpp
+1 −1 include/godot_cpp/variant/vector4.hpp
+1 −1 include/godot_cpp/variant/vector4i.hpp
+1 −0 misc/scripts/check_get_file_list.py
+4 −4 src/classes/wrapped.cpp
+9 −6 src/core/class_db.cpp
+10 −4 src/godot.cpp
+6 −0 src/variant/packed_arrays.cpp
+7 −6 src/variant/variant.cpp
+43 −0 src/variant/variant_internal.cpp
+55 −129 test/CMakeLists.txt
+18 −2 test/project/main.gd
+43 −0 test/src/example.cpp
+17 −0 test/src/example.h
+1 −0 test/src/register_types.cpp
+3 −46 tools/godotcpp.py
+8 −3 tools/windows.py