diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 4f80be65a..bb6b93add 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -33,9 +33,11 @@ class MacPlatform extends PlatformTarget private var contentDirectory:String; private var executableDirectory:String; private var executablePath:String; - private var is64:Bool; + private var targetArchitecture:Architecture; private var targetType:String; + private var dirSuffix(get, never):String; + public function new(command:String, _project:HXProject, targetFlags:Map) { super(command, _project, targetFlags); @@ -93,20 +95,6 @@ class MacPlatform extends PlatformTarget title: "" }; - switch (System.hostArchitecture) - { - case ARMV6: - defaults.architectures = [ARMV6]; - case ARMV7: - defaults.architectures = [ARMV7]; - case X86: - defaults.architectures = [X86]; - case X64: - defaults.architectures = [X64]; - default: - defaults.architectures = []; - } - defaults.window.allowHighDPI = false; for (i in 1...project.windows.length) @@ -122,11 +110,13 @@ class MacPlatform extends PlatformTarget project.architectures.remove(excludeArchitecture); } + targetArchitecture = Type.createEnum(Architecture, Type.enumConstructor(System.hostArchitecture)); for (architecture in project.architectures) { - if (architecture == Architecture.X64) + if (architecture.match(X86 | X64 | ARMV6 | ARMV7 | ARM64)) { - is64 = true; + targetArchitecture = architecture; + break; } } @@ -137,7 +127,6 @@ class MacPlatform extends PlatformTarget else if (project.targetFlags.exists("hl")) { targetType = "hl"; - is64 = true; } else if (project.targetFlags.exists("java")) { @@ -157,7 +146,7 @@ class MacPlatform extends PlatformTarget } targetDirectory = Path.combine(project.app.path, project.config.getString("mac.output-directory", targetType == "cpp" ? "macos" : targetType)); - targetDirectory = StringTools.replace(targetDirectory, "arch64", is64 ? "64" : ""); + targetDirectory = StringTools.replace(targetDirectory, "arch64", dirSuffix); applicationDirectory = targetDirectory + "/bin/" + project.app.file + ".app"; contentDirectory = applicationDirectory + "/Contents/Resources"; executableDirectory = applicationDirectory + "/Contents/MacOS"; @@ -179,11 +168,11 @@ class MacPlatform extends PlatformTarget // TODO: Support single binary for HashLink if (targetType == "hl") { - ProjectHelper.copyLibrary(project, ndll, "Mac" + (is64 ? "64" : ""), "", ".hdll", executableDirectory, project.debug, targetSuffix); + ProjectHelper.copyLibrary(project, ndll, "Mac" + dirSuffix, "", ".hdll", executableDirectory, project.debug, targetSuffix); } else { - ProjectHelper.copyLibrary(project, ndll, "Mac" + (is64 ? "64" : ""), "", + ProjectHelper.copyLibrary(project, ndll, "Mac" + dirSuffix, "", (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", executableDirectory, project.debug, targetSuffix); @@ -197,8 +186,8 @@ class MacPlatform extends PlatformTarget if (noOutput) return; - NekoHelper.createExecutable(project.templatePaths, "mac" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath); - NekoHelper.copyLibraries(project.templatePaths, "mac" + (is64 ? "64" : ""), executableDirectory); + NekoHelper.createExecutable(project.templatePaths, "mac" + dirSuffix, targetDirectory + "/obj/ApplicationMain.n", executablePath); + NekoHelper.copyLibraries(project.templatePaths, "mac" + dirSuffix, executableDirectory); } else if (targetType == "hl") { @@ -206,7 +195,7 @@ class MacPlatform extends PlatformTarget if (noOutput) return; - HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, is64); + HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, true); // HashLink looks for hlboot.dat and libraries in the current // working directory, so the .app file won't work properly if it @@ -234,7 +223,7 @@ class MacPlatform extends PlatformTarget System.recursiveCopy(targetDirectory + "/obj/lib", Path.combine(executableDirectory, "lib")); System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", Path.combine(executableDirectory, project.app.file + ".jar")); - JavaHelper.copyLibraries(project.templatePaths, "Mac" + (is64 ? "64" : ""), executableDirectory); + JavaHelper.copyLibraries(project.templatePaths, "Mac" + dirSuffix, executableDirectory); } else if (targetType == "nodejs") { @@ -242,8 +231,8 @@ class MacPlatform extends PlatformTarget if (noOutput) return; - // NekoHelper.createExecutable (project.templatePaths, "Mac" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath); - // NekoHelper.copyLibraries (project.templatePaths, "Mac" + (is64 ? "64" : ""), executableDirectory); + // NekoHelper.createExecutable (project.templatePaths, "Mac" + dirSuffix, targetDirectory + "/obj/ApplicationMain.n", executablePath); + // NekoHelper.copyLibraries (project.templatePaths, "Mac" + dirSuffix, executableDirectory); } else if (targetType == "cs") { @@ -264,12 +253,18 @@ class MacPlatform extends PlatformTarget var haxeArgs = [hxml, "-D", "HXCPP_CLANG"]; var flags = ["-DHXCPP_CLANG"]; - if (is64) + if (targetArchitecture == X64) { haxeArgs.push("-D"); haxeArgs.push("HXCPP_M64"); flags.push("-DHXCPP_M64"); } + else if (targetArchitecture == ARM64) + { + haxeArgs.push("-D"); + haxeArgs.push("HXCPP_ARM64"); + flags.push("-DHXCPP_ARM64"); + } if (!project.targetFlags.exists("static")) { @@ -332,7 +327,7 @@ class MacPlatform extends PlatformTarget context.NODE_FILE = executableDirectory + "/ApplicationMain.js"; context.HL_FILE = targetDirectory + "/obj/ApplicationMain.hl"; context.CPP_DIR = targetDirectory + "/obj/"; - context.BUILD_DIR = project.app.path + "/mac" + (is64 ? "64" : ""); + context.BUILD_DIR = project.app.path + "/mac" + dirSuffix; return context; } @@ -372,22 +367,27 @@ class MacPlatform extends PlatformTarget { var commands = []; - if (targetFlags.exists("hl") && System.hostArchitecture == X64) + switch (System.hostArchitecture) { - // TODO: Support single binary - commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64", "-Dhashlink"]); - } - else - { - if (!targetFlags.exists("32") && (command == "rebuild" || System.hostArchitecture == X64)) - { - commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64"]); - } - - if (!targetFlags.exists("64") && (targetFlags.exists("32") || System.hostArchitecture == X86)) - { + case X64: + if (targetFlags.exists("hl")) + { + // TODO: Support single binary + commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64", "-Dhashlink"]); + } + else if (!targetFlags.exists("32")) + { + commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64"]); + } + else + { + commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M32"]); + } + case X86: commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M32"]); - } + case ARM64: + commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_ARM64"]); + default: } if (targetFlags.exists("hl")) @@ -455,7 +455,7 @@ class MacPlatform extends PlatformTarget if (ndll.path == null || ndll.path == "") { - context.ndlls[i].path = NDLL.getLibraryPath(ndll, "Mac" + (is64 ? "64" : ""), "lib", ".a", project.debug); + context.ndlls[i].path = NDLL.getLibraryPath(ndll, "Mac" + dirSuffix, "lib", ".a", project.debug); } } } @@ -530,4 +530,11 @@ class MacPlatform extends PlatformTarget @ignore public override function trace():Void {} @ignore public override function uninstall():Void {} + + // Getters & Setters + + private inline function get_dirSuffix():String + { + return targetArchitecture == X64 ? "64" : ""; + } }