Rename godot-headers to gdextension, move header to top folder

Changes the `<godot/gdextension_interface.h>` include to simply
`<gdextension_interface.h>`.

Refactor and better document the SCons and CMake logic around setting
the paths to the header and API JSON file.
pull/960/head
Rémi Verschelde 2022-12-14 00:40:17 +01:00
parent 1e8eb1c1f2
commit bab247dcb6
No known key found for this signature in database
GPG Key ID: C3336907360768E1
22 changed files with 68 additions and 50 deletions

View File

@ -2,8 +2,8 @@
# CMAKE_BUILD_TYPE: Compilation target (Debug or Release defaults to Debug)
#
# godot-cpp cmake arguments
# GODOT_HEADERS_DIR: Custom include path for the GDExtension. It should include interface header at this subpath: godot/gdextension_interface.h
# GODOT_CUSTOM_API_FILE: Custom path for extension_api.json
# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
# FLOAT_TYPE Floating-point precision (32, 64)
#
# Android cmake arguments
@ -57,9 +57,14 @@ if(NOT DEFINED BITS)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
endif()
# Input from user for godot headers and the api file
set(GODOT_HEADERS_DIR "godot-headers" CACHE STRING "")
set(GODOT_CUSTOM_API_FILE "godot-headers/extension_api.json" CACHE STRING "")
# Input from user for GDExtension interface header and the API JSON file
set(GODOT_GDEXTENSION_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}")
endif()
set(GODOT_COMPILE_FLAGS )
set(GODOT_LINKER_FLAGS )
@ -125,16 +130,16 @@ else()
set(GENERATE_BINDING_PARAMETERS "False")
endif()
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_CUSTOM_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)"
execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_GDEXTENSION_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GENERATED_FILES_LIST
)
add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${FLOAT_TYPE_FLAG}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_GDEXTENSION_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${FLOAT_TYPE_FLAG}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MAIN_DEPENDENCY ${GODOT_CUSTOM_API_FILE}
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/binding_generator.py
COMMENT "Generating bindings"
)
@ -173,7 +178,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
${GODOT_HEADERS_DIR}
${GODOT_GDEXTENSION_DIR}
)
# Add the compile flags

View File

@ -24,10 +24,9 @@ Stable releases are also tagged on this repository:
this repository as a Git submodule, checking out the specific tag matching your
Godot version.**
> As the `master` and `3.x` branches are constantly getting updates, if you are
> As the `master` branch of Godot is constantly getting updated, if you are
> using `godot-cpp` against a more current version of Godot, see the instructions
> in [**godot-headers**](https://github.com/godotengine/godot-headers) for
> updating the relevant files.
> in the `gdextension` folder to update the relevant files.
## Contributing

View File

@ -77,10 +77,20 @@ opts.Add(
)
opts.Add(
PathVariable(
"headers_dir", "Path to the directory containing Godot headers", "godot-headers", PathVariable.PathIsDir
"gdextension_dir",
"Path to the directory containing GDExtension interface header and API JSON file",
"gdextension",
PathVariable.PathIsDir,
)
)
opts.Add(
PathVariable(
"custom_api_file",
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
None,
PathVariable.PathIsFile,
)
)
opts.Add(PathVariable("custom_api_file", "Path to a custom JSON API file", None, PathVariable.PathIsFile))
opts.Add(
BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False)
)
@ -179,11 +189,11 @@ json_api_file = ""
if "custom_api_file" in env:
json_api_file = env["custom_api_file"]
else:
json_api_file = os.path.join(os.getcwd(), env["headers_dir"], "extension_api.json")
json_api_file = os.path.join(os.getcwd(), env["gdextension_dir"], "extension_api.json")
bindings = env.GenerateBindings(
env.Dir("."),
[json_api_file, os.path.join(env["headers_dir"], "godot", "gdextension_interface.h"), "binding_generator.py"],
[json_api_file, os.path.join(env["gdextension_dir"], "gdextension_interface.h"), "binding_generator.py"],
)
scons_cache_path = os.environ.get("SCONS_CACHE")
@ -197,7 +207,7 @@ if env["generate_bindings"]:
NoCache(bindings)
# Includes
env.Append(CPPPATH=[[env.Dir(d) for d in [env["headers_dir"], "include", os.path.join("gen", "include")]]])
env.Append(CPPPATH=[[env.Dir(d) for d in [env["gdextension_dir"], "include", os.path.join("gen", "include")]]])
# Sources to compile
sources = []

View File

