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

[godot-cpp] Create a new port #37931

Merged
merged 1 commit into from
Jun 8, 2024
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
126 changes: 126 additions & 0 deletions ports/godot-cpp/packagable.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e715102..b000066 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,7 +37,7 @@
# Todo
# Test build for Windows, Mac and mingw.

-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 3.19)
project(godot-cpp LANGUAGES CXX)

option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON)
@@ -65,9 +65,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}")
@@ -85,9 +84,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(GODOT_COMPILE_FLAGS "/utf-8") # /GF /MP

if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
+ set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /Od") # /Od /RTC1 /Zi
else()
- set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
+ set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /O2") # /Oy /GL /Gy
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif(CMAKE_BUILD_TYPE MATCHES Debug)
@@ -117,7 +116,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 +181,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 +212,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"
)
+
+
+include("cmake/install.cmake")
diff --git a/cmake/config.cmake b/cmake/config.cmake
new file mode 100644
index 0000000..bcddb3c
--- /dev/null
+++ b/cmake/config.cmake
@@ -0,0 +1 @@
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-godot-cpp-target.cmake")
diff --git a/cmake/install.cmake b/cmake/install.cmake
new file mode 100644
index 0000000..f48ab5c
--- /dev/null
+++ b/cmake/install.cmake
@@ -0,0 +1,46 @@
+
+include("CMakePackageConfigHelpers")
+include("GNUInstallDirs")
+
+install(TARGETS "godot-cpp"
+ EXPORT "unofficial-godot-cpp-target"
+ ARCHIVE
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+)
+install(
+ DIRECTORY
+ "${CMAKE_CURRENT_SOURCE_DIR}/include/"
+ "${CMAKE_CURRENT_BINARY_DIR}/gen/include/"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+)
+
+install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+)
+install(FILES "${GODOT_GDEXTENSION_API_FILE}"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp"
+)
+
+install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake"
+ RENAME "unofficial-godot-cpp-config.cmake"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
+)
+install(EXPORT "unofficial-godot-cpp-target"
+ NAMESPACE "unofficial::godot::"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
+)
+
+file(READ "${GODOT_GDEXTENSION_API_FILE}" GODOT_GDEXTENSION_API_JSON)
+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)
+
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/unofficial-godot-cpp-config-version.cmake"
+ VERSION "${GODOT_API_VERSION}"
+ COMPATIBILITY SameMinorVersion
+)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unofficial-godot-cpp-config-version.cmake"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
+)
36 changes: 36 additions & 0 deletions ports/godot-cpp/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO "godotengine/godot-cpp"
REF "godot-${VERSION}-stable"
SHA512 "820e07ffb0545324f01598898bb342d7e143dcc8b83818824e7e1bc22937d3e8016b435f1ec085ebaae8b26e6f6dfb5500f120089316fc0f0c4153c340226941"
HEAD_REF "master"
PATCHES
"packagable.patch"
)

vcpkg_find_acquire_program(PYTHON3)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
"-DPython3_EXECUTABLE=${PYTHON3}"
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(PACKAGE_NAME "unofficial-${PORT}")
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"
)
4 changes: 4 additions & 0 deletions ports/godot-cpp/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
godot-cpp provides CMake targets:

find_package(unofficial-godot-cpp CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::godot::cpp)
17 changes: 17 additions & 0 deletions ports/godot-cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "godot-cpp",
"version": "4.2.1",
"description": "C++ bindings for the Godot script API",
"homepage": "https://github.com/godotengine/godot-cpp",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,10 @@
"baseline": "1.72.0",
"port-version": 8
},
"godot-cpp": {
"baseline": "4.2.1",
"port-version": 0
},
"google-cloud-cpp": {
"baseline": "2.22.0",
"port-version": 1
Expand Down
9 changes: 9 additions & 0 deletions versions/g-/godot-cpp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "3125afbc0a8a200f3a3213b8a4be710ad3190890",
"version": "4.2.1",
"port-version": 0
}
]
}