-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
ports/godot-cpp/0001-Patches-so-that-godot-cpp-is-packagable.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
From 0d814979aadda7f4d49dfe2554868eaeed6a659e Mon Sep 17 00:00:00 2001 | ||
From: ytnuf <[email protected]> | ||
Date: Wed, 20 Mar 2024 20:53:56 +0000 | ||
Subject: [PATCH] Patches so that godot-cpp is packagable | ||
|
||
--- | ||
CMakeLists.txt | 21 +++++++++----- | ||
cmake/config.cmake | 3 ++ | ||
cmake/install.cmake | 67 +++++++++++++++++++++++++++++++++++++++++++++ | ||
3 files changed, 84 insertions(+), 7 deletions(-) | ||
create mode 100644 cmake/config.cmake | ||
create mode 100644 cmake/install.cmake | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index e715102..702af4c 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -30,6 +30,10 @@ | ||
# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_PLATFORM=android-23 -DCMAKE_BUILD_TYPE=Debug . | ||
# cmake --build . | ||
# | ||
+# Installation (after the library is built): | ||
+# cmake --install <insert_build_directory_here> --component godot-cpp-dev | ||
+# | ||
+# | ||
# Protip | ||
# Generate the buildfiles in a sub directory to not clutter the root directory with build files: | ||
# mkdir build && cd build && cmake -G "Unix Makefiles" .. && cmake --build . | ||
@@ -37,7 +41,7 @@ | ||
# Todo | ||
# Test build for Windows, Mac and mingw. | ||
|
||
-cmake_minimum_required(VERSION 3.12) | ||
+cmake_minimum_required(VERSION 3.13) | ||
project(godot-cpp LANGUAGES CXX) | ||
|
||
option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON) | ||
@@ -65,9 +69,8 @@ if(NOT DEFINED BITS) | ||
endif() | ||
|
||
# Input from user for GDExtension interface header and the API JSON file | ||
-set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "") | ||
+set(GODOT_GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE STRING "") | ||
set(GODOT_CUSTOM_API_FILE "" CACHE STRING "") | ||
- | ||
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json") | ||
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override. | ||
set(GODOT_GDEXTENSION_API_FILE "${GODOT_CUSTOM_API_FILE}") | ||
@@ -117,7 +120,6 @@ else() | ||
endif() | ||
|
||
# Generate source from the bindings file | ||
-find_package(Python3 3.4 REQUIRED) # pathlib should be present | ||
if(GENERATE_TEMPLATE_GET_NODE) | ||
set(GENERATE_BINDING_PARAMETERS "True") | ||
else() | ||
@@ -183,9 +185,10 @@ if (GODOT_CPP_SYSTEM_HEADERS) | ||
endif () | ||
|
||
target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC | ||
- include | ||
- ${CMAKE_CURRENT_BINARY_DIR}/gen/include | ||
- ${GODOT_GDEXTENSION_DIR} | ||
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/gen/include> | ||
+ $<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR}> | ||
+ $<INSTALL_INTERFACE:include> | ||
) | ||
|
||
# Add the compile flags | ||
@@ -213,4 +216,8 @@ set_target_properties(${PROJECT_NAME} | ||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" | ||
OUTPUT_NAME "${OUTPUT_NAME}" | ||
+ EXPORT_NAME "cpp" # This ensures that the exported target is godot::cpp | ||
) | ||
+ | ||
+ | ||
+include("cmake/install.cmake") | ||
diff --git a/cmake/config.cmake b/cmake/config.cmake | ||
new file mode 100644 | ||
index 0000000..73015ef | ||
--- /dev/null | ||
+++ b/cmake/config.cmake | ||
@@ -0,0 +1,3 @@ | ||
+include("${CMAKE_CURRENT_LIST_DIR}/godot-cpp-target.cmake") | ||
+ | ||
+add_library("unofficial::godot::cpp" ALIAS "godot::cpp") | ||
diff --git a/cmake/install.cmake b/cmake/install.cmake | ||
new file mode 100644 | ||
index 0000000..ebee704 | ||
--- /dev/null | ||
+++ b/cmake/install.cmake | ||
@@ -0,0 +1,67 @@ | ||
+ | ||
+include("CMakePackageConfigHelpers") | ||
+include("GNUInstallDirs") | ||
+ | ||
+# Install the library and headers to their respective install location | ||
+# CMAKE_INSTALL_ are used to allow the package manager to chose the install location | ||
+# Components are used so that if godot-cpp is a subproject, the user can chose not to install it | ||
+install(TARGETS "godot-cpp" | ||
+ EXPORT "godot-cpp-target" | ||
+ ARCHIVE | ||
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+install( | ||
+ DIRECTORY | ||
+ "${CMAKE_CURRENT_SOURCE_DIR}/include/" | ||
+ "${CMAKE_CURRENT_BINARY_DIR}/gen/include/" | ||
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+# Install the gdextension files | ||
+# The gdextension header is assumed to be the root include directory | ||
+# As the JSON file is neither a header nor lib file it goes to the datadir | ||
+install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h" | ||
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+install(FILES "${GODOT_GDEXTENSION_API_FILE}" | ||
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+ | ||
+# Install the export config file | ||
+# This allows this library to be easily consumed by cmake projects: | ||
+# find_package("godot-cpp" 4.2.0 CONFIG REQUIRED) | ||
+# target_link_libaries("my-project" PRIVATE "godot::cpp") | ||
+install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake" | ||
+ RENAME "godot-cpp-config.cmake" | ||
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+install(EXPORT "godot-cpp-target" | ||
+ NAMESPACE "godot::" | ||
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" | ||
+ COMPONENT "godot-cpp-dev" | ||
+) | ||
+ | ||
+if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") # string(JSON...) only available in cmake v3.19+ | ||
+ # Use the JSON api file to get the version | ||
+ file(READ "${GODOT_GDEXTENSION_API_FILE}" GODOT_GDEXTENSION_API_JSON) | ||
+ # GODOT_API_VERSION_MAJOR = GODOT_GDEXTENSION_API_JSON["header"]["version_major"] | ||
+ string(JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_major") | ||
+ string(JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_minor") | ||
+ string(JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_patch") | ||
+ set(GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR}.${GODOT_API_VERSION_MINOR}.${GODOT_API_VERSION_PATCH}") | ||
+ unset(GODOT_GDEXTENSION_API_JSON) | ||
+ | ||
+ # Install the config version file so that the gdextension version can be specified in find_package | ||
+ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/godot-cpp-config-version.cmake" | ||
+ VERSION "${GODOT_API_VERSION}" | ||
+ COMPATIBILITY SameMinorVersion | ||
+ ) | ||
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/godot-cpp-config-version.cmake" | ||
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp" | ||
+ COMPONENT "godot-cpp-dev" | ||
+ ) | ||
+endif() | ||
-- | ||
2.44.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
vcpkg_from_github( | ||
OUT_SOURCE_PATH SOURCE_PATH | ||
REPO "godotengine/godot-cpp" | ||
REF "godot-${VERSION}-stable" | ||
SHA512 "820e07ffb0545324f01598898bb342d7e143dcc8b83818824e7e1bc22937d3e8016b435f1ec085ebaae8b26e6f6dfb5500f120089316fc0f0c4153c340226941" | ||
HEAD_REF "master" | ||
PATCHES | ||
"0001-Patches-so-that-godot-cpp-is-packagable.patch" | ||
) | ||
|
||
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS | ||
INVERTED_FEATURES | ||
"exceptions" GODOT_DISABLE_EXCEPTIONS | ||
) | ||
|
||
vcpkg_find_acquire_program("PYTHON3") | ||
|
||
vcpkg_cmake_configure( | ||
SOURCE_PATH "${SOURCE_PATH}" | ||
OPTIONS | ||
"-DPython3_EXECUTABLE=${PYTHON3}" | ||
) | ||
|
||
vcpkg_cmake_install() | ||
vcpkg_cmake_config_fixup() | ||
vcpkg_copy_pdbs() | ||
|
||
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") | ||
|
||
file( | ||
INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" | ||
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" | ||
) | ||
|
||
file(REMOVE_RECURSE | ||
"${CURRENT_PACKAGES_DIR}/debug/include" | ||
"${CURRENT_PACKAGES_DIR}/debug/share" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
The godot-cpp provides CMake targets: | ||
|
||
find_package("godot-cpp" CONFIG REQUIRED) | ||
target_link_libraries("main" PRIVATE "unofficial::godot::cpp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "godot-cpp", | ||
"version": "4.2.1", | ||
"description": "C++ bindings for the Godot script API", | ||
"homepage": "https://github.com/godotengine/godot-cpp", | ||
"license": "MIT", | ||
"supports": "static", | ||
"dependencies": [ | ||
{ | ||
"name": "vcpkg-cmake", | ||
"host": true | ||
}, | ||
{ | ||
"name": "vcpkg-cmake-config", | ||
"host": true | ||
} | ||
], | ||
"default-features": [ | ||
"exceptions" | ||
], | ||
"features": { | ||
"exceptions": { | ||
"description": "Allow this library to be used with exceptions." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"versions": [ | ||
{ | ||
"git-tree": "8523172e819f7b86f32a8f3dd19c2968453134bf", | ||
"version": "4.2.1", | ||
"port-version": 0 | ||
} | ||
] | ||
} |