Skip to content
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

Add CMake file #57

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
130 changes: 130 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Using the same minimum as the godot-cpp project
cmake_minimum_required(VERSION 3.17)

#[[ Things to know

The default build type in CMake is 'Debug' which optimises for and generates debugging symbols.
To compile a roughly equivalent build as a default SCons build, further action is required:
* For Ninja, or Makefile; add '-DCMAKE_BUILD_TYPE=Release' to the configure command
* For Ninja-Multi, Visual Studio, or XCode; add '--config Release' to the build command
]]

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")

set(GODOT_TARGET_TYPE "template_debug" CACHE STRING "Which target type to build against")
set_property(CACHE GODOT_TARGET_TYPE PROPERTY STRINGS "template_debug;template_release;editor")

# Specify Options
option(USE_GIT_SUBMODULES "Use the git submodules to fetch godot-cpp" ON)
option(USE_FETCHCONTENT "Use CMake's FetchContent to fetch godot-cpp" OFF)

# Verify Options
if(USE_GIT_SUBMODULES AND USE_FETCHCONTENT)
message(FATAL_ERROR "USE_GIT_SUBMODULES and USE_FETCHCONTENT are mutually exclusive options")
endif()

#[[ CMake has a bunch of global properties which get copied to projects and targets at the moment of definition.
So make any changes to global options which effect all components of the build prior to making any call that
leads to a project or target definition.
Examples are: CMAKE_OSX_ARCHITECTURES, CMAKE_MSVC_RUNTIME_LIBRARY
]]

# Silence unused variable warning when specified from toolchain
if(CMAKE_C_COMPILER)
endif()

# Make sure all the dependencies are satisfied
find_package(Python3 3.4 REQUIRED)

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

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

if(USE_GIT_SUBMODULES)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_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_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
add_subdirectory(godot-cpp)
endif()

if(USE_FETCHCONTENT)
include(FetchContent)
# Godot-cpp
set(GODOTCPP_GIT_URL "http://github.com/godotengine/godot-cpp.git" CACHE STRING "The git url of godot-cpp to fetch")
set(GODOTCPP_GIT_BRANCH "master" CACHE STRING "The git branch of godot-cpp to fetch")

fetchcontent_declare(godot-cpp
GIT_REPOSITORY ${GODOTCPP_GIT_URL}
GIT_TAG ${GODOTCPP_GIT_BRANCH}
GIT_PROGRESS ON
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp"
)
fetchcontent_makeavailable(godot-cpp)
endif()

# 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};${CMAKE_CURRENT_SOURCE_DIR}/godot-cpp/cmake")
include(GodotCPPModule)

# The godot-cpp cmake project specifies three targets to link against.
# godot-cpp.template-debug
# godot-cpp.template_release
# godot-cpp.editor

# Helper variable to prevent typo's
set(GODOTCPP_TARGET godot-cpp.${GODOT_TARGET_TYPE})

# The targets have some of useful properties attached to them that can be retrieved like so.
get_target_property(GODOTCPP_SUFFIX ${GODOTCPP_TARGET} GODOTCPP_SUFFIX)
get_target_property(GODOTCPP_PLATFORM ${GODOTCPP_TARGET} 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 "${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml")

# conditionally add doc data to compile output
if(DOC_XML)
if(GODOT_TARGET_TYPE MATCHES "editor|template_debug")
target_doc_sources(${LIBNAME} ${DOC_XML})
endif()
endif()

target_link_libraries(${LIBNAME} PRIVATE ${GODOTCPP_TARGET})

set_target_properties(${LIBNAME}
PROPERTIES
# The generator expression here prevents msvc from adding a Debug or Release subdir.
RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_SOURCE_DIR}/${GODOT_PROJECT_DIR}/bin/${GODOTCPP_PLATFORM}>"

PREFIX lib
OUTPUT_NAME "${LIBNAME}${GODOTCPP_SUFFIX}"
)
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 56 files
+18 −45 .github/workflows/ci.yml
+4 −1 .gitignore
+54 −16 CMakeLists.txt
+216 −72 binding_generator.py
+169 −0 cmake/GodotCPPModule.cmake
+40 −0 cmake/android.cmake
+176 −93 cmake/common_compiler_flags.cmake
+40 −0 cmake/emsdkHack.cmake
+325 −192 cmake/godotcpp.cmake
+21 −0 cmake/ios.cmake
+21 −0 cmake/linux.cmake
+46 −0 cmake/macos.cmake
+42 −0 cmake/web.cmake
+103 −0 cmake/windows.cmake
+0 −57 doc/cmake.md
+377 −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
+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
+81 −143 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
+2 −46 tools/godotcpp.py
+8 −3 tools/windows.py