Browse Source

Adds dylib export for "dmg" export mode and change dylib path to "/Contents/Frameworks"

bruvzg 7 years ago
parent
commit
cce6adfc51
3 changed files with 47 additions and 2 deletions
  1. 20 2
      platform/osx/export/export.cpp
  2. 2 0
      platform/osx/os_osx.h
  3. 25 0
      platform/osx/os_osx.mm

+ 20 - 2
platform/osx/export/export.cpp

@@ -358,6 +358,11 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 			err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
 		}
 
+		if (err == OK) {
+			print_line("Creating " + tmp_app_path_name + "/Contents/Frameworks");
+			err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
+		}
+
 		if (err == OK) {
 			print_line("Creating " + tmp_app_path_name + "/Contents/Resources");
 			err = tmp_app_path->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
@@ -502,10 +507,23 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 
 		if (use_dmg()) {
 			String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
-			err = save_pack(p_preset, pack_path);
+			Vector<SharedObject> shared_objects;
+			Error err = save_pack(p_preset, pack_path, &shared_objects);
 
 			// see if we can code sign our new package
 			String identity = p_preset->get("codesign/identity");
+
+			if (err == OK) {
+				DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+				for (int i = 0; i < shared_objects.size(); i++) {
+					da->copy(shared_objects[i].path, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
+					if (err == OK && identity != "") {
+						err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Frameworks/" + shared_objects[i].path.get_file());
+					}
+				}
+				memdelete(da);
+			}
+
 			if (err == OK && identity != "") {
 				ep.step("Code signing bundle", 2);
 
@@ -582,7 +600,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 					ERR_CONTINUE(file.empty());
 
 					zipOpenNewFileInZip(dst_pkg_zip,
-							(pkg_name + ".app/Contents/MacOS/").plus_file(shared_objects[i].path.get_file()).utf8().get_data(),
+							(pkg_name + ".app/Contents/Frameworks/").plus_file(shared_objects[i].path.get_file()).utf8().get_data(),
 							NULL,
 							NULL,
 							0,

+ 2 - 0
platform/osx/os_osx.h

@@ -138,6 +138,8 @@ public:
 
 	virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
 
+	virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false);
+
 	virtual void set_cursor_shape(CursorShape p_shape);
 	virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
 

+ 25 - 0
platform/osx/os_osx.mm

@@ -38,6 +38,8 @@
 #include "servers/visual/visual_server_raster.h"
 #include "version_generated.gen.h"
 
+#include <mach-o/dyld.h>
+
 #include <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 #include <IOKit/IOCFPlugIn.h>
@@ -48,6 +50,7 @@
 #include <os/log.h>
 #endif
 
+#include <dlfcn.h>
 #include <fcntl.h>
 #include <libproc.h>
 #include <stdio.h>
@@ -1258,6 +1261,28 @@ void OS_OSX::alert(const String &p_alert, const String &p_title) {
 	[window release];
 }
 
+Error OS_OSX::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
+
+	String path = p_path;
+
+	if (!FileAccess::exists(path)) {
+		//this code exists so gdnative can load .dylib files from within the executable path
+		path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
+	}
+
+	if (!FileAccess::exists(path)) {
+		//this code exists so gdnative can load .dylib files from a standard macOS location
+		path = get_executable_path().get_base_dir().plus_file("../Frameworks").plus_file(p_path.get_file());
+	}
+
+	p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
+	if (!p_library_handle) {
+		ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror());
+		ERR_FAIL_V(ERR_CANT_OPEN);
+	}
+	return OK;
+}
+
 void OS_OSX::set_cursor_shape(CursorShape p_shape) {
 
 	if (cursor_shape == p_shape)