diff options
| author | ruki <[email protected]> | 2019-06-11 00:54:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-10 23:27:58 +0800 |
| commit | f42f1b5a97f5fdbac4d74a2e43a32fcc71cee0c3 (patch) | |
| tree | 4bd1cdcdc1f8db843720686133666bd9c0098d37 | |
| parent | 9f81f22e0d241bfc6ddb2f5b55b75ddfbc3f6851 (diff) | |
improve cuda.env and ignore static kind
| -rw-r--r-- | xmake/rules/cuda/device_link/xmake.lua | 21 | ||||
| -rw-r--r-- | xmake/rules/cuda/env/xmake.lua | 19 |
2 files changed, 24 insertions, 16 deletions
diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 90481c34b..068c8270f 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -24,24 +24,15 @@ rule("cuda.device_link") -- add rule: cuda environment add_deps("cuda.env") - -- after load - after_load(function (target) - - -- get cuda - local cuda = assert(target:data("cuda")) - - -- add links - target:add("links", "cudadevrt", "cudart_static") - if is_plat("linux") then - target:add("links", "rt", "pthread", "dl") - end - target:add("linkdirs", cuda.linkdirs) - target:add("rpathdirs", cuda.linkdirs) - end) - -- @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ before_link(function (target, opt) + -- only for binary/shared + local targetkind = target:targetkind() + if targetkind ~= "binary" and targetkind ~= "shared" then + return + end + -- imports import("core.base.option") import("core.theme.theme") diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index a4d408d2d..1acbc08ba 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -25,7 +25,6 @@ rule("cuda.env") -- get cuda sdk import("detect.sdks.find_cuda") local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") - target:data_set("cuda", cuda) -- add arch if is_arch("i386", "x86") then @@ -43,6 +42,24 @@ rule("cuda.env") target:add("culdflags", "-ccbin", os.args(cu_ccbin), {force = true}) end + -- add links + target:add("syslinks", "cudadevrt") + local cudart = false + for _, link in ipairs(table.join(target:get("links") or {}, target:get("syslinks"))) do + if link == "cudart" or link == "cudart_static" then + cudart = true + break + end + end + if not cudart then + target:add("syslinks", "cudart_static") + end + if is_plat("linux") then + target:add("syslinks", "rt", "pthread", "dl") + end + target:add("linkdirs", cuda.linkdirs) + target:add("rpathdirs", cuda.linkdirs) + -- add includedirs target:add("includedirs", cuda.includedirs) end) |