@ -377,7 +377,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
if len(fully_used_classes) > 0:
result.append("")
result.append(f"#include <godot/gdextension_interface.h>")
result.append(f"#include <gdextension_interface.h>")
result.append("")
result.append("namespace godot {")
result.append("")

20
gdextension/README.md Normal file
View File

@ -0,0 +1,20 @@
# GDExtension header and API
This repository contains the C header and API JSON for
[**Godot Engine**](https://github.com/godotengine/godot)'s *GDExtensions* API.
## Updating header and API
If the current branch is not up-to-date for your needs, or if you want to sync
the header and API JSON with your own modified version of Godot, here is the
update procedure used to sync this repository with upstream releases:
- Compile [Godot Engine](https://github.com/godotengine/godot) at the specific
version/commit which you are using.
* Or if you use an official release, download that version of the Godot editor.
- Use the compiled or downloaded executable to generate the `extension_api.json`
and `gdextension_interface.h` files with:
```
godot --dump-extension-api --dump-gdextension-interface
```

View File

@ -1,16 +0,0 @@
# godot-headers
This repository contains C headers for
[**Godot Engine**](https://github.com/godotengine/godot)'s *GDExtensions* API.
## Updating Headers
If the current branch is not up-to-date for your needs, or if you want to sync
the headers with your own modified version of Godot, here is the update
procedure used to sync this repository with upstream releases:
- Compile [Godot Engine](https://github.com/godotengine/godot) at the specific
version/commit which you are using.
- Use the compiled executable to generate the `extension_api.json` file with:
`godot --dump-extension-api extension_api.json`
- Copy the file `core/extension/gdextension_interface.h` to `godot`

View File

@ -31,7 +31,7 @@
#ifndef GODOT_BINDER_COMMON_HPP
#define GODOT_BINDER_COMMON_HPP
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <godot_cpp/core/method_ptrcall.hpp>
#include <godot_cpp/core/type_info.hpp>

View File

@ -31,7 +31,7 @@
#ifndef GODOT_BUILTIN_PTRCALL_HPP
#define GODOT_BUILTIN_PTRCALL_HPP
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <array>

View File

@ -31,7 +31,7 @@
#ifndef GODOT_CLASS_DB_HPP
#define GODOT_CLASS_DB_HPP
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/core/error_macros.hpp>

View File

@ -31,7 +31,7 @@
#ifndef GODOT_ENGINE_PTRCALL_HPP
#define GODOT_ENGINE_PTRCALL_HPP
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/core/object.hpp>

View File

@ -33,7 +33,7 @@
#include <godot_cpp/core/defs.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <cmath>

View File

@ -36,7 +36,7 @@
#include <godot_cpp/core/memory.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <godot_cpp/classes/global_constants.hpp>

View File

@ -41,7 +41,7 @@
#include <godot_cpp/godot.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <vector>

View File

@ -39,7 +39,7 @@
#include <godot_cpp/godot.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
namespace godot {

View File

@ -35,7 +35,7 @@
#include <godot_cpp/variant/typed_array.hpp>
#include <godot_cpp/variant/variant.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
namespace godot {

View File

@ -31,7 +31,7 @@
#ifndef GODOT_GODOT_HPP
#define GODOT_GODOT_HPP
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
namespace godot {

View File

@ -36,7 +36,7 @@
#include <godot_cpp/variant/builtin_types.hpp>
#include <godot_cpp/variant/variant_size.hpp>
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <array>

View File

@ -8,7 +8,7 @@ sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", ".."))
from binding_generator import get_file_list, generate_bindings
api_filepath = "godot-headers/extension_api.json"
api_filepath = "gdextension/extension_api.json"
bits = "64"
double = "float"
output_dir = "self_test"

View File

@ -1,7 +1,7 @@
project(godot-cpp-test)
cmake_minimum_required(VERSION 3.6)
set(GODOT_HEADERS_PATH ../godot-headers/ CACHE STRING "Path to Godot headers")
set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
@ -103,7 +103,7 @@ target_include_directories(${PROJECT_NAME} SYSTEM
PRIVATE
${CPP_BINDINGS_PATH}/include
${CPP_BINDINGS_PATH}/gen/include
${GODOT_HEADERS_PATH}
${GODOT_GDEXTENSION_DIR}
)
# Create the correct name (godot.os.build_type.system_bits)

View File

@ -5,7 +5,7 @@
#include "register_types.h"
#include <godot/gdextension_interface.h>
#include <gdextension_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>