summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Minakov <naithar@icloud.com>2020-07-02 12:38:51 +0300
committerSergey Minakov <naithar@icloud.com>2020-07-02 12:55:49 +0300
commit9086599ae60dea951db33ca50a54c30c4a05bb8d (patch)
tree702aa559a0734e28e4b6aa7b83e12d6a3bd0b67d
parent719609522a30fa9e3b96b028ac5a1d1a65f1678f (diff)
GDNative: support dynamic loading of iOS frameworks
-rw-r--r--modules/gdnative/gdnative.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 3d747ba41e..bb2da70c3a 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -291,8 +291,26 @@ bool GDNative::initialize() {
return false;
}
#ifdef IPHONE_ENABLED
- // on iOS we use static linking
+ // On iOS we use static linking by default.
String path = "";
+
+ // On iOS dylibs is not allowed, but can be replaced with .framework or .xcframework.
+ // If they are used, we can run dlopen on them.
+ // They should be located under Frameworks directory, so we need to replace library path.
+ if (!lib_path.ends_with(".a")) {
+ path = ProjectSettings::get_singleton()->globalize_path(lib_path);
+
+ if (!FileAccess::exists(path)) {
+ String lib_name = lib_path.get_basename().get_file();
+ String framework_path_format = "Frameworks/$name.framework/$name";
+
+ Dictionary format_dict;
+ format_dict["name"] = lib_name;
+ String framework_path = framework_path_format.format(format_dict, "$_");
+
+ path = OS::get_singleton()->get_executable_path().get_base_dir().plus_file(framework_path);
+ }
+ }
#elif defined(ANDROID_ENABLED)
// On Android dynamic libraries are located separately from resource assets,
// we should pass library name to dlopen(). The library name is flattened