summaryrefslogtreecommitdiff
path: root/xmake/modules/detect
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-17 10:59:28 +0800
committerGitHub <[email protected]>2020-12-17 10:59:28 +0800
commite95f99d7d99daf3c065dd04d457b2a8a81545380 (patch)
tree72816b1c749dd12e31da06b9b9d97ffc8d057866 /xmake/modules/detect
parent37521d4aa857d57773b0f6cb9311856d3787c6f5 (diff)
parent98a044d2947d070d035fe76c651fdbf9f0c3b135 (diff)
Merge pull request #1141 from xmake-io/toolchain
Improve toolchain
Diffstat (limited to 'xmake/modules/detect')
-rw-r--r--xmake/modules/detect/sdks/find_dotnet.lua17
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua22
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua120
-rw-r--r--xmake/modules/detect/tools/find_devenv.lua12
-rw-r--r--xmake/modules/detect/tools/find_lib.lua4
-rw-r--r--xmake/modules/detect/tools/find_rc.lua16
6 files changed, 75 insertions, 116 deletions
diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua
index bb8180f57..284925f04 100644
--- a/xmake/modules/detect/sdks/find_dotnet.lua
+++ b/xmake/modules/detect/sdks/find_dotnet.lua
@@ -21,6 +21,7 @@
-- imports
import("lib.detect.cache")
import("lib.detect.find_file")
+import("core.tool.toolchain")
import("core.base.option")
import("core.base.global")
import("core.project.config")
@@ -28,14 +29,16 @@ import("core.project.config")
-- find dotnet directory
function _find_sdkdir(sdkdir)
- -- get sdk directory from vsvars
+ -- get sdk directory from vcvars
if not sdkdir then
- local arch = config.arch()
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir
- if sdkdir then
- sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK")
+ local msvc = toolchain.load("msvc")
+ if msvc and msvc:check() then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ sdkdir = vcvars.WindowsSdkDir
+ if sdkdir then
+ sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK")
+ end
end
end
end
diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua
index f91e9a1b7..d9844146a 100644
--- a/xmake/modules/detect/sdks/find_wdk.lua
+++ b/xmake/modules/detect/sdks/find_wdk.lua
@@ -24,6 +24,7 @@ import("lib.detect.find_file")
import("core.base.option")
import("core.base.global")
import("core.project.config")
+import("core.tool.toolchain")
import("detect.sdks.find_vstudio")
-- find WDK directory
@@ -34,24 +35,15 @@ function _find_sdkdir(sdkdir)
sdkdir = os.getenv("WindowsSdkDir")
end
- -- get sdk directory from vsvars
+ -- get sdk directory from vcvars
if not sdkdir then
- local arch = config.arch() or os.arch()
- local vcvarsall = config.get("__vcvarsall")
- if not vcvarsall then
- local vstudio = find_vstudio()
- if vstudio then
- for _, vsinfo in pairs(vstudio) do
- if vsinfo.vcvarsall then
- vcvarsall = vsinfo.vcvarsall
- break
- end
- end
+ local msvc = toolchain.load("msvc")
+ if msvc and msvc:check() then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ sdkdir = vcvars.WindowsSdkDir
end
end
- if vcvarsall then
- sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir
- end
end
return sdkdir
end
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua
index 1177685a5..4e7a1f677 100644
--- a/xmake/modules/detect/sdks/find_xcode.lua
+++ b/xmake/modules/detect/sdks/find_xcode.lua
@@ -27,7 +27,7 @@ import("lib.detect.find_directory")
import("private.tools.codesign")
-- find xcode directory
-function _find_sdkdir(sdkdir)
+function _find_sdkdir(sdkdir, opt)
if sdkdir and os.isdir(sdkdir) then
return sdkdir
end
@@ -35,9 +35,11 @@ function _find_sdkdir(sdkdir)
end
-- find the sdk version of xcode
-function _find_xcode_sdkver(sdkdir, plat, arch)
+function _find_xcode_sdkver(sdkdir, opt)
-- select platform sdkdir
+ local plat = opt.plat
+ local arch = opt.arch
local platsdkdir = nil
if plat == "iphoneos" then
if arch == "i386" or arch == "x86_64" then
@@ -65,52 +67,56 @@ function _find_xcode_sdkver(sdkdir, plat, arch)
end
-- find the xcode toolchain
-function _find_xcode(sdkdir, xcode_sdkver, plat, arch)
+function _find_xcode(sdkdir, opt)
-- find xcode root directory
- sdkdir = _find_sdkdir(sdkdir)
+ sdkdir = _find_sdkdir(sdkdir, opt)
if not sdkdir then
return {}
end
-- find the sdk version
- local sdkver = xcode_sdkver or _find_xcode_sdkver(sdkdir, plat, arch)
+ local sdkver = opt.sdkver or _find_xcode_sdkver(sdkdir, opt)
if not sdkver then
return {}
end
- -- find codesign identity
- local codesign_identity = config.get("xcode_codesign_identity")
- if codesign_identity == nil then -- we will disable codesign_identity if be false
- codesign_identity = global.get("xcode_codesign_identity")
- end
- if codesign_identity == nil then
- local codesign_identities = codesign.codesign_identities()
- if codesign_identities then
- for identity, _ in pairs(codesign_identities) do
- codesign_identity = identity
- break
+ -- find codesign
+ if opt.find_codesign then
+
+ -- find codesign identity
+ local codesign_identity = config.get("xcode_codesign_identity")
+ if codesign_identity == nil then -- we will disable codesign_identity if be false
+ codesign_identity = global.get("xcode_codesign_identity")
+ end
+ if codesign_identity == nil then
+ local codesign_identities = codesign.codesign_identities()
+ if codesign_identities then
+ for identity, _ in pairs(codesign_identities) do
+ codesign_identity = identity
+ break
+ end
end
end
- end
- -- find mobile provision only for iphoneos
- local mobile_provision
- if is_plat("iphoneos") then
- local mobile_provisions = codesign.mobile_provisions()
- if mobile_provisions then
- mobile_provision = config.get("xcode_mobile_provision")
- if mobile_provision == nil then -- we will disable mobile_provision if be false
- mobile_provision = global.get("xcode_mobile_provision")
- end
- if mobile_provision == nil then
- for provision, _ in pairs(mobile_provisions) do
- mobile_provision = provision
- break
+ -- find mobile provision only for iphoneos
+ local mobile_provision
+ if opt.plat == "iphoneos" then
+ local mobile_provisions = codesign.mobile_provisions()
+ if mobile_provisions then
+ mobile_provision = config.get("xcode_mobile_provision")
+ if mobile_provision == nil then -- we will disable mobile_provision if be false
+ mobile_provision = global.get("xcode_mobile_provision")
+ end
+ if mobile_provision == nil then
+ for provision, _ in pairs(mobile_provisions) do
+ mobile_provision = provision
+ break
+ end
+ -- valid mobile provision not found? reset it
+ elseif not mobile_provisions[mobile_provision] then
+ mobile_provision = nil
end
- -- valid mobile provision not found? reset it
- elseif not mobile_provisions[mobile_provision] then
- mobile_provision = nil
end
end
end
@@ -121,7 +127,7 @@ end
--
-- @param sdkdir the xcode directory
-- @param opt the argument options
--- e.g. {verbose = true, force = false, sdkver = 19, toolchains_ver = "4.9"}
+-- e.g. {verbose = true, force = false, sdkver = 19, find_codesign = true}
--
-- @return the xcode toolchain. e.g. {bindir = .., cross = ..}
--
@@ -144,54 +150,14 @@ function main(sdkdir, opt)
end
-- get plat and arch
- local plat = opt.plat or config.get("plat") or "macosx"
- local arch = opt.arch or config.get("arch") or "x86_64"
-
- -- get xcode sdk version
- local xcode_sdkver = (plat == config.plat()) and config.get("xcode_sdkver")
- if not xcode_sdkver then
- xcode_sdkver = config.get("xcode_sdkver_" .. plat)
- end
+ local plat = opt.plat or config.get("plat") or os.host()
+ local arch = opt.arch or config.get("arch") or os.arch()
-- find xcode
- local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or xcode_sdkver, plat, arch)
- if xcode and xcode.sdkdir then
-
- -- save to config
- config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
- config.set("xcode_sdkver_" .. plat, xcode.sdkver, {force = true, readonly = true})
- config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true})
- config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true})
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir)
- cprint("checking for SDK version of Xcode ... ${color.success}%s", xcode.sdkver)
- if xcode.codesign_identity then
- cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity)
- else
- cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}")
- end
- if plat == "iphoneos" then
- if xcode.mobile_provision then
- cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision)
- else
- cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}")
- end
- end
- end
- else
-
- -- trace
- if opt.verbose or option.get("verbose") then
- cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
- end
- end
+ local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt)
-- save to cache
cacheinfo.xcode = xcode or false
cache.save(key, cacheinfo)
-
- -- ok?
return xcode
end
diff --git a/xmake/modules/detect/tools/find_devenv.lua b/xmake/modules/detect/tools/find_devenv.lua
index 745c26099..1111c92a3 100644
--- a/xmake/modules/detect/tools/find_devenv.lua
+++ b/xmake/modules/detect/tools/find_devenv.lua
@@ -20,6 +20,7 @@
-- imports
import("core.project.config")
+import("core.tool.toolchain")
-- find devenv
--
@@ -48,11 +49,12 @@ function main(opt)
-- e.g. C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
--
local program = nil
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- for _, vsvars in pairs(vcvarsall) do
- if vsvars.DevEnvdir and os.isexec(path.join(vsvars.DevEnvdir, "devenv.exe")) then
- program = path.join(vsvars.DevEnvdir, "devenv.exe")
+ local msvc = toolchain.load("msvc")
+ if msvc then
+ local vcvars = msvc:config("vcvars")
+ if vcvars then
+ if vcvars.DevEnvdir and os.isexec(path.join(vcvars.DevEnvdir, "devenv.exe")) then
+ program = path.join(vcvars.DevEnvdir, "devenv.exe")
end
end
end
diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua
index f3c5806ee..b01960e25 100644
--- a/xmake/modules/detect/tools/find_lib.lua
+++ b/xmake/modules/detect/tools/find_lib.lua
@@ -51,8 +51,8 @@ function main(opt)
io.writefile(sourcefile, "int test(void)\n{return 0;}")
-- check it
- local cl = assert(find_tool("cl"))
- local link = assert(find_tool("link"))
+ local cl = assert(find_tool("cl", {envs = opt.envs}))
+ local link = assert(find_tool("link", {envs = opt.envs}))
os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs})
os.runv(link.program, {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs})
verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs})
diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua
index 5edd8d69c..a36cd25bb 100644
--- a/xmake/modules/detect/tools/find_rc.lua
+++ b/xmake/modules/detect/tools/find_rc.lua
@@ -57,16 +57,12 @@ function main(opt)
--
-- e.g. C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64
--
- local arch = opt.arch or config.arch() or os.arch()
- local vcvarsall = config.get("__vcvarsall")
- if vcvarsall then
- local vcvars = vcvarsall[arch]
- if vcvars and vcvars.WindowsSdkDir and vcvars.WindowsSDKVersion then
- local bindir = path.join(vcvars.WindowsSdkDir, "bin", vcvars.WindowsSDKVersion, arch)
- if os.isdir(bindir) then
- opt.paths = opt.paths or {}
- table.insert(opt.paths, bindir)
- end
+ local envs = opt.envs
+ if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion then
+ local bindir = path.join(envs.WindowsSdkDir, "bin", envs.WindowsSDKVersion, arch)
+ if os.isdir(bindir) then
+ opt.paths = opt.paths or {}
+ table.insert(opt.paths, bindir)
end
end