diff options
| author | ruki <[email protected]> | 2019-06-11 00:31:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-10 21:07:32 +0800 |
| commit | 21fbe003a96514fe92106a6b8fb88fab7ed02fce (patch) | |
| tree | e351ea28a146a2d3b8f770e3b1e4a9c08fdbe0f6 | |
| parent | f63112325a658b582b87428a1f78c7e89f3b074e (diff) | |
move platform cuda setting to env rule
| -rw-r--r-- | xmake/platforms/linux/load.lua | 14 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 14 | ||||
| -rw-r--r-- | xmake/platforms/windows/load.lua | 9 | ||||
| -rw-r--r-- | xmake/rules/cuda/device_link/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/cuda/env/xmake.lua | 49 |
5 files changed, 53 insertions, 41 deletions
diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index 65761d0ac..dcdacd8c1 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -77,19 +77,5 @@ function main(platform) -- init flags for rust platform:set("rc-shflags", "") platform:set("rc-ldflags", "") - - -- init flags for cuda - local cu_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("cuflags", cu_archs[arch] or "") - platform:add("cu-ldflags", cu_archs[arch] or "") - local cuda_dir = config.get("cuda") - if cuda_dir then - platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) - end - local cu_ccbin = config.get("cu-ccbin") - if cu_ccbin then - platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) - platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) - end end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 19c2182b9..e53dc1b8c 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -88,19 +88,5 @@ function main(platform) -- init flags for rust platform:set("rc-shflags", "") platform:set("rc-ldflags", "") - - -- init flags for cuda - local cu_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("cuflags", cu_archs[arch] or "") - platform:add("cu-ldflags", cu_archs[arch] or "") - local cuda_dir = config.get("cuda") - if cuda_dir then - platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) - end - local cu_ccbin = config.get("cu-ccbin") - if cu_ccbin then - platform:add("cuflags", "-ccbin", os.args(cu_ccbin)) - platform:add("cu-ldflags", "-ccbin", os.args(cu_ccbin)) - end end diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua index 444b3feb6..f7789ddb9 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/platforms/windows/load.lua @@ -35,13 +35,4 @@ function main(platform) platform:add("dcflags", dc_archs[arch]) platform:add("dc-shflags", dc_archs[arch]) platform:add("dc-ldflags", dc_archs[arch]) - - -- init flags for cuda - local cu_archs = { x86 = "-m32", x64 = "-m64" } - platform:add("cuflags", cu_archs[arch] or "") - platform:add("cu-ldflags", cu_archs[arch] or "") - local cuda_dir = config.get("cuda") - if cuda_dir then - platform:add("cuflags", "-I" .. os.args(path.join(cuda_dir, "include"))) - end end diff --git a/xmake/rules/cuda/device_link/xmake.lua b/xmake/rules/cuda/device_link/xmake.lua index 8489d8c83..90481c34b 100644 --- a/xmake/rules/cuda/device_link/xmake.lua +++ b/xmake/rules/cuda/device_link/xmake.lua @@ -21,14 +21,14 @@ -- define rule: device-link rule("cuda.device_link") + -- add rule: cuda environment + add_deps("cuda.env") + -- after load after_load(function (target) - -- imports - import("detect.sdks.find_cuda") - -- get cuda - local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK directory not found!") + local cuda = assert(target:data("cuda")) -- add links target:add("links", "cudadevrt", "cudart_static") diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua new file mode 100644 index 000000000..a334bb200 --- /dev/null +++ b/xmake/rules/cuda/env/xmake.lua @@ -0,0 +1,49 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: environment +rule("cuda.env") + after_load(function (target) + + -- 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("x86_64", "x64") then + target:add("cuflags", "-m64", {force = true}) + target:add("culdflags", "-m64", {force = true}) + else + target:add("cuflags", "-m32", {force = true}) + target:add("culdflags", "-m32", {force = true}) + end + + -- add -ccbin + local cu_ccbin = get_config("cu-ccbin") + if cu_ccbin then + target:add("cuflags", "-ccbin", os.args(cu_ccbin), {force = true}) + target:add("culdflags", "-ccbin", os.args(cu_ccbin), {force = true}) + end + + -- add includedirs + target:add("includedirs", cuda.includedirs) + end) + |
