summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/toolchains/llvm/check.lua7
-rw-r--r--xmake/toolchains/llvm/xmake.lua27
2 files changed, 33 insertions, 1 deletions
diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua
index 54ec397a5..a398d26df 100644
--- a/xmake/toolchains/llvm/check.lua
+++ b/xmake/toolchains/llvm/check.lua
@@ -58,6 +58,7 @@ function main(toolchain)
-- get sdk directory
local sdkdir = toolchain:sdkdir()
local bindir = toolchain:bindir()
+ local cross = toolchain:cross()
if not sdkdir and not bindir then
bindir = try {function () return os.iorunv("llvm-config", {"--bindir"}) end}
if bindir then
@@ -83,7 +84,7 @@ function main(toolchain)
end
-- find cross toolchain from external envirnoment
- local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir})
+ local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross})
if not cross_toolchain then
-- find it from packages
for _, package in ipairs(toolchain:packages()) do
@@ -105,6 +106,10 @@ function main(toolchain)
raise("llvm toolchain not found!")
end
+ if toolchain:is_plat("cross") and (not toolchain:cross() or toolchain:cross():match("^%s*$")) then
+ raise("Missing cross target. Use `--cross=name` to specify.")
+ end
+
-- attempt to find xcode to pass `-isysroot` on macos
if toolchain:is_plat("macosx") then
_find_xcode(toolchain)
diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua
index 71baf9fe6..226eebeb7 100644
--- a/xmake/toolchains/llvm/xmake.lua
+++ b/xmake/toolchains/llvm/xmake.lua
@@ -62,6 +62,33 @@ toolchain("llvm")
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
+ elseif toolchain:is_plat("cross") then
+ local sysroot
+ local sdkdir = toolchain:sdkdir()
+ local bindir = toolchain:bindir()
+ local cross = toolchain:cross():gsub("(.*)%-$", "%1")
+ march = "--target=" .. cross
+ if bindir and os.isexec(path.join(bindir, cross .. "-gcc" .. (is_host("windows") and ".exe" or ""))) then
+ local gcc_toolchain = path.directory(bindir)
+ toolchain:add("cxflags", "--gcc-toolchain=" .. gcc_toolchain)
+ toolchain:add("mxflags", "--gcc-toolchain=" .. gcc_toolchain)
+ toolchain:add("asflags", "--gcc-toolchain=" .. gcc_toolchain)
+ toolchain:add("ldflags", "--gcc-toolchain=" .. gcc_toolchain)
+ toolchain:add("shflags", "--gcc-toolchain=" .. gcc_toolchain)
+ end
+ if sdkdir and os.isdir(path.join(sdkdir, cross, "include")) then
+ sysroot = path.join(sdkdir, cross)
+ end
+ if sysroot then
+ if os.isdir(path.join(sysroot, "libc")) then
+ sysroot = path.join(sysroot, "libc")
+ end
+ toolchain:add("cxflags", "--sysroot=" .. sysroot)
+ toolchain:add("mxflags", "--sysroot=" .. sysroot)
+ toolchain:add("asflags", "--sysroot=" .. sysroot)
+ toolchain:add("ldflags", "--sysroot=" .. sysroot)
+ toolchain:add("shflags", "--sysroot=" .. sysroot)
+ end
end
if march then
toolchain:add("cxflags", march)