Skip to content

Commit

Permalink
Check on linker instead of compiler to set flags
Browse files Browse the repository at this point in the history
The tests to set the linker flags are now based on "ld/fcld" instead of
the compilers "cc/fc" to avoid problems with toolchains combining
different tools.
  • Loading branch information
Julien Bloino committed Sep 19, 2024
1 parent adb9d01 commit 154419a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
32 changes: 23 additions & 9 deletions packages/m/mkl/fetch.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import("lib.detect.find_path")
import("lib.detect.find_library")

-- add_configs("runtime", {description = "Set MKL runtime for gcc/clang like compilers.", default = "default", type = "string", values = {"default", "custom"}})

function _find_package(package, opt)
local rdir = (package:is_arch("x64", "x86_64") and "intel64" or "ia32")
local suffix = (package:config("interface") == 32 and "lp64" or "ilp64")
Expand Down Expand Up @@ -45,15 +47,27 @@ function _find_package(package, opt)
table.join2(group, {"mkl_intel_thread", "mkl_core"})
end

if (package:has_tool("cc", "gcc", "gxx") or
package:has_tool("fc", "gfortran")) then
result.ldflags = "-Wl,--start-group "
for _, lib in ipairs(group) do
result.ldflags = result.ldflags .. "-l" .. lib .. " "
end
result.ldflags = result.ldflags .. "-Wl,--end-group"
else
table.join2(result.links, group)
for _, toolkind in ipairs({"ld", "fcld"}) do
-- if package:config("runtime") == "default" then
if (package:has_tool(toolkind, "gcc", "gxx") or package:has_tool(toolkind, "gfortran")) then
local flags = {"-Wl,--start-group"}
for _, lib in ipairs(group) do
table.insert(flags, "-l" .. lib)
end
table.insert(flags, "-Wl,--end-group")
if package:has_tool(toolkind, "gcc", "gxx") then
result.ldflags = table.concat(flags, " ")
result.shflags = table.concat(flags, " ")
else
-- result.fcldflags = table.concat(flags, " ")
-- result.fcshflags = table.concat(flags, " ")
result.fcldflags = table.concat(flags, " ")
result.fcshflags = table.concat(flags, " ")
end
else
table.join2(result.links, group)
end
-- end
end

-- find include
Expand Down
82 changes: 49 additions & 33 deletions packages/m/mkl/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package("mkl")
set_homepage("https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl.html")
set_description("Intel® oneAPI Math Kernel Library")

add_configs("runtime", {description = "Set MKL runtime for gcc/clang like compilers.", default = "default", type = "string", values = {"default", "custom"}})

if is_plat("windows") then
if is_arch("x64") then
add_urls("https://software.repos.intel.com/python/conda/$(version).tar.bz2", {version = function (version)
Expand Down Expand Up @@ -113,43 +115,57 @@ package("mkl")
package:add("links", package:is_arch("x64", "x86_64") and "mkl_blas95_" .. suffix or "mkl_blas95")
package:add("links", package:is_arch("x64", "x86_64") and "mkl_lapack95_" .. suffix or "mkl_lapack95")

if (package:has_tool("cc", "gcc", "gxx") or
package:has_tool("fc", "gfortran")) then
local flags = {"-Wl,--start-group"}
table.insert(flags, package:is_arch("x64", "x86_64") and "-lmkl_intel_" .. suffix or "-lmkl_intel")
local threading = package:config("threading")
if threading == "tbb" then
table.insert(flags, "-lmkl_tbb_thread")
package:add("deps", "tbb")
elseif threading == "seq" then
table.insert(flags, "-lmkl_sequential")
elseif threading == "openmp" then
table.insert(flags, "-lmkl_intel_thread")
table.insert(flags, "-lomp")
elseif threading == "gomp" then
table.insert(flags, "-lmkl_gnu_thread")
table.insert(flags, "-lgomp")
end
table.insert(flags, "-lmkl_core")
table.insert(flags, "-Wl,--end-group")
package:add("ldflags", table.concat(flags, " "))
else
package:add("links", package:is_arch("x64", "x86_64") and "mkl_intel_" .. suffix or "mkl_intel_c")
local threading = package:config("threading")
if threading == "tbb" then
package:add("links", "mkl_tbb_thread")
package:add("deps", "tbb")
elseif threading == "seq" then
package:add("links", "mkl_sequential")
elseif threading == "openmp" then
package:add("links", "mkl_intel_thread", "omp")
elseif threading == "gomp" then
package:add("links", "mkl_gnu_thread", "gomp")
for _, toolkind in ipairs({"ld", "fcld"}) do
if package:config("runtime") == "default" then
if (package:has_tool(toolkind, "gcc", "gxx") or package:has_tool(toolkind, "gfortran")) then
if package:has_tool(toolkind, "gcc", "gxx") then
var_ldflags = 'ldflags'
var_shflags = 'shflags'
else
var_ldflags = 'ldflags'
var_shflags = 'shflags'
-- var_ldflags = 'fcldflags'
-- var_shflags = 'fcshflags'
end
local flags = {"-Wl,--start-group"}
table.insert(flags, package:is_arch("x64", "x86_64") and "-lmkl_intel_" .. suffix or "-lmkl_intel")
local threading = package:config("threading")
if threading == "tbb" then
table.insert(flags, "-lmkl_tbb_thread")
package:add("deps", "tbb")
elseif threading == "seq" then
table.insert(flags, "-lmkl_sequential")
elseif threading == "openmp" then
table.insert(flags, "-lmkl_intel_thread")
table.insert(flags, "-lomp")
elseif threading == "gomp" then
table.insert(flags, "-lmkl_gnu_thread")
table.insert(flags, "-lgomp")
end
table.insert(flags, "-lmkl_core")
table.insert(flags, "-Wl,--end-group")
package:add(var_ldflags, table.concat(flags, " "))
package:add(var_shflags, table.concat(flags, " "))
else
package:add("links", package:is_arch("x64", "x86_64") and "mkl_intel_" .. suffix or "mkl_intel_c")
local threading = package:config("threading")
if threading == "tbb" then
package:add("links", "mkl_tbb_thread")
package:add("deps", "tbb")
elseif threading == "seq" then
package:add("links", "mkl_sequential")
elseif threading == "openmp" then
package:add("links", "mkl_intel_thread", "omp")
elseif threading == "gomp" then
package:add("links", "mkl_gnu_thread", "gomp")
end
package:add("links", "mkl_core")
end
end
package:add("links", "mkl_core")
end
end)


on_install("windows|!arm64", "macosx|!arm64", "linux|x86_64", "linux|i386", function (package)
local headerdir = package:resourcedir("headers")
if package:is_plat("windows") then
Expand Down

0 comments on commit 154419a

Please sign in to comment.