diff options
| author | ruki <[email protected]> | 2021-12-08 23:10:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-08 23:10:12 +0800 |
| commit | 74e0376c16f033d1a72a280808f83c9e4aeb4874 (patch) | |
| tree | e33c262dd8022fd7010ffc16b388e929d4c0015b | |
| parent | 42c73afaf38ab2645944c8bccd4e24aedba62d7e (diff) | |
improve icc toolchain
| -rw-r--r-- | xmake/modules/detect/sdks/find_iccenv.lua | 21 | ||||
| -rw-r--r-- | xmake/toolchains/icc/check.lua | 32 | ||||
| -rw-r--r-- | xmake/toolchains/icc/load.lua | 9 | ||||
| -rw-r--r-- | xmake/toolchains/ifort/load.lua | 1 |
4 files changed, 51 insertions, 12 deletions
diff --git a/xmake/modules/detect/sdks/find_iccenv.lua b/xmake/modules/detect/sdks/find_iccenv.lua index 0e432a99c..2eb2c353c 100644 --- a/xmake/modules/detect/sdks/find_iccenv.lua +++ b/xmake/modules/detect/sdks/find_iccenv.lua @@ -102,6 +102,11 @@ function _find_intel_on_windows(opt) -- find iclvars_bat.bat local paths = {"$(env ICPP_COMPILER20)"} local iclvars_bat = find_file("bin/iclvars.bat", paths) + -- look for setvars.bat which is new in 2021 + if not iclvars_bat then + paths = {"$(env ICPP_COMPILER21)"} + iclvars_bat = find_file("../../../setvars.bat", paths) + end if iclvars_bat then -- load iclvars_bat @@ -123,6 +128,22 @@ function _find_intel_on_linux(opt) local sdkdir = path.directory(path.directory(icc)) return {sdkdir = sdkdir, bindir = path.directory(icc), path.join(sdkdir, "include"), libdir = path.join(sdkdir, "lib")} end + + -- find it from oneapi sdk directory + local oneapi_rootdirs = {"~/intel/oneapi/compiler", "/opt/intel/oneapi/compiler"} + local arch = os.arch() == "x86_64" and "intel64" or "ia32" + paths = {} + for _, rootdir in ipairs(oneapi_rootdirs) do + table.insert(paths, path.join(rootdir, "*", is_host("macosx") and "mac" or "linux", "bin", arch)) + end + if #paths > 0 then + local icc = find_file("icc", paths) + if icc then + local bindir = path.directory(icc) + local sdkdir = path.directory(bindir) + return {sdkdir = sdkdir, bindir = bindir, libdir = path.join(sdkdir, "compiler", "lib", arch)} + end + end end -- find intel c/c++ environment diff --git a/xmake/toolchains/icc/check.lua b/xmake/toolchains/icc/check.lua index 3b9c7b953..9dde538f0 100644 --- a/xmake/toolchains/icc/check.lua +++ b/xmake/toolchains/icc/check.lua @@ -28,7 +28,8 @@ import("lib.detect.find_tool") function _check_intel_on_windows(toolchain) -- have been checked? - if config.get("__iclvarsall") then + local varsall = toolchain:config("varsall") + if varsall then return true end @@ -38,18 +39,11 @@ function _check_intel_on_windows(toolchain) local iclvarsall = iccenv.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()) + toolchain:config_set("varsall", iclvarsall) + toolchain:configs_save() return true end end @@ -58,7 +52,23 @@ end -- check intel on linux function _check_intel_on_linux(toolchain) - return find_tool("icc") + local iccenv = toolchain:config("iccenv") + if iccenv then + return true + end + iccenv = find_iccenv() + if iccenv then + local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH" + local tool = find_tool("icc", {force = true, envs = {[ldname] = iccenv.libdir}, paths = iccenv.bindir}) + if tool then + cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch()) + toolchain:config_set("iccenv", iccenv) + toolchain:config_set("bindir", iccenv.bindir) + toolchain:configs_save() + return true + end + return true + end end -- main entry diff --git a/xmake/toolchains/icc/load.lua b/xmake/toolchains/icc/load.lua index 5784fc5c8..e1ceba260 100644 --- a/xmake/toolchains/icc/load.lua +++ b/xmake/toolchains/icc/load.lua @@ -26,7 +26,7 @@ import("core.project.config") function _add_iclenv(toolchain, name) -- get iclvarsall - local iclvarsall = config.get("__iclvarsall") + local iclvarsall = toolchain:config("varsall") if not iclvarsall then return end @@ -100,6 +100,13 @@ function _load_intel_on_linux(toolchain) toolchain:add("ldflags", march) toolchain:add("shflags", march) end + + -- get icc environments + local iccenv = toolchain:config("iccenv") + if iccenv then + local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH" + toolchain:add("runenvs", ldname, iccenv.libdir) + end end -- main entry diff --git a/xmake/toolchains/ifort/load.lua b/xmake/toolchains/ifort/load.lua index 1d8eb870f..2cb212a57 100644 --- a/xmake/toolchains/ifort/load.lua +++ b/xmake/toolchains/ifort/load.lua @@ -87,6 +87,7 @@ function _load_intel_on_linux(toolchain) end -- get ifort environments + local ifortenv = toolchain:config("ifortenv") if ifortenv then local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH" toolchain:add("runenvs", ldname, ifortenv.libdir) |
