Skip to content

Commit a68a14e

Browse files
authored
[godot-cpp] Create a new port (#37931)
Fixes #34492 - [X] Changes comply with the [maintainer guide](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md). - [X] The name of the port matches an existing name for this component on https://repology.org/ if possible, and/or is strongly associated with that component on search engines. - [X] Optional dependencies are resolved in exactly one way. For example, if the component is built with CMake, all `find_package` calls are REQUIRED, are satisfied by `vcpkg.json`'s declared dependencies, or disabled with [CMAKE_DISABLE_FIND_PACKAGE_Xxx](https://cmake.org/cmake/help/latest/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.html). - [X] The versioning scheme in `vcpkg.json` matches what upstream says. - [X] The license declaration in `vcpkg.json` matches what upstream says. - [X] The installed as the "copyright" file matches what upstream says. - [X] The source code of the component installed comes from an authoritative source. - [X] The generated "usage text" is accurate. See [adding-usage](https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/examples/adding-usage.md) for context. - [X] The version database is fixed by rerunning `./vcpkg x-add-version --all` and committing the result. - [X] Only one version is in the new port's versions file. - [X] Only one version is added to each modified port's versions file. Notes: - This library is static only, so it's only supported for the static triplets. - Unfortunately, godot-cpp is not yet installable, so I had to patch its cmake script. I have made a PR upstream: godotengine/godot-cpp#1418 But in the meanwhile, I have created an unofficial export target `unofficial::godot::cpp`.
1 parent dadc5ed commit a68a14e

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

ports/godot-cpp/packagable.patch

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index e715102..b000066 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -37,7 +37,7 @@
6+
# Todo
7+
# Test build for Windows, Mac and mingw.
8+
9+
-cmake_minimum_required(VERSION 3.12)
10+
+cmake_minimum_required(VERSION 3.19)
11+
project(godot-cpp LANGUAGES CXX)
12+
13+
option(GENERATE_TEMPLATE_GET_NODE "Generate a template version of the Node class's get_node." ON)
14+
@@ -65,9 +65,8 @@ if(NOT DEFINED BITS)
15+
endif()
16+
17+
# Input from user for GDExtension interface header and the API JSON file
18+
-set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "")
19+
+set(GODOT_GDEXTENSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gdextension" CACHE STRING "")
20+
set(GODOT_CUSTOM_API_FILE "" CACHE STRING "")
21+
-
22+
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
23+
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override.
24+
set(GODOT_GDEXTENSION_API_FILE "${GODOT_CUSTOM_API_FILE}")
25+
@@ -85,9 +84,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
26+
set(GODOT_COMPILE_FLAGS "/utf-8") # /GF /MP
27+
28+
if(CMAKE_BUILD_TYPE MATCHES Debug)
29+
- set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
30+
+ set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /Od") # /Od /RTC1 /Zi
31+
else()
32+
- set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
33+
+ set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /O2") # /Oy /GL /Gy
34+
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
35+
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
36+
endif(CMAKE_BUILD_TYPE MATCHES Debug)
37+
@@ -117,7 +116,6 @@ else()
38+
endif()
39+
40+
# Generate source from the bindings file
41+
-find_package(Python3 3.4 REQUIRED) # pathlib should be present
42+
if(GENERATE_TEMPLATE_GET_NODE)
43+
set(GENERATE_BINDING_PARAMETERS "True")
44+
else()
45+
@@ -183,9 +181,10 @@ if (GODOT_CPP_SYSTEM_HEADERS)
46+
endif ()
47+
48+
target_include_directories(${PROJECT_NAME} ${GODOT_CPP_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
49+
- include
50+
- ${CMAKE_CURRENT_BINARY_DIR}/gen/include
51+
- ${GODOT_GDEXTENSION_DIR}
52+
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
53+
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/gen/include>
54+
+ $<BUILD_INTERFACE:${GODOT_GDEXTENSION_DIR}>
55+
+ $<INSTALL_INTERFACE:include>
56+
)
57+
58+
# Add the compile flags
59+
@@ -213,4 +212,8 @@ set_target_properties(${PROJECT_NAME}
60+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
61+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
62+
OUTPUT_NAME "${OUTPUT_NAME}"
63+
+ EXPORT_NAME "cpp"
64+
)
65+
+
66+
+
67+
+include("cmake/install.cmake")
68+
diff --git a/cmake/config.cmake b/cmake/config.cmake
69+
new file mode 100644
70+
index 0000000..bcddb3c
71+
--- /dev/null
72+
+++ b/cmake/config.cmake
73+
@@ -0,0 +1 @@
74+
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-godot-cpp-target.cmake")
75+
diff --git a/cmake/install.cmake b/cmake/install.cmake
76+
new file mode 100644
77+
index 0000000..f48ab5c
78+
--- /dev/null
79+
+++ b/cmake/install.cmake
80+
@@ -0,0 +1,46 @@
81+
+
82+
+include("CMakePackageConfigHelpers")
83+
+include("GNUInstallDirs")
84+
+
85+
+install(TARGETS "godot-cpp"
86+
+ EXPORT "unofficial-godot-cpp-target"
87+
+ ARCHIVE
88+
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}"
89+
+)
90+
+install(
91+
+ DIRECTORY
92+
+ "${CMAKE_CURRENT_SOURCE_DIR}/include/"
93+
+ "${CMAKE_CURRENT_BINARY_DIR}/gen/include/"
94+
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
95+
+)
96+
+
97+
+install(FILES "${GODOT_GDEXTENSION_DIR}/gdextension_interface.h"
98+
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
99+
+)
100+
+install(FILES "${GODOT_GDEXTENSION_API_FILE}"
101+
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/godot-cpp"
102+
+)
103+
+
104+
+install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake"
105+
+ RENAME "unofficial-godot-cpp-config.cmake"
106+
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
107+
+)
108+
+install(EXPORT "unofficial-godot-cpp-target"
109+
+ NAMESPACE "unofficial::godot::"
110+
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
111+
+)
112+
+
113+
+file(READ "${GODOT_GDEXTENSION_API_FILE}" GODOT_GDEXTENSION_API_JSON)
114+
+string(JSON GODOT_API_VERSION_MAJOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_major")
115+
+string(JSON GODOT_API_VERSION_MINOR GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_minor")
116+
+string(JSON GODOT_API_VERSION_PATCH GET "${GODOT_GDEXTENSION_API_JSON}" "header" "version_patch")
117+
+set(GODOT_API_VERSION "${GODOT_API_VERSION_MAJOR}.${GODOT_API_VERSION_MINOR}.${GODOT_API_VERSION_PATCH}")
118+
+unset(GODOT_GDEXTENSION_API_JSON)
119+
+
120+
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/unofficial-godot-cpp-config-version.cmake"
121+
+ VERSION "${GODOT_API_VERSION}"
122+
+ COMPATIBILITY SameMinorVersion
123+
+)
124+
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unofficial-godot-cpp-config-version.cmake"
125+
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-godot-cpp"
126+
+)

