summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-10-07 00:53:57 +0800
committerruki <[email protected]>2020-10-07 00:53:57 +0800
commited9243b5b503c00057b10efb7cf6ee82eb9c35c5 (patch)
tree200070c6ba5b56b06c71bf4f6f47f66a577e1c60
parentacc4c79235d585c6c3f05aaf3d2c6e11adb076ff (diff)
support icl for windows
-rw-r--r--xmake/modules/detect/sdks/find_intel.lua116
-rw-r--r--xmake/modules/detect/tools/find_icl.lua12
-rw-r--r--xmake/toolchains/icc/check.lua28
-rw-r--r--xmake/toolchains/icc/load.lua26
4 files changed, 100 insertions, 82 deletions
diff --git a/xmake/modules/detect/sdks/find_intel.lua b/xmake/modules/detect/sdks/find_intel.lua
index cac5a5ca1..a5ddc95e0 100644
--- a/xmake/modules/detect/sdks/find_intel.lua
+++ b/xmake/modules/detect/sdks/find_intel.lua
@@ -22,52 +22,42 @@
import("lib.detect.find_file")
import("lib.detect.find_tool")
---[[
-- init vc variables
-local vcvars = {"path",
- "lib",
- "libpath",
- "include",
- "DevEnvdir",
- "VSInstallDir",
- "VCInstallDir",
- "WindowsSdkDir",
- "WindowsLibPath",
- "WindowsSDKVersion",
- "WindowsSdkBinPath",
- "UniversalCRTSdkDir",
- "UCRTVersion"}
+local iclvars = {"path",
+ "lib",
+ "libpath",
+ "include",
+ "DevEnvdir",
+ "VSInstallDir",
+ "VCInstallDir",
+ "WindowsSdkDir",
+ "WindowsLibPath",
+ "WindowsSDKVersion",
+ "WindowsSdkBinPath",
+ "UniversalCRTSdkDir",
+ "UCRTVersion"}
--- load iclvars environment variables
-function _load_iclvars(iclvars, vsver, arch, opt)
+-- load iclvars_bat environment variables
+function _load_iclvars(iclvars_bat, arch, opt)
- -- make the genvcvars.bat
+ -- make the geniclvars.bat
opt = opt or {}
- local genvcvars_bat = os.tmpfile() .. "_genvcvars.bat"
- local genvcvars_dat = os.tmpfile() .. "_genvcvars.txt"
- local file = io.open(genvcvars_bat, "w")
+ local geniclvars_bat = os.tmpfile() .. "_geniclvars.bat"
+ local geniclvars_dat = os.tmpfile() .. "_geniclvars.txt"
+ local file = io.open(geniclvars_bat, "w")
file:print("@echo off")
- -- fix error caused by the new vsDevCmd.bat of vs2019
- -- @see https://github.com/xmake-io/xmake/issues/549
- if vsver and tonumber(vsver) >= 16 then
- file:print("set VSCMD_SKIP_SENDTELEMETRY=yes")
- end
- if opt.vcvars_ver then
- file:print("call \"%s\" %s %s -vcvars_ver=%s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver)
- else
- file:print("call \"%s\" %s %s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "")
- end
- for idx, var in ipairs(vcvars) do
- file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", genvcvars_dat)
+ file:print("call \"%s\" -arch %s > nul", iclvars_bat, arch)
+ for idx, var in ipairs(iclvars) do
+ file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", geniclvars_dat)
end
file:close()
- -- run genvcvars.bat
- os.run(genvcvars_bat)
+ -- run geniclvars.bat
+ os.run(geniclvars_bat)
-- load all envirnoment variables
local variables = {}
- for _, line in ipairs((io.readfile(genvcvars_dat) or ""):split("\n")) do
+ for _, line in ipairs((io.readfile(geniclvars_dat) or ""):split("\n")) do
local p = line:find('=', 1, true)
if p then
local name = line:sub(1, p - 1):trim()
@@ -80,41 +70,12 @@ function _load_iclvars(iclvars, vsver, arch, opt)
end
-- remove some empty entries
- for _, name in ipairs(vcvars) do
+ for _, name in ipairs(iclvars) do
if variables[name] and #variables[name]:trim() == 0 then
variables[name] = nil
end
end
- -- fix WindowsSDKVersion
- local WindowsSDKVersion = variables["WindowsSDKVersion"]
- if WindowsSDKVersion then
- WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim()
- if WindowsSDKVersion ~= "" then
- variables["WindowsSDKVersion"] = WindowsSDKVersion
- end
- end
-
- -- fix UCRTVersion
- --
- -- @note iclvars.bat maybe detect error if install WDK and SDK at same time (multi-sdk version exists in include directory).
- --
- local UCRTVersion = variables["UCRTVersion"]
- if UCRTVersion and WindowsSDKVersion and UCRTVersion ~= WindowsSDKVersion and WindowsSDKVersion ~= "" then
- local lib = variables["lib"]
- if lib then
- lib = lib:gsub(UCRTVersion, WindowsSDKVersion)
- variables["lib"] = lib
- end
- local include = variables["include"]
- if include then
- include = include:gsub(UCRTVersion, WindowsSDKVersion)
- variables["include"] = include
- end
- UCRTVersion = WindowsSDKVersion
- variables["UCRTVersion"] = UCRTVersion
- end
-
-- convert path/lib/include to PATH/LIB/INCLUDE
variables.PATH = variables.path
variables.LIB = variables.lib
@@ -124,8 +85,6 @@ function _load_iclvars(iclvars, vsver, arch, opt)
variables.lib = nil
variables.include = nil
variables.libpath = nil
-
- -- ok
return variables
end
@@ -135,18 +94,19 @@ function _find_intel_on_windows(opt)
-- init options
opt = opt or {}
- -- find iclvars.bat, vcvars32.bat for vs7.1
- local iclvars = find_file("iclvars.bat", paths) or find_file("vcvars32.bat", paths)
- if iclvars then
+ -- find iclvars_bat.bat
+ local paths = {"$(env ICPP_COMPILER20)"}
+ local iclvars_bat = find_file("bin/iclvars.bat", paths)
+ if iclvars_bat then
+
+ -- load iclvars_bat
+ local iclvars_x86 = _load_iclvars(iclvars_bat, "ia32", opt)
+ local iclvars_x64 = _load_iclvars(iclvars_bat, "intel64", opt)
- -- load iclvars
- local iclvars_x86 = _load_iclvars(iclvars, version, "x86", opt)
- local iclvars_x64 = _load_iclvars(iclvars, version, "x64", opt)
-]]
- -- save results
- -- results[vsvers[version]] = {version = version, iclvars_bat = iclvars, iclvars = {x86 = iclvars_x86, x64 = iclvars_x64}}
- -- end
---end
+ -- save results
+ return {iclvars_bat = iclvars_bat, iclvars = {x86 = iclvars_x86, x64 = iclvars_x64}}
+ end
+end
-- find intel envirnoment on linux
function _find_intel_on_linux(opt)
diff --git a/xmake/modules/detect/tools/find_icl.lua b/xmake/modules/detect/tools/find_icl.lua
index f61f0ce76..ac0008c0e 100644
--- a/xmake/modules/detect/tools/find_icl.lua
+++ b/xmake/modules/detect/tools/find_icl.lua
@@ -38,15 +38,19 @@ import("lib.detect.find_programver")
function main(opt)
-- init options
- opt = opt or {}
+ opt = opt or {}
+ opt.check = opt.check or function (program) os.runv(program, {"/help"}, {envs = opt.envs}) end
-- find program
- local program = find_program(opt.program or "icl", opt)
+ local program = find_program(opt.program or "icl.exe", opt)
-- find program version
local version = nil
- if program and opt.version then
- version = find_programver(program, opt)
+ if program and opt and opt.version then
+ opt.command = opt.command or function () local _, info = os.iorunv(program, {"/help"}, {envs = opt.envs}); return info end
+ opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end
+ version = find_programver(program, opt)
end
return program, version
end
+
diff --git a/xmake/toolchains/icc/check.lua b/xmake/toolchains/icc/check.lua
index a5254f20f..4cbc9f5d2 100644
--- a/xmake/toolchains/icc/check.lua
+++ b/xmake/toolchains/icc/check.lua
@@ -26,6 +26,34 @@ import("lib.detect.find_tool")
-- check intel on windows
function _check_intel_on_windows(toolchain)
+
+ -- have been checked?
+ if config.get("__iclvarsall") then
+ return true
+ end
+
+ -- find intel
+ local intel = find_intel()
+ if intel and intel.iclvars then
+ local iclvarsall = intel.iclvars
+ local iclenv = iclvarsall[toolchain:arch()]
+ if iclenv and iclenv.PATH and iclenv.INCLUDE and iclenv.LIB then
+
+ -- save iclvars
+ config.set("__iclvarsall", iclvarsall)
+
+ -- check compiler
+ local program = nil
+ local tool = find_tool("icl.exe", {force = true, envs = iclenv, version = true})
+ if tool then
+ program = tool.program
+ end
+ if program then
+ cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
+ return true
+ end
+ end
+ end
end
-- check intel on linux
diff --git a/xmake/toolchains/icc/load.lua b/xmake/toolchains/icc/load.lua
index 1265ac731..c854b7b91 100644
--- a/xmake/toolchains/icc/load.lua
+++ b/xmake/toolchains/icc/load.lua
@@ -22,6 +22,26 @@
import("core.base.option")
import("core.project.config")
+-- add the given icl environment
+function _add_iclenv(toolchain, name)
+
+ -- get iclvarsall
+ local iclvarsall = config.get("__iclvarsall")
+ if not iclvarsall then
+ return
+ end
+
+ -- get icl environment for the current arch
+ local arch = toolchain:arch()
+ local iclenv = iclvarsall[arch] or {}
+
+ -- get the paths for the icl environment
+ local env = iclenv[name]
+ if env then
+ toolchain:add("runenvs", name:upper(), path.splitenv(env))
+ end
+end
+
-- load intel on windows
function _load_intel_on_windows(toolchain)
@@ -49,6 +69,12 @@ function _load_intel_on_windows(toolchain)
toolchain:set("toolset", "strip", "strip")
toolchain:set("toolset", "as", "icc")
end
+
+ -- add icl environments
+ _add_iclenv(toolchain, "PATH")
+ _add_iclenv(toolchain, "LIB")
+ _add_iclenv(toolchain, "INCLUDE")
+ _add_iclenv(toolchain, "LIBPATH")
end
-- load intel on linux