diff options
| author | ruki <[email protected]> | 2020-05-18 22:56:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-18 11:40:14 +0800 |
| commit | 9aaf4d1f861acb3167ce101ddbf12a5f57b0392a (patch) | |
| tree | 8a9a9b27081a0cff3d1b2de91014431fa2981d7f | |
| parent | 3537041f82f3c12f6c9312b3325550d1f18eb94e (diff) | |
support iphoneos for xcode toolchain
| -rw-r--r-- | xmake/platforms/iphoneos/check.lua | 27 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/macosx/check.lua | 21 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 94 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua (renamed from xmake/platforms/iphoneos/load.lua) | 26 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua (renamed from xmake/toolchains/xcode/load.lua) | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/xmake.lua | 50 |
8 files changed, 66 insertions, 161 deletions
diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index 94a3a9ae9..1a7fbd4e3 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -20,9 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") + +--[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -105,24 +107,21 @@ function _toolchains() sc_sh:add({name = "swiftc", cross = cross}) return toolchains -end +end]] -- check it function main(platform, name) - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, "arm64") - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 6d2af82ae..ff5ba2204 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,8 +36,8 @@ platform("iphoneos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 2158dc25a..1166c3205 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -20,11 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") --[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -148,6 +148,9 @@ end]] -- check it function main(platform) + -- check arch + check_arch(config) + -- check toolchains local toolchains = platform:toolchains() for idx, toolchain in irpairs(toolchains) do @@ -156,21 +159,5 @@ function main(platform) end end assert(#toolchains > 0, "toolchains not found!") - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua deleted file mode 100644 index 6d2547a75..000000000 --- a/xmake/platforms/macosx/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!A cross-platform 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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch) - platform:add("ldflags", "-arch " .. arch) - if target_minver then - platform:add("cxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("mxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - platform:add("cxflags", "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - platform:add("cxflags", "-I/usr/local/include") - platform:add("cxflags", "-I/usr/include") - platform:add("ldflags", "-L/usr/local/lib") - platform:add("ldflags", "-L/usr/lib") - end - platform:add("ldflags", "-stdlib=libc++") - platform:add("ldflags", "-lz") - platform:add("shflags", platform:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm - platform:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") - platform:set("fasm.asflags", "") - platform:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 512499c7c..9fd14a82f 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -39,9 +39,6 @@ platform("macosx") -- on check on_check("check") - -- on load - on_load("load") - -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") set_toolchains("xcode") diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 7d54e24be..3aeb78672 100644 --- a/xmake/platforms/iphoneos/load.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -1,4 +1,4 @@ ---!A cross-platform build utility based on Lua +--!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. @@ -15,14 +15,14 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file load_iphoneos.lua -- -- imports import("core.project.config") --- load it -function main(platform) +-- main entry +function main(toolchain) -- init architecture local arch = config.get("arch") or "arm64" @@ -44,19 +44,19 @@ function main(platform) local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + -- 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_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load_macosx.lua index 4d4165a7e..b735b8d77 100644 --- a/xmake/toolchains/xcode/load.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -15,7 +15,7 @@ -- Copyright (C) 2015-2020, TBOOX Open Source Group. -- -- @author ruki --- @file load.lua +-- @file load_macosx.lua -- -- imports diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index d9b1d9944..4f45f6d60 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,24 +21,40 @@ -- define toolchain toolchain("xcode") - -- set toolsets - set_toolsets("cc", "xcrun -sdk macosx clang") - set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("as", "xcrun -sdk macosx clang") - set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("ar", "xcrun -sdk macosx ar") - set_toolsets("ex", "xcrun -sdk macosx ar") - set_toolsets("strip", "xcrun -sdk macosx strip") - set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") - set_toolsets("mm", "xcrun -sdk macosx clang") - set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") - -- check toolchain on_check("check") -- load toolchain - on_load("load") + on_load(function (toolchain) + + -- get cross + local cross + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "as", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) |
