summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-08 22:30:38 +0800
committerruki <[email protected]>2021-12-08 22:30:38 +0800
commitdedcd548ec31ad936128b272c705f8f30fb01eb2 (patch)
treecae8d7b373d1eacb097298f022780d75abc6eb6a
parent86eaab2842abf6570895da359ed484805bf759a5 (diff)
improve ifort
-rw-r--r--xmake/modules/detect/sdks/find_ifortenv.lua18
-rw-r--r--xmake/modules/detect/tools/find_ifort.lua14
-rw-r--r--xmake/toolchains/ifort/check.lua31
-rw-r--r--xmake/toolchains/ifort/load.lua9
4 files changed, 43 insertions, 29 deletions
diff --git a/xmake/modules/detect/sdks/find_ifortenv.lua b/xmake/modules/detect/sdks/find_ifortenv.lua
index f3aafad06..f45bda0d5 100644
--- a/xmake/modules/detect/sdks/find_ifortenv.lua
+++ b/xmake/modules/detect/sdks/find_ifortenv.lua
@@ -116,12 +116,24 @@ 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
+
+ if is_host("linux") then
+ local arch = os.arch() == "x86_64" and "intel64" or "ia32"
+ local host = is_host("macosx") and "macos" or "linux"
+ local paths = {"~/intel/oneapi/compiler/latest/" .. host .. "/bin/" .. arch}
+ 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
diff --git a/xmake/modules/detect/tools/find_ifort.lua b/xmake/modules/detect/tools/find_ifort.lua
index dfa8f254c..31f158996 100644
--- a/xmake/modules/detect/tools/find_ifort.lua
+++ b/xmake/modules/detect/tools/find_ifort.lua
@@ -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
diff --git a/xmake/toolchains/ifort/check.lua b/xmake/toolchains/ifort/check.lua
index 67d4e3931..cb37666b7 100644
--- a/xmake/toolchains/ifort/check.lua
+++ b/xmake/toolchains/ifort/check.lua
@@ -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
@@ -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:config_save()
return true
end
end
@@ -58,7 +52,22 @@ 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_save()
+ return true
+ end
+ return true
+ end
end
-- main entry
diff --git a/xmake/toolchains/ifort/load.lua b/xmake/toolchains/ifort/load.lua
index 804f3a914..2cb212a57 100644
--- a/xmake/toolchains/ifort/load.lua
+++ b/xmake/toolchains/ifort/load.lua
@@ -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
@@ -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