diff options
| author | Arthur LAURENT <[email protected]> | 2025-11-01 19:03:10 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-11-01 21:23:17 +0100 |
| commit | 6bb310b029f7adb13709d73655b635649b7c5814 (patch) | |
| tree | 9ba139d9a76a173ae299fff595f49205eacdd8c9 /xmake/toolchains/xcode | |
| parent | b3a2dba93a185f205dbd18a154e42da72fdd4881 (diff) | |
nfc(xcode) refactor xcode toolchain and improve it
Diffstat (limited to 'xmake/toolchains/xcode')
| -rw-r--r-- | xmake/toolchains/xcode/load_appletvos.lua | 38 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_applexros.lua | 42 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 42 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 112 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_platform.lua | 60 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 38 |
6 files changed, 129 insertions, 203 deletions
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 |
