From 3143d12d72eb623c0cfe3585d1302487d7bf81f2 Mon Sep 17 00:00:00 2001 From: Hieu Trung Nguyen Date: Mon, 7 Oct 2024 18:26:36 +0100 Subject: [PATCH 1/2] Remove conflicting paths and udpate code to use correct header --- SConstruct | 28 ++++++++++----------- godot_plugin/godot_plugin.mm | 2 +- godot_plugin/godot_plugin_implementation.h | 6 +++++ godot_plugin/godot_plugin_implementation.mm | 4 +-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/SConstruct b/SConstruct index 3403638..dadc308 100644 --- a/SConstruct +++ b/SConstruct @@ -152,20 +152,18 @@ else: quit(); # Adding header files -env.Append(CPPPATH=[ - '.', - 'godot', - 'godot/main', - 'godot/core', - 'godot/core/os', - 'godot/core/platform', - 'godot/platform/iphone', - 'godot/modules', - 'godot/scene', - 'godot/servers', - 'godot/drivers', - 'godot/thirdparty', -]) +if env['version'] == '3.x': + env.Append(CPPPATH=[ + '.', + 'godot', + 'godot/platform/iphone', + ]) +else: + env.Append(CPPPATH=[ + '.', + 'godot', + 'godot/platform/ios', + ]) # tweak this if you want to use different folders, or more folders, to store your source code in. sources = Glob('godot_plugin/*.cpp') @@ -173,7 +171,7 @@ sources.append(Glob('godot_plugin/*.mm')) sources.append(Glob('godot_plugin/*.m')) # lib.-..a -library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone") +library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "ios") library_name = env['target_name'] + "." + library_platform + "." + env["target"] + ".a" library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources) diff --git a/godot_plugin/godot_plugin.mm b/godot_plugin/godot_plugin.mm index 1e97f10..1952ce2 100644 --- a/godot_plugin/godot_plugin.mm +++ b/godot_plugin/godot_plugin.mm @@ -11,7 +11,7 @@ #import "godot_plugin.h" #import "godot_plugin_implementation.h" -#import "core/engine.h" +#import "core/config/engine.h" PluginExample *plugin; diff --git a/godot_plugin/godot_plugin_implementation.h b/godot_plugin/godot_plugin_implementation.h index 198f711..5f31d77 100644 --- a/godot_plugin/godot_plugin_implementation.h +++ b/godot_plugin/godot_plugin_implementation.h @@ -9,7 +9,13 @@ #ifndef godot_plugin_implementation_h #define godot_plugin_implementation_h +#include "core/version.h" + +// #if VERSION_MAJOR == 4 +#include "core/object/class_db.h" +#else #include "core/object.h" +#endif class PluginExample : public Object { GDCLASS(PluginExample, Object); diff --git a/godot_plugin/godot_plugin_implementation.mm b/godot_plugin/godot_plugin_implementation.mm index e811092..634612f 100644 --- a/godot_plugin/godot_plugin_implementation.mm +++ b/godot_plugin/godot_plugin_implementation.mm @@ -8,8 +8,8 @@ #import -#include "core/project_settings.h" -#include "core/class_db.h" +#include "core/config/project_settings.h" +#include "core/object/class_db.h" #import "godot_plugin_implementation.h" From 85497c3a2a9c0c2d247eb3b5b8d664d268077ade Mon Sep 17 00:00:00 2001 From: Hieu Trung Nguyen Date: Wed, 13 Nov 2024 11:22:26 +0000 Subject: [PATCH 2/2] Update README.md to include more detail instruction on how to build the plugin --- README.md | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6e86af4..9cda072 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Godot iOS Plugin template This repo contains a *starter* Xcode and SCons configuration to build Godot plugin for iOS. -Xcode project and Scons configuration allows to build static `.a` library, that could be used with `.gdip` file as Godot's plugin to include platform functionality into exported application. +Xcode project and Scons configuration allows user to build static `.a` library, that could be used with `.gdip` file as Godot's plugin to include platform functionality into exported application. # Initial setup @@ -9,11 +9,24 @@ Xcode project and Scons configuration allows to build static `.a` library, that To build iOS plugin library it's required to have Godot's header files including generated ones. So running `scons platform=iphone target=` in `godot` submodule folder is required. -# Working with Xcode - -Building project should be enough to build a `.a` library that could be used with `.gdip` file. - -# Working with SCons - -Running `scons platform=ios arch= target= target_name= version=<3.2|4.0>` would result in plugin library for specific platform. -Compiling for multiple archs and using `lipo -create .. -output ..` might be required for release builds. +To build iOS plugin library it's required to have Godot's header files +1. You must use the headers of the same godot engine version as your editor (e.g. version 4.3) +``` +cd godot +git fetch +git checkout origin/4.3 +``` +2. run `scons platform=ios target=` in `godot` submodule folder to generate header files (use `template_debug` for development and `template_release` for release) +**Note**: +- You don't have to wait for full engine compilation, as header files are generated first. Once the actual compilation starts, you can stop this command by pressing `Ctrl + C` +- The scons command may vary depend on the version of Godot engine. Older version may use `scons platform=iphone target=` (Check SConstruct file to construct the right command) + +## Building Godot Plugin + +- run `scons platform=ios arch= target= target_name= version=<3.2|4.0>` to build GodotShare (the generated `.a` file is found in /bin) +- The above command only generate library that works in IOS device but not in simulator. To test in simulator, run `scons platform=ios arch= target= target_name= version=<3.2|4.0> simulator=yes` + +## Using Godot Plugin +- Create the directory [Your_Godot_project]/ios/plugins/[Library_name] in your Godot project and copy both the generated `.a` file and `plugin_example.gdip` file there +- Update `plugin_example.gdip` to point to correct `.a` file (The plugin should show up in the export template) +- Compiling for multiple archs and using `lipo -create .. -output ..` might be required for release builds.