diff options
| author | ruki <[email protected]> | 2020-12-23 23:27:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-23 23:27:38 +0800 |
| commit | a729c747a47e55e06c73291cda53a3c620143213 (patch) | |
| tree | 15ce5ae9cb0fd025bdf238cd0de5fc18912df7cd | |
| parent | 85e912f6d1a58ccd811738efc43fa0ff711def34 (diff) | |
-a
| -rw-r--r-- | xmake/toolchains/llvm/check.lua | 56 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 13 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 4 |
3 files changed, 73 insertions, 0 deletions
diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua index 22a0f3b89..a7543e901 100644 --- a/xmake/toolchains/llvm/check.lua +++ b/xmake/toolchains/llvm/check.lua @@ -20,8 +20,59 @@ -- imports import("core.project.config") +import("detect.sdks.find_xcode") import("detect.sdks.find_cross_toolchain") +-- find xcode on macos +function _find_xcode(toolchain) + + -- find xcode + local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") + local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true, + find_codesign = false, + sdkver = xcode_sdkver, + plat = toolchain:plat(), + arch = toolchain:arch()}) + if not xcode then + cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}") + return + end + + -- xcode found + xcode_sdkver = xcode.sdkver + if toolchain:global() then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir) + end + + -- save target minver + -- + -- @note we need to differentiate the version for the system, + -- because the xcode toolchain of iphoneos/macosx may need to be used at the same time. + -- + -- e.g. + -- + -- target("test") + -- set_toolchains("xcode", {plat = os.host(), arch = os.arch()}) + -- + local target_minver = toolchain:config("target_minver") and config.get("target_minver") + if xcode_sdkver and not target_minver then + target_minver = xcode_sdkver + if toolchain:is_plat("macosx") then + local macos_ver = macos.version() + if macos_ver then + target_minver = macos_ver:major() .. "." .. macos_ver:minor() + end + end + end + toolchain:config_set("xcode", xcode.sdkdir) + toolchain:config_set("xcode_sdkver", xcode_sdkver) + toolchain:config_set("target_minver", target_minver) + toolchain:configs_save() + cprint("checking for SDK version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), xcode_sdkver) + cprint("checking for Minimal target version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), target_minver) +end + -- check the cross toolchain function main(toolchain) @@ -42,5 +93,10 @@ function main(toolchain) else raise("llvm toolchain not found!") end + + -- attempt to find xcode to pass `-isysroot` on macos + if toolchain:is_plat("macosx") then + _find_xcode(toolchain) + end return cross_toolchain end diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index 27257b7e0..6b6598406 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -61,6 +61,19 @@ toolchain("llvm") toolchain:add("shflags", march) end + -- init flags for the xcode sdk directory + if toolchain:is_plat("macosx") then + local xcode_dir = get_config("xcode") + local xcode_sdkver = toolchain:config("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" + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-isysroot " .. xcode_sdkdir) + end + end + -- add bin search library for loading some dependent .dll files windows local bindir = toolchain:bindir() if bindir and is_host("windows") then diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index cea62787d..f87a00c4f 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -39,16 +39,20 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch " .. arch) toolchain:add("ldflags", "-arch " .. arch) + toolchain:add("shflags", "-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) + toolchain:add("shflags", "-mmacosx-version-min=" .. target_minver) end if xcode_sdkdir then toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-isysroot " .. xcode_sdkdir) end toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("shflags", "-stdlib=libc++") toolchain:add("syslinks", "z") -- init flags for objc/c++ (with ldflags and shflags) |
