Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ifort #1898

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions xmake/modules/detect/sdks/find_iccenv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 19 additions & 3 deletions xmake/modules/detect/sdks/find_ifortenv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,28 @@ end
-- find intel fortran envirnoment on linux
function _find_intel_on_linux(opt)

-- attempt to find the sdk directory
local paths = {"/opt/intel/bin", "/usr/local/bin", "/usr/bin"}
local ifort = find_file("ifort", paths)
if ifort then
local sdkdir = path.directory(path.directory(ifort))
return {sdkdir = sdkdir, bindir = path.directory(ifort), path.join(sdkdir, "include"), libdir = path.join(sdkdir, "lib")}
local bindir = path.directory(ifort)
local sdkdir = path.directory(bindir)
return {sdkdir = sdkdir, bindir = bindir, 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 ifort = find_file("ifort", paths)
if ifort then
local bindir = path.directory(ifort)
local sdkdir = path.directory(bindir)
return {sdkdir = sdkdir, bindir = bindir, libdir = path.join(sdkdir, "compiler", "lib", arch)}
end
end
end

Expand Down
14 changes: 0 additions & 14 deletions xmake/modules/detect/tools/find_ifort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ function main(opt)
return program, version
else
-- find program
if is_host("linux") then
local arch = os.arch() == "x86_64" and "intel64" or "ia32"
local dirs = {"~/intel/oneapi/compiler/latest/linux"}
opt.envs = opt.envs or {}
opt.paths = opt.paths or {}
local LD_LIBRARY_PATH = {}
for _, dir in ipairs(dirs) do
if os.isdir(dir) then
table.insert(LD_LIBRARY_PATH, path.join(dir, "compiler/lib", arch))
table.insert(opt.paths, path.join(dir, "bin", arch))
end
end
opt.envs.LD_LIBRARY_PATH = path.joinenv(LD_LIBRARY_PATH)
end
local program = find_program(opt.program or "ifort", opt)

-- find program version
Expand Down
32 changes: 21 additions & 11 deletions xmake/toolchains/icc/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion xmake/toolchains/icc/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions xmake/toolchains/ifort/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import("lib.detect.find_tool")
function _check_intel_on_windows(toolchain)

-- have been checked?
if config.get("__ifortvarsall") then
local varsall = toolchain:config("varsall")
if varsall then
return true
end

Expand All @@ -38,18 +39,11 @@ function _check_intel_on_windows(toolchain)
local ifortvarsall = ifortenv.ifortvars
local ifortenv = ifortvarsall[toolchain:arch()]
if ifortenv and ifortenv.PATH and ifortenv.INCLUDE and ifortenv.LIB then

-- save ifortvars
config.set("__ifortvarsall", ifortvarsall)

-- check compiler
local program = nil
local tool = find_tool("ifort.exe", {force = true, envs = ifortenv, version = true})
if tool then
program = tool.program
end
if program then
cprint("checking for Intel Fortran Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("varsall", ifortvarsall)
toolchain:configs_save()
return true
end
end
Expand All @@ -58,7 +52,23 @@ end

-- check intel on linux
function _check_intel_on_linux(toolchain)
return find_tool("ifort")
local ifortenv = toolchain:config("ifortenv")
if ifortenv then
return true
end
ifortenv = find_ifortenv()
if ifortenv then
local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
local tool = find_tool("ifort", {force = true, envs = {[ldname] = ifortenv.libdir}, paths = ifortenv.bindir})
if tool then
cprint("checking for Intel Fortran Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("ifortenv", ifortenv)
toolchain:config_set("bindir", ifortenv.bindir)
toolchain:configs_save()
return true
end
return true
end
end

-- main entry
Expand Down
9 changes: 8 additions & 1 deletion xmake/toolchains/ifort/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import("core.project.config")
function _add_ifortenv(toolchain, name)

-- get ifortvarsall
local ifortvarsall = config.get("__ifortvarsall")
local ifortvarsall = toolchain:config("varsall")
if not ifortvarsall then
return
end
Expand Down Expand Up @@ -85,6 +85,13 @@ function _load_intel_on_linux(toolchain)
toolchain:add("fcldflags", march)
toolchain:add("fcshflags", march)
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)
end
end

-- main entry
Expand Down