ports/godot-cpp/portfile.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
3+
4+
vcpkg_from_github(
5+
OUT_SOURCE_PATH SOURCE_PATH
6+
REPO "godotengine/godot-cpp"
7+
REF "godot-${VERSION}-stable"
8+
SHA512 "820e07ffb0545324f01598898bb342d7e143dcc8b83818824e7e1bc22937d3e8016b435f1ec085ebaae8b26e6f6dfb5500f120089316fc0f0c4153c340226941"
9+
HEAD_REF "master"
10+
PATCHES
11+
"packagable.patch"
12+
)
13+
14+
vcpkg_find_acquire_program(PYTHON3)
15+
16+
vcpkg_cmake_configure(
17+
SOURCE_PATH "${SOURCE_PATH}"
18+
OPTIONS
19+
"-DPython3_EXECUTABLE=${PYTHON3}"
20+
)
21+
22+
vcpkg_cmake_install()
23+
vcpkg_cmake_config_fixup(PACKAGE_NAME "unofficial-${PORT}")
24+
vcpkg_copy_pdbs()
25+
26+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md")
27+
28+
file(
29+
INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage"
30+
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
31+
)
32+
33+
file(REMOVE_RECURSE
34+
"${CURRENT_PACKAGES_DIR}/debug/include"
35+
"${CURRENT_PACKAGES_DIR}/debug/share"
36+
)

ports/godot-cpp/usage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
godot-cpp provides CMake targets:
2+
3+
find_package(unofficial-godot-cpp CONFIG REQUIRED)
4+
target_link_libraries(main PRIVATE unofficial::godot::cpp)

ports/godot-cpp/vcpkg.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "godot-cpp",
3+
"version": "4.2.1",
4+
"description": "C++ bindings for the Godot script API",
5+
"homepage": "https://github.com/godotengine/godot-cpp",
6+
"license": "MIT",
7+
"dependencies": [
8+
{
9+
"name": "vcpkg-cmake",
10+
"host": true
11+
},
12+
{
13+
"name": "vcpkg-cmake-config",
14+
"host": true
15+
}
16+
]
17+
}

versions/baseline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,6 +3140,10 @@
31403140
"baseline": "1.72.0",
31413141
"port-version": 8
31423142
},
3143+
"godot-cpp": {
3144+
"baseline": "4.2.1",
3145+
"port-version": 0
3146+
},
31433147
"google-cloud-cpp": {
31443148
"baseline": "2.25.0",
31453149
"port-version": 0

versions/g-/godot-cpp.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"versions": [
3+
{
4+
"git-tree": "3125afbc0a8a200f3a3213b8a4be710ad3190890",
5+
"version": "4.2.1",
6+
"port-version": 0
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)