summaryrefslogtreecommitdiff
path: root/xmake/rules/xcode
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-23 09:36:29 +0800
committerGitHub <[email protected]>2022-08-23 09:36:29 +0800
commit006390def621247c8d3857495afaa4e7038a32fa (patch)
treeaa0bb46561ded824fd53999d0d6884fa803ba942 /xmake/rules/xcode
parent5a9631ba93e7a677a8c1e9769b17e392cdbb61af (diff)
parent2019daea91cb6ad5eda1a38fab3b515e261ea698 (diff)
Merge pull request #2707 from xmake-io/framework
improve frameworks
Diffstat (limited to 'xmake/rules/xcode')
-rw-r--r--xmake/rules/xcode/application/build.lua35
-rw-r--r--xmake/rules/xcode/framework/xmake.lua7
2 files changed, 40 insertions, 2 deletions
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index a4862ae86..b39c3546e 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -25,6 +25,25 @@ import("core.project.depend")
import("private.tools.codesign")
import("utils.progress")
+-- copy frameworks with symlink
+--
+-- TODO we should improve os.cp to support for copying directory with symlink
+-- os.vcp(frameworkdir, frameworksdir, {symlink = true})
+function _copy_frameworks(frameworkdir, frameworksdir)
+ os.mkdir(frameworksdir)
+ local frameworkdir_dst = path.join(frameworksdir, path.filename(frameworkdir))
+ os.tryrm(frameworkdir_dst)
+ for _, filepath in ipairs(os.filedirs(path.join(frameworkdir, "*"))) do
+ if path.filename(filepath) == "Versions" then
+ _copy_frameworks(filepath, frameworkdir_dst)
+ else
+ local dstpath = path.join(frameworkdir_dst, path.filename(filepath))
+ os.tryrm(dstpath)
+ os.cp(filepath, dstpath, {symlink = true})
+ end
+ end
+end
+
-- main entry
function main (target, opt)
@@ -32,6 +51,7 @@ function main (target, opt)
local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir"))
local resourcesdir = path.absolute(target:data("xcode.bundle.resourcesdir"))
+ local frameworksdir = path.join(contentsdir, "Frameworks")
-- do build if changed
depend.on_changed(function ()
@@ -46,10 +66,21 @@ function main (target, opt)
end
os.vcp(target:targetfile(), path.join(binarydir, path.filename(target:targetfile())))
- -- copy dependent dynamic libraries, TODO copy frameworks
+ -- change rpath
+ -- @see https://github.com/xmake-io/xmake/issues/2679#issuecomment-1221839215
+ local targetfile = path.join(binarydir, path.filename(target:targetfile()))
+ os.vrunv("install_name_tool", {"-delete_rpath", "@loader_path", targetfile})
+ os.vrunv("install_name_tool", {"-add_rpath", "@executable_path/../Frameworks", targetfile})
+
+ -- copy dependent dynamic libraries and frameworks
for _, dep in ipairs(target:orderdeps()) do
if dep:kind() == "shared" then
- os.vcp(dep:targetfile(), binarydir)
+ local frameworkdir = dep:data("xcode.bundle.rootdir")
+ if dep:rule("xcode.framework") and frameworkdir then
+ _copy_frameworks(frameworkdir, frameworksdir, {symlink = true})
+ else
+ os.vcp(dep:targetfile(), binarydir)
+ end
end
end
diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua
index de7d7c93c..520ccf1b8 100644
--- a/xmake/rules/xcode/framework/xmake.lua
+++ b/xmake/rules/xcode/framework/xmake.lua
@@ -105,6 +105,13 @@ rule("xcode.framework")
end
os.vcp(target:targetfile(), contentsdir)
+ -- change rpath
+ -- @see https://github.com/xmake-io/xmake/issues/2679#issuecomment-1221839215
+ local filename = path.filename(target:targetfile())
+ local targetfile = path.join(contentsdir, filename)
+ local rpath = path.relative(contentsdir, path.directory(bundledir))
+ os.vrunv("install_name_tool", {"-id", path.join("@rpath", rpath, filename), targetfile})
+
-- move header files
os.tryrm(headersdir)
os.mv(path.join(contentsdir, "Headers.tmp", target:basename()), headersdir)