From f3c457bc3fd98a7c06383e260aec3f5b358ceaae Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Apr 2020 22:34:40 +0800 Subject: impl xcode.application --- tests/projects/objc/application/src/Info.plist | 54 ++++++++++++++++++++ tests/projects/objc/application/xmake.lua | 3 +- xmake/rules/xcode/application/xmake.lua | 68 ++++++++++++++++++++++++++ xmake/scripts/PkgInfo | 1 + 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/projects/objc/application/src/Info.plist create mode 100644 xmake/scripts/PkgInfo diff --git a/tests/projects/objc/application/src/Info.plist b/tests/projects/objc/application/src/Info.plist new file mode 100644 index 000000000..968bf5d3d --- /dev/null +++ b/tests/projects/objc/application/src/Info.plist @@ -0,0 +1,54 @@ + + + + + BuildMachineOSBuild + 18G95 + CFBundleDevelopmentRegion + en + CFBundleExecutable + test + CFBundleIdentifier + org.tboox.test + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + test + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 11B52 + DTPlatformVersion + GM + DTSDKBuild + 19B81 + DTSDKName + macosx10.15 + DTXcode + 1120 + DTXcodeBuild + 11B52 + LSMinimumSystemVersion + 10.14 + NSHumanReadableCopyright + Copyright © 2020 tboox. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + NSSupportsAutomaticTermination + + NSSupportsSuddenTermination + + + diff --git a/tests/projects/objc/application/xmake.lua b/tests/projects/objc/application/xmake.lua index 83522c669..12f773a1d 100644 --- a/tests/projects/objc/application/xmake.lua +++ b/tests/projects/objc/application/xmake.lua @@ -1,5 +1,6 @@ add_rules("mode.debug", "mode.release") -target("demo") +target("test") add_rules("xcode.application") add_files("src/main.m") + add_installfiles("src/Info.plist") diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index 91ec7dbda..756d94d6c 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -23,6 +23,74 @@ rule("xcode.application") -- we must set kind before target.on_load(), may we will use target in on_load() before_load(function (target) + + -- get app directory + local targetdir = target:targetdir() + local appdir = path.join(targetdir, target:basename() .. ".app") + target:data_set("xcode.appdir", appdir) + + -- set target info for app target:set("kind", "binary") + target:set("filename", target:basename()) + if is_plat("macosx") then + target:set("targetdir", path.join(appdir, "Contents", "MacOS")) + else + target:set("targetdir", appdir) + end + + -- register clean files for `xmake clean` + target:add("cleanfiles", appdir) end) + after_build(function (target) + + -- imports + import("private.tools.codesign") + + -- get app directory + local appdir = path.absolute(target:data("xcode.appdir")) + + -- get contents directory + local contentsdir = appdir + if is_plat("macosx") then + contentsdir = path.join(appdir, "Contents") + end + + -- copy PkgInfo to the contents directory + os.cp(path.join(os.programdir(), "scripts", "PkgInfo"), contentsdir) + + -- copy resource files to the contents directory + local srcfiles, dstfiles = target:installfiles(contentsdir) + if srcfiles and dstfiles then + local i = 1 + for _, srcfile in ipairs(srcfiles) do + local dstfile = dstfiles[i] + if dstfile then + os.vcp(srcfile, dstfile) + end + i = i + 1 + end + end + + -- do codesign + codesign(appdir) + end) + + on_install(function (target) + local appdir = path.absolute(target:data("xcode.appdir")) + local installdir = target:installdir() + if not os.isdir(installdir) then + os.mkdir(installdir) + end + os.vcp(appdir, installdir) + end) + + on_uninstall(function (target) + local appdir = path.absolute(target:data("xcode.appdir")) + local installdir = target:installdir() + os.tryrm(path.join(installdir, path.filename(appdir))) + end) + + -- disable package + on_package(function (target) end) + diff --git a/xmake/scripts/PkgInfo b/xmake/scripts/PkgInfo new file mode 100644 index 000000000..bd04210fb --- /dev/null +++ b/xmake/scripts/PkgInfo @@ -0,0 +1 @@ +APPL???? \ No newline at end of file -- cgit v1.3.1