summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-03 09:24:00 +0800
committerGitHub <[email protected]>2025-11-03 09:24:00 +0800
commitc5d08dcde1187fbf3903d51d63af8e15e28650c1 (patch)
tree47f7c09e1407d63fe050da2e436d27b9ae521460
parentef232054688770d4d858866019ee29eb3b17d318 (diff)
parentffd3dd3885359c969d36d3ea963e011c50dc854d (diff)
Merge pull request #6977 from Arthapz/improve-xcode-toolchain
nfc(xcode) refactor xcode toolchain, improve it and use it in llvm toolchain when targeting a apple device
-rw-r--r--xmake/core/project/target.lua10
-rw-r--r--xmake/rules/swift/xmake.lua10
-rw-r--r--xmake/toolchains/llvm/xmake.lua43
-rw-r--r--xmake/toolchains/xcode/load_appletvos.lua38
-rw-r--r--xmake/toolchains/xcode/load_applexros.lua42
-rw-r--r--xmake/toolchains/xcode/load_iphoneos.lua42
-rw-r--r--xmake/toolchains/xcode/load_macosx.lua112
-rw-r--r--xmake/toolchains/xcode/load_platform.lua60
-rw-r--r--xmake/toolchains/xcode/load_watchos.lua38
9 files changed, 165 insertions, 230 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3f9e7b813..6547a4a6c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1065,17 +1065,17 @@ end
-- get the target compiler
function _instance:compiler(sourcekind)
- local compilerinst = self:_memcache():get("compiler")
+ if not sourcekind then
+ os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as")
+ end
+ local compilerinst = self:_memcache():get("compiler_" .. sourcekind)
if not compilerinst then
- if not sourcekind then
- os.raise("please pass sourcekind to the first argument of target:compiler(), e.g. cc, cxx, as")
- end
local instance, errors = compiler.load(sourcekind, self)
if not instance then
os.raise(errors)
end
compilerinst = instance
- self:_memcache():set("compiler", compilerinst)
+ self:_memcache():set("compiler_" .. sourcekind, compilerinst)
end
return compilerinst
end
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 78f2ebb4f..46b225db9 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -73,7 +73,6 @@ rule("swift.interop")
import("utils.progress")
import("core.base.option")
import("core.tool.compiler")
- import("core.language.language")
import("core.project.depend")
local function _get_target_cpp_langflags()
@@ -96,7 +95,7 @@ rule("swift.interop")
end
local mode = target:data("swift.interop")
- local sc = target:tool("sc")
+ local sc = target:compiler("sc")
assert(sc, "No swift compiler found!")
local outdir = target:data("swift.interop.outdir")
if not os.isdir(outdir) then os.mkdir(outdir) end
@@ -134,8 +133,7 @@ rule("swift.interop")
progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.swift.header %s", target:fullname(), headername)
end
- local compinst = import("core.tool.compiler").load("sc")
- local _scflags = compinst:compflags({target = target, sourcekind = "sc"})
+ local _scflags = sc:compflags({target = target, sourcekind = "sc"})
local scflags
if target:has_tool("sc", "swift_frontend") then
for _, scflag in ipairs(_scflags) do
@@ -160,11 +158,11 @@ rule("swift.interop")
stdflag or {},
public_sourcefiles)
if option.get("verbose") then
- print(os.args(table.join(sc, flags)))
+ print(os.args(table.join(sc:program(), flags)))
end
os.tryrm(header)
- local outdata, errdata = os.iorunv(sc, flags)
+ local outdata, errdata = os.iorunv(sc:program(), flags)
assert(outdata, errdata)
end, {
files = public_sourcefiles,
diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua
index 3dce6bff4..b1cf68d5c 100644
--- a/xmake/toolchains/llvm/xmake.lua
+++ b/xmake/toolchains/llvm/xmake.lua
@@ -87,26 +87,37 @@ toolchain("llvm")
if toolchain:is_plat("windows") and not is_host("windows") then
toolchain:add("ldflags", "-fuse-ld=lld")
toolchain:add("shflags", "-fuse-ld=lld")
- elseif toolchain:is_plat("macosx") then
- if not toolchain:config("xcode_sysroot") then
- local xcode_dir = get_config("xcode")
- local xcode_sdkver = toolchain:config("xcode_sdkver")
- local xcode_sdkdir
- if xcode_dir and xcode_sdkver then
- local macsdk = path.join(xcode_dir, "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk")
- if os.isdir(macsdk) then
- xcode_sdkdir = macsdk
+ elseif toolchain:is_plat("macosx", "iphoneos", "tvos", "watchos", "xros") then
+ if not toolchain:config("xcode_sysroot") and not get_config("xcode_sysroot") then
+ local xcode_dir = toolchain:config("xcode") or get_config("xcode")
+ local xcode_sdkver = toolchain:config("xcode_sdkver") or get_config("xcode_sdkver")
+ local sdkdir
+ if toolchain:is_plat("macosx") then
+ -- @see https://github.com/xmake-io/xmake/issues/1179
+ local sdkroot = xcode_dir and path.join(xcode_dir, "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs")
+ or "/Library/Developer/CommandLineTools/SDKs"
+ sdkdir = xcode_sdkver and path.join(sdkroot, "MacOSX" .. xcode_sdkver .. ".sdk")
+ if not sdkdir or not os.isdir(sdkdir) then
+ sdkdir = path.join(sdkroot, "MacOSX.sdk")
+ sdkdir = os.isdir(sdkdir) and sdkdir or nil
end
else
- -- @see https://github.com/xmake-io/xmake/issues/1179
- local macsdk = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
- if os.isdir(macsdk) then
- xcode_sdkdir = macsdk
+ local mapper = {
+ iphoneos = { arm64 = "iPhoneOS", ["x86_64"] = "iPhoneSimulator" },
+ tvos = { arm64 = "AppleTVOS", ["x86_64"] = "AppleTVSimulator" },
+ watchos = { arm64 = "WatchOS", ["x86_64"] = "WatchSimulator" },
+ xros = { arm64 = "XROS", ["x86_64"] = "XRSimulator" }
+ }
+ local plat = mapper[toolchain:plat()][toolchain:arch()]
+ local sdkroot = xcode_dir and path.join(xcode_dir, "Contents/Developer/Platforms/" .. plat ..".platform/Developer/SDKs")
+ if xcode_sdkver and os.isdir(path.join(sdkroot, plat .. xcode_sdkver .. ".sdk")) then
+ sdkdir = path.join(sdkroot, plat .. xcode_sdkver .. ".sdk")
+ elseif os.isdir(path.join(sdkroot, plat .. ".sdk")) then
+ sdkdir = path.join(sdkroot, plat .. ".sdk")
end
+ assert(sdkdir and os.isdir(sdkdir), "No xcode sysroot found!")
end
- if os.isdir(xcode_sdkdir) then
- toolchain:config_set("xcode_sysroot", xcode_sdkdir)
- end
+ toolchain:config_set("xcode_sysroot", sdkdir)
end
-- load configurations
import(".xcode.load_" .. toolchain:plat())(toolchain)
diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua
index 446177cab..cc3382a06 100644
--- a/xmake/toolchains/xcode/load_appletvos.lua
+++ b/xmake/toolchains/xcode/load_appletvos.lua
@@ -18,41 +18,9 @@
-- @file load_appletvos.lua
--
-function main(toolchain)
-
- -- init architecture
- local arch = toolchain:arch()
- local xcode_sdkver = toolchain:config("xcode_sdkver")
- local xcode_sysroot = toolchain:config("xcode_sysroot")
-
- -- is simulator?
- local simulator = toolchain:config("appledev") == "simulator"
-
- -- init target minimal version
- local target_minver = toolchain:config("target_minver")
- local target_minver_flags = (simulator and "-mappletvsimulator-version-min=" or "-mappletvos-version-min=") .. target_minver
-
- -- init flags for c/c++
- toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
+import("load_platform")
- -- init flags for objc/c++
- toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
- toolchain:add("mxflags", "-fobjc-arc")
-
- -- init flags for asm
- toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-
- -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
- toolchain:add("scflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scshflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scarflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scldflags", format("-target %s-apple-tvos%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
-
- toolchain:add("scshflags", "-sdk " .. xcode_sysroot, "-emit-library")
- toolchain:add("scarflags", "-sdk " .. xcode_sysroot, "-emit-library", "-static")
- toolchain:add("scldflags", "-sdk " .. xcode_sysroot, "-emit-executable")
+function main(toolchain)
+ load_platform(toolchain, "tvos")
end
diff --git a/xmake/toolchains/xcode/load_applexros.lua b/xmake/toolchains/xcode/load_applexros.lua
index 6a74abaf7..497c5024c 100644
--- a/xmake/toolchains/xcode/load_applexros.lua
+++ b/xmake/toolchains/xcode/load_applexros.lua
@@ -18,45 +18,9 @@
-- @file load_applexros.lua
--
-function main(toolchain)
-
- local arch = toolchain:arch()
- local xcode_sdkver = toolchain:config("xcode_sdkver")
- local xcode_sysroot = toolchain:config("xcode_sysroot")
- local target_minver = toolchain:config("target_minver")
-
- -- init target flags
- if target_minver then
- local simulator = toolchain:config("appledev") == "simulator"
- local target = (simulator and "%s-apple-xrsimulator%s" or "%s-apple-xros%s"):format(arch, target_minver)
- toolchain:add("cxflags", "-target", target)
- toolchain:add("mxflags", "-target", target)
- toolchain:add("asflags", "-target", target)
- toolchain:add("ldflags", "-target", target)
- toolchain:add("shflags", "-target", target)
- toolchain:add("scflags", "-target", target)
- toolchain:add("scldflags", "-target", target)
- toolchain:add("scshflags", "-target", target)
- toolchain:add("scarflags", "-target", target)
- end
-
- -- init flags for c/c++
- toolchain:add("cxflags", "-isysroot", xcode_sysroot)
- toolchain:add("ldflags", "-fobjc-link-runtime", "-isysroot", xcode_sysroot)
- toolchain:add("shflags", "-fobjc-link-runtime", "-isysroot", xcode_sysroot)
+import("load_platform")
- -- init flags for objc/c++
- toolchain:add("mxflags", "-isysroot", xcode_sysroot)
- -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
- toolchain:add("mxflags", "-fobjc-arc")
-
- -- init flags for asm
- toolchain:add("asflags", "-isysroot", xcode_sysroot)
-
- -- init flags for swift (with toolchain:add("ldflags") and toolchain:add("shflags") and toolchain:add("arflags"))
- toolchain:add("scflags", "-sdk " .. xcode_sysroot)
- toolchain:add("scshflags", "-sdk " .. xcode_sysroot, "-emit-library")
- toolchain:add("scarflags", "-sdk " .. xcode_sysroot, "-emit-library", "-static")
- toolchain:add("scldflags", "-sdk " .. xcode_sysroot, "-emit-executable")
+function main(toolchain)
+ load_platform(toolchain, "xros")
end
diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua
index 4f3fb1293..7c7df157a 100644
--- a/xmake/toolchains/xcode/load_iphoneos.lua
+++ b/xmake/toolchains/xcode/load_iphoneos.lua
@@ -18,44 +18,8 @@
-- @file load_iphoneos.lua
--
-function main(toolchain)
-
- -- init architecture
- local arch = toolchain:arch()
- local xcode_sdkver = toolchain:config("xcode_sdkver")
- local xcode_sysroot = toolchain:config("xcode_sysroot")
-
- -- is simulator?
- local simulator = toolchain:config("appledev") == "simulator"
-
- -- init target minimal version
- local target_minver = toolchain:config("target_minver")
- if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then
- target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets
- end
- local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver
-
- -- init flags for c/c++
- toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
+import("load_platform")
- -- init flags for objc/c++
- toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
- toolchain:add("mxflags", "-fobjc-arc")
-
- -- init flags for asm
- toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-
- -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
- toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scarflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
-
- toolchain:add("scshflags", "-emit-library")
- toolchain:add("scarflags", "-emit-library", "-static")
- toolchain:add("scldflags", "-emit-executable")
+function main(toolchain)
+ load_platform(toolchain, "ios")
end
-
diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua
index c88680644..24d35c72c 100644
--- a/xmake/toolchains/xcode/load_macosx.lua
+++ b/xmake/toolchains/xcode/load_macosx.lua
@@ -19,69 +19,71 @@
--
function main(toolchain)
+ -- init architecture
+ local arch = toolchain:arch()
+ local xcode_sdkver = toolchain:config('xcode_sdkver')
+ local xcode_sysroot = toolchain:config('xcode_sysroot')
- local arch = toolchain:arch()
- local target_minver = toolchain:config("target_minver")
- local xcode_sysroot = toolchain:config("xcode_sysroot")
+ -- is simulator?
+ local appledev = toolchain:config('appledev')
+ local simulator = appledev == 'simulator'
+ assert(not simulator)
+ local catalyst = appledev == 'catalyst'
- -- init target flags
- local appledev = toolchain:config("appledev")
+ -- init target minimal version
+ local target_minver = toolchain:config('target_minver')
+ local targetflag = format("%s-apple-macos", arch)
if target_minver then
- local target = ("%s-apple-macos%s"):format(arch, target_minver)
- if appledev == "catalyst" then
- target = ("%s-apple-ios%s-macabi"):format(arch, target_minver)
- end
- toolchain:add("cxflags", "-target", target)
- toolchain:add("mxflags", "-target", target)
- toolchain:add("asflags", "-target", target)
- toolchain:add("ldflags", "-target", target)
- toolchain:add("shflags", "-target", target)
- toolchain:add("scflags", "-target", target)
- toolchain:add("scldflags", "-target", target)
- toolchain:add("scshflags", "-target", target)
- toolchain:add("scarflags", "-target", target)
+ targetflag = targetflag .. target_minver
end
-
- -- add sysroot flags
- if xcode_sysroot then
- toolchain:add("cxflags", "-isysroot", xcode_sysroot)
- toolchain:add("asflags", "-isysroot", xcode_sysroot)
- toolchain:add("ldflags", "-isysroot", xcode_sysroot)
- toolchain:add("shflags", "-isysroot", xcode_sysroot)
- toolchain:add("mxflags", "-isysroot", xcode_sysroot)
- toolchain:add("scflags", "-sdk " .. xcode_sysroot)
- toolchain:add("scshflags", "-sdk " .. xcode_sysroot)
- toolchain:add("scarflags", "-sdk " .. xcode_sysroot)
- toolchain:add("scldflags", "-sdk " .. xcode_sysroot)
- if appledev == "catalyst" then
- toolchain:add("cxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
- toolchain:add("asflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
- toolchain:add("mxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
- toolchain:add("ldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
- toolchain:add("shflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
- toolchain:add("scldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
- toolchain:add("scshflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
- toolchain:add("cxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("asflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("ldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("shflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("mxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("scflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("scshflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("scarflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- toolchain:add("scldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
- end
+ if catalyst then
+ targetflag = targetflag .. "-macabi"
end
+ targetflag = {"-target", targetflag}
-- init flags for c/c++
- toolchain:add("ldflags", "-lz")
- toolchain:add("shflags", "-lz")
+ toolchain:add('cxflags', {'-arch', arch}, targetflag, {'-isysroot', xcode_sysroot})
+ toolchain:add('ldflags', {'-arch', arch}, targetflag, {'-isysroot', xcode_sysroot}, '-lz')
+ toolchain:add('shflags', {'-arch', arch}, targetflag, {'-isysroot', xcode_sysroot}, '-lz')
+
+ -- init flags for objc/c++
+ toolchain:add('mxflags', {'-arch', arch}, targetflag, {'-isysroot', xcode_sysroot})
- -- init flags for objc/c++ (with ldflags and shflags)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
- toolchain:add("mxflags", "-fobjc-arc")
+ toolchain:add('mxflags', '-fobjc-arc')
+
+ -- init flags for asm
+ toolchain:add('asflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot)
+
+ -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
+ toolchain:add('scflags', {'-sdk', xcode_sysroot}, targetflag)
+ toolchain:add('scshflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-library")
+ toolchain:add('scarflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-library", "-static")
+ toolchain:add('scldflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-executable")
+
+ if xcode_sysroot and catalyst then
+ toolchain:add("cxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
+ toolchain:add("mxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
- toolchain:add("scshflags", "-emit-library")
- toolchain:add("scarflags", "-emit-library", "-static")
- toolchain:add("scldflags", "-emit-executable")
+ toolchain:add("asflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
+ toolchain:add("ldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
+ toolchain:add("shflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
+
+ toolchain:add("scflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
+ toolchain:add("scldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
+ toolchain:add("scshflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
+ toolchain:add("scarflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
+
+ toolchain:add("cxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("mxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+
+ toolchain:add("asflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("ldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("shflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+
+ toolchain:add("scflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("scshflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("scarflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ toolchain:add("scldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
+ end
end
diff --git a/xmake/toolchains/xcode/load_platform.lua b/xmake/toolchains/xcode/load_platform.lua
new file mode 100644
index 000000000..7d8809acf
--- /dev/null
+++ b/xmake/toolchains/xcode/load_platform.lua
@@ -0,0 +1,60 @@
+--!A cross-toolchain build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file load_platform.lua
+--
+
+function main(toolchain, plat)
+ -- init architecture
+ local arch = toolchain:arch()
+ local xcode_sdkver = toolchain:config('xcode_sdkver')
+ local xcode_sysroot = toolchain:config('xcode_sysroot')
+
+ -- is simulator?
+ local appledev = toolchain:config('appledev')
+ local simulator = appledev == 'simulator'
+
+ -- init target minimal version
+ local target_minver = toolchain:config('target_minver')
+ if target_minver then
+ if plat == "ios" and tonumber(target_minver) > 10 and (arch == 'armv7' or arch == 'armv7s' or arch == 'i386') then
+ target_minver = '10' -- iOS 10 is the maximum deployment target for 32-bit targets
+ end
+ end
+ local targetflag = format("%s-apple-%s%s%s", arch, plat, target_minver or "", simulator and "-simulator" or "")
+ targetflag = {"-target", targetflag}
+
+ -- init flags for c/c++
+ toolchain:add('cxflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot)
+ toolchain:add('ldflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot, '-ObjC', '-fobjc-link-runtime')
+ toolchain:add('shflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot, '-ObjC', '-fobjc-link-runtime')
+
+ -- init flags for objc/c++
+ toolchain:add('mxflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot)
+
+ -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
+ toolchain:add('mxflags', '-fobjc-arc')
+
+ -- init flags for asm
+ toolchain:add('asflags', {'-arch', arch}, targetflag, '-isysroot', xcode_sysroot)
+
+ -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
+ toolchain:add('scflags', {'-sdk', xcode_sysroot}, targetflag)
+ toolchain:add('scshflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-library")
+ toolchain:add('scarflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-library", "-static")
+ toolchain:add('scldflags', {'-sdk', xcode_sysroot}, targetflag, "-emit-executable")
+end
diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua
index 99fc12313..fa3f9f785 100644
--- a/xmake/toolchains/xcode/load_watchos.lua
+++ b/xmake/toolchains/xcode/load_watchos.lua
@@ -18,41 +18,9 @@
-- @file load_watchos.lua
--
-function main(toolchain)
-
- -- init architecture
- local arch = toolchain:arch()
- local xcode_sdkver = toolchain:config("xcode_sdkver")
- local xcode_sysroot = toolchain:config("xcode_sysroot")
-
- -- is simulator?
- local simulator = toolchain:config("appledev") == "simulator"
-
- -- init target minimal version
- local target_minver = toolchain:config("target_minver")
- local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver
-
- -- init flags for c/c++
- toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
- toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot)
+import("load_platform")
- -- init flags for objc/c++
- toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
- -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
- toolchain:add("mxflags", "-fobjc-arc")
-
- -- init flags for asm
- toolchain:add("asflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot)
-
- -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags)
- toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
- toolchain:add("scarflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sysroot)
-
- toolchain:add("scshflags", "-emit-library")
- toolchain:add("scarflags", "-emit-library", "-static")
- toolchain:add("scldflags", "-emit-executable")
+function main(toolchain)
+ load_platform(toolchain, "watchos")
end