diff options
| author | ruki <[email protected]> | 2026-02-11 00:50:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-11 00:50:01 +0800 |
| commit | cc60f116f272ac596b1ab1f779e02aecc719e8eb (patch) | |
| tree | c9256f8c5b4bca511f9390471daeda2b731c01fe /xmake/toolchains/xcode | |
| parent | b1151620cca00ebf4f011ae5e3656359cba80f0c (diff) | |
improve xcode toolchain
Diffstat (limited to 'xmake/toolchains/xcode')
| -rw-r--r-- | xmake/toolchains/xcode/load.lua | 140 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_appletvos.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_applexros.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 80 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_platform.lua | 49 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/xmake.lua | 42 |
8 files changed, 141 insertions, 270 deletions
diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua new file mode 100644 index 000000000..1841d8117 --- /dev/null +++ b/xmake/toolchains/xcode/load.lua @@ -0,0 +1,140 @@ +--!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.lua +-- +-- imports +import("private.utils.toolchain", {alias = "toolchain_utils"}) + +-- set toolset programs from xcode toolchain bindir/arch/appledev +function _set_toolset(toolchain, bindir, arch, appledev) + + local xc_clang = bindir and path.join(bindir, "clang") or "clang" + local xc_clangxx = bindir and path.join(bindir, "clang++") or "clang++" + local xc_ar = bindir and path.join(bindir, "ar") or "ar" + local xc_strip = bindir and path.join(bindir, "strip") or "strip" + local xc_swift_frontend = bindir and path.join(bindir, "swift-frontend") or "swift-frontend" + local xc_swiftc = bindir and path.join(bindir, "swiftc") or "swiftc" + local xc_dsymutil = bindir and path.join(bindir, "dsymutil") or "dsymutil" + + toolchain:set("toolset", "cc", xc_clang) + toolchain:set("toolset", "cxx", xc_clangxx, xc_clang) + toolchain:set("toolset", "ld", xc_clangxx, xc_clang) + toolchain:set("toolset", "sh", xc_clangxx, xc_clang) + toolchain:set("toolset", "ar", xc_ar) + toolchain:set("toolset", "strip", xc_strip) + toolchain:set("toolset", "dsymutil", xc_dsymutil, "dsymutil") + toolchain:set("toolset", "mm", xc_clang) + toolchain:set("toolset", "mxx", xc_clangxx, xc_clang) + toolchain:set("toolset", "sc", xc_swift_frontend, "swift_frontend", xc_swiftc, "swiftc") + toolchain:set("toolset", "scld", xc_swiftc, "swiftc") + toolchain:set("toolset", "scsh", xc_swiftc, "swiftc") + toolchain:set("toolset", "scar", xc_swiftc, "swiftc") + if arch then + toolchain:set("toolset", "cpp", xc_clang .. " -arch " .. arch .. " -E") + end + if toolchain:is_plat("macosx") then + toolchain:set("toolset", "as", xc_clang) + elseif appledev == "simulator" or appledev == "catalyst" then + toolchain:set("toolset", "as", xc_clang) + else + toolchain:set("toolset", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. xc_clang)) + end +end + +-- add platform-independent flags for xcode toolchain +function _add_common_flags(toolchain, xcode_sysroot) + + -- init target triple flags + local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)} + + -- init flags for c/c++ + toolchain:add("cxflags", targetflag, "-isysroot", xcode_sysroot) + if toolchain:is_plat("macosx") then + toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-lz") + toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-lz") + else + toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") + toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") + end + + -- init flags for objc/c++ + toolchain:add("mxflags", 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", targetflag, "-isysroot", xcode_sysroot) + + -- init flags for swift + 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 + +-- add extra headers/libs/frameworks for catalyst (macosx + appledev=catalyst) +function _add_catalyst_support(toolchain, xcode_sysroot) + + 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("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 + +-- main entry +function main(toolchain) + + local bindir = toolchain:bindir() + local arch = toolchain:arch() + local appledev = toolchain:config("appledev") + local xcode_sysroot = toolchain:config("xcode_sysroot") + if toolchain:is_plat("macosx") then + assert(appledev ~= "simulator") + end + + -- init toolset + _set_toolset(toolchain, bindir, arch, appledev) + + -- init flags + _add_common_flags(toolchain, xcode_sysroot) + + -- init extra flags for catalyst + if toolchain:is_plat("macosx") and xcode_sysroot and appledev == "catalyst" then + _add_catalyst_support(toolchain, xcode_sysroot) + end +end diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua deleted file mode 100644 index af1745bb7..000000000 --- a/xmake/toolchains/xcode/load_appletvos.lua +++ /dev/null @@ -1,25 +0,0 @@ ---!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_appletvos.lua --- - -import("load_platform") - -function main(toolchain) - load_platform(toolchain) -end diff --git a/xmake/toolchains/xcode/load_applexros.lua b/xmake/toolchains/xcode/load_applexros.lua deleted file mode 100644 index 98779a970..000000000 --- a/xmake/toolchains/xcode/load_applexros.lua +++ /dev/null @@ -1,25 +0,0 @@ ---!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_applexros.lua --- - -import("load_platform") - -function main(toolchain) - load_platform(toolchain) -end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua deleted file mode 100644 index 09e3c5b51..000000000 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ /dev/null @@ -1,25 +0,0 @@ ---!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_iphoneos.lua --- - -import("load_platform") - -function main(toolchain) - load_platform(toolchain) -end diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua deleted file mode 100644 index ee0c8d17d..000000000 --- a/xmake/toolchains/xcode/load_macosx.lua +++ /dev/null @@ -1,80 +0,0 @@ ---!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_macosx.lua --- --- imports -import("private.utils.toolchain", {alias = "toolchain_utils"}) - --- main entry -function main(toolchain) - - -- is simulator? - local appledev = toolchain:config("appledev") - assert(appledev ~= "simulator") - local catalyst = appledev == "catalyst" - - -- init target triple flags - local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)} - - -- init flags for c/c++ - local xcode_sysroot = toolchain:config("xcode_sysroot") - toolchain:add("cxflags", targetflag, {"-isysroot", xcode_sysroot}) - toolchain:add("ldflags", targetflag, {"-isysroot", xcode_sysroot}, "-lz") - toolchain:add("shflags", targetflag, {"-isysroot", xcode_sysroot}, "-lz") - - -- init flags for objc/c++ - toolchain:add("mxflags", 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", 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("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 deleted file mode 100644 index 60dfd6d86..000000000 --- a/xmake/toolchains/xcode/load_platform.lua +++ /dev/null @@ -1,49 +0,0 @@ ---!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 --- --- imports -import("private.utils.toolchain", {alias = "toolchain_utils"}) - --- main entry -function main(toolchain) - - -- init target triple flags - local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)} - - -- init flags for c/c++ - local xcode_sysroot = toolchain:config("xcode_sysroot") - toolchain:add("cxflags", targetflag, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") - toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") - - -- init flags for objc/c++ - toolchain:add("mxflags", 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", 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 deleted file mode 100644 index 39d071dfd..000000000 --- a/xmake/toolchains/xcode/load_watchos.lua +++ /dev/null @@ -1,25 +0,0 @@ ---!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_watchos.lua --- - -import("load_platform") - -function main(toolchain) - load_platform(toolchain) -end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 482fbaf7e..59ddb045d 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -25,44 +25,4 @@ toolchain("xcode") set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") on_check("check") - on_load(function (toolchain) - - -- set toolset - local arch = toolchain:arch() - local bindir = toolchain:bindir() - local appledev = toolchain:config("appledev") - local xc_clang = bindir and path.join(bindir, "clang") or "clang" - local xc_clangxx = bindir and path.join(bindir, "clang++") or "clang++" - local xc_ar = bindir and path.join(bindir, "ar") or "ar" - local xc_strip = bindir and path.join(bindir, "strip") or "strip" - local xc_swift_frontend = bindir and path.join(bindir, "swift-frontend") or "swift-frontend" - local xc_swiftc = bindir and path.join(bindir, "swiftc") or "swiftc" - local xc_dsymutil = bindir and path.join(bindir, "dsymutil") or "dsymutil" - - toolchain:set("toolset", "cc", xc_clang) - toolchain:set("toolset", "cxx", xc_clangxx, xc_clang) - toolchain:set("toolset", "ld", xc_clangxx, xc_clang) - toolchain:set("toolset", "sh", xc_clangxx, xc_clang) - toolchain:set("toolset", "ar", xc_ar) - toolchain:set("toolset", "strip", xc_strip) - toolchain:set("toolset", "dsymutil", xc_dsymutil, "dsymutil") - toolchain:set("toolset", "mm", xc_clang) - toolchain:set("toolset", "mxx", xc_clangxx, xc_clang) - toolchain:set("toolset", "sc", xc_swift_frontend, "swift_frontend", xc_swiftc, "swiftc") - toolchain:set("toolset", "scld", xc_swiftc, "swiftc") - toolchain:set("toolset", "scsh", xc_swiftc, "swiftc") - toolchain:set("toolset", "scar", xc_swiftc, "swiftc") - if arch then - toolchain:set("toolset", "cpp", xc_clang .. " -arch " .. arch .. " -E") - end - if toolchain:is_plat("macosx") then - toolchain:set("toolset", "as", xc_clang) - elseif appledev == "simulator" or appledev == "catalyst" then - toolchain:set("toolset", "as", xc_clang) - else - toolchain:set("toolset", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. xc_clang)) - end - - -- load configurations - import("load_" .. toolchain:plat())(toolchain) - end) + on_load("load") |
