summaryrefslogtreecommitdiff
path: root/xmake/toolchains/xcode
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-24 21:10:49 +0800
committerGitHub <[email protected]>2020-05-24 21:10:49 +0800
commitfb2ba113ca1534249b0872002af0f133becd7e51 (patch)
treed5bc9fb1553f622842712b18a7959a0c08a92d63 /xmake/toolchains/xcode
parentdd09a2264181f82a0b6aefb38dce5c92fb3af8fe (diff)
parent5ad2eaee8cd65987359dbdfc5149bdd61b9260fc (diff)
Merge pull request #792 from xmake-io/toolchain
Improve to detect cross-compilation toolchains
Diffstat (limited to 'xmake/toolchains/xcode')
-rw-r--r--xmake/toolchains/xcode/check.lua51
-rw-r--r--xmake/toolchains/xcode/load_iphoneos.lua62
-rw-r--r--xmake/toolchains/xcode/load_macosx.lua78
-rw-r--r--xmake/toolchains/xcode/load_watchos.lua59
-rw-r--r--xmake/toolchains/xcode/xmake.lua76
5 files changed, 326 insertions, 0 deletions
diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua
new file mode 100644
index 000000000..925db3870
--- /dev/null
+++ b/xmake/toolchains/xcode/check.lua
@@ -0,0 +1,51 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.config")
+import("detect.sdks.find_xcode")
+
+-- main entry
+function main(toolchain)
+
+ -- find xcode
+ local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")})
+ if xcode then
+ config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
+ else
+ return false
+ end
+
+ -- save target minver
+ local xcode_sdkver = config.get("xcode_sdkver")
+ local target_minver = config.get("target_minver")
+ if xcode_sdkver and not target_minver then
+ target_minver = xcode_sdkver
+ if is_plat("macosx") then
+ local macos_ver = macos.version()
+ if macos_ver then
+ target_minver = macos_ver:major() .. "." .. macos_ver:minor()
+ end
+ end
+ config.set("target_minver", target_minver)
+ end
+ return true
+end
diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua
new file mode 100644
index 000000000..3aeb78672
--- /dev/null
+++ b/xmake/toolchains/xcode/load_iphoneos.lua
@@ -0,0 +1,62 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file load_iphoneos.lua
+--
+
+-- imports
+import("core.project.config")
+
+-- main entry
+function main(toolchain)
+
+ -- init architecture
+ local arch = config.get("arch") or "arm64"
+ local simulator = (arch == "i386" or arch == "x86_64")
+
+ -- init platform name
+ local platname = simulator and "iPhoneSimulator" or "iPhoneOS"
+
+ -- init target minimal version
+ local target_minver = config.get("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 the xcode sdk directory
+ local xcode_dir = config.get("xcode")
+ local xcode_sdkver = config.get("xcode_sdkver")
+ 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++
+ 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++
+ toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir)
+
+ -- init flags for asm
+ toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. 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_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua
new file mode 100644
index 000000000..5cebd96bb
--- /dev/null
+++ b/xmake/toolchains/xcode/load_macosx.lua
@@ -0,0 +1,78 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file load_macosx.lua
+--
+
+-- imports
+import("core.project.config")
+
+-- main entry
+function main(toolchain)
+
+ -- 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++
+ toolchain:add("cxflags", "-arch " .. arch)
+ toolchain:add("ldflags", "-arch " .. arch)
+ if target_minver then
+ toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver)
+ toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver)
+ toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver)
+ end
+ if xcode_sdkdir then
+ toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir)
+ toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir)
+ else
+ toolchain:add("cxflags", "-I/usr/local/include")
+ toolchain:add("cxflags", "-I/usr/include")
+ toolchain:add("ldflags", "-L/usr/local/lib")
+ toolchain:add("ldflags", "-L/usr/lib")
+ end
+ toolchain:add("ldflags", "-stdlib=libc++")
+ toolchain:add("ldflags", "-lz")
+ toolchain:add("shflags", toolchain:get("ldflags"))
+
+ -- init flags for objc/c++ (with ldflags and shflags)
+ toolchain:add("mxflags", "-arch " .. arch)
+ if xcode_sdkdir then
+ toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir)
+ end
+
+ -- init flags for asm
+ toolchain:add("asflags", "-arch " .. arch)
+ if xcode_sdkdir then
+ toolchain:add("asflags", "-isysroot " .. xcode_sdkdir)
+ end
+
+ -- init flags for swift
+ if target_minver and xcode_sdkdir then
+ toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir)
+ toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir)
+ toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir)
+ end
+end
diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua
new file mode 100644
index 000000000..5048f4bb7
--- /dev/null
+++ b/xmake/toolchains/xcode/load_watchos.lua
@@ -0,0 +1,59 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file load_watchos.lua
+--
+
+-- imports
+import("core.project.config")
+
+-- main entry
+function main(toolchain)
+
+ -- init architecture
+ local arch = config.get("arch")
+ local simulator = arch == "i386"
+
+ -- init platform name
+ local platname = simulator and "WatchSimulator" or "WatchOS"
+
+ -- init target minimal version
+ local target_minver = config.get("target_minver")
+ local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver
+
+ -- init the xcode sdk directory
+ local xcode_dir = config.get("xcode")
+ local xcode_sdkver = config.get("xcode_sdkver")
+ 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++
+ 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++
+ toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir)
+
+ -- init flags for asm
+ toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. 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/xmake.lua b/xmake/toolchains/xcode/xmake.lua
new file mode 100644
index 000000000..74462908c
--- /dev/null
+++ b/xmake/toolchains/xcode/xmake.lua
@@ -0,0 +1,76 @@
+--!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 xmake.lua
+--
+
+-- define toolchain
+toolchain("xcode")
+
+ -- mark as standalone toolchain
+ set_kind("standalone")
+
+ -- check toolchain
+ on_check("check")
+
+ -- load toolchain
+ on_load(function (toolchain)
+
+ -- get cross
+ local cross, arch, simulator
+ if is_plat("macosx") then
+ cross = "xcrun -sdk macosx "
+ elseif is_plat("iphoneos") then
+ arch = get_config("arch") or os.arch()
+ simulator = (arch == "i386" or arch == "x86_64")
+ cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos "
+ elseif is_plat("watchos") then
+ arch = get_config("arch") or os.arch()
+ simulator = (arch == "i386")
+ cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos "
+ 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", "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")
+ if arch then
+ toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E")
+ end
+ if is_plat("macosx") then
+ toolchain:set("toolsets", "as", cross .. "clang")
+ elseif simulator then
+ toolchain:set("toolsets", "as", cross .. "clang")
+ else
+ toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang")
+ end
+
+ -- load configurations
+ import("load_" .. get_config("plat"))(toolchain)
+ end)