summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-06-08 00:37:49 +0800
committerruki <[email protected]>2019-06-07 21:46:59 +0800
commit754f2510e5d521097ac15a15f6ec5912bc30358d (patch)
tree503083d291b44254b802ebe84a85eff1cf28994d
parent4b28a75f3cfd24d4b37af729db14925c1389c033 (diff)
improve to find_cuda
-rw-r--r--xmake/modules/detect/sdks/find_cuda.lua85
-rw-r--r--xmake/modules/private/platform/check_cuda.lua18
-rw-r--r--xmake/platforms/linux/global.lua4
-rw-r--r--xmake/platforms/macosx/global.lua4
-rw-r--r--xmake/platforms/windows/global.lua4
-rw-r--r--xmake/rules/cuda/env/xmake.lua11
6 files changed, 68 insertions, 58 deletions
diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua
index 259f643fe..a75dfa9f5 100644
--- a/xmake/modules/detect/sdks/find_cuda.lua
+++ b/xmake/modules/detect/sdks/find_cuda.lua
@@ -19,10 +19,14 @@
--
-- imports
+import("lib.detect.cache")
import("lib.detect.find_file")
+import("core.base.option")
+import("core.base.global")
+import("core.project.config")
-- find cuda sdk directory
-function _find_cudadir()
+function _find_sdkdir()
-- init the search directories
local pathes = {}
@@ -42,11 +46,40 @@ function _find_cudadir()
end
-- find cuda sdk toolchains
+function _find_cuda(sdkdir)
+
+ -- find cuda directory
+ if not sdkdir or not os.isdir(sdkdir) then
+ sdkdir = _find_sdkdir()
+ end
+
+ -- not found?
+ if not sdkdir or not os.isdir(sdkdir) then
+ return nil
+ end
+
+ -- get the bin directory
+ local bindir = path.join(sdkdir, "bin")
+ if not os.isexec(path.join(bindir, "nvcc")) then
+ return nil
+ end
+
+ -- get linkdirs
+ local linkdirs = {path.join(sdkdir, "lib")}
+
+ -- get includedirs
+ local includedirs = {path.join(sdkdir, "include")}
+
+ -- get toolchains
+ return {sdkdir = sdkdir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs}
+end
+
+-- find cuda sdk toolchains
--
--- @param cudadir the cuda directory
+-- @param sdkdir the cuda sdk directory
-- @param opt the argument options
--
--- @return the cuda sdk toolchains. .e.g {cudadir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. }
+-- @return the cuda sdk toolchains. .e.g {sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. }
--
-- @code
--
@@ -54,33 +87,41 @@ end
--
-- @endcode
--
-function main(cudadir, opt)
+function main(sdkdir, opt)
-- init arguments
opt = opt or {}
- -- find cuda directory
- if not cudadir or not os.isdir(cudadir) then
- cudadir = _find_cudadir()
+ -- attempt to load cache first
+ local key = "detect.sdks.find_cuda." .. (sdkdir or "")
+ local cacheinfo = cache.load(key)
+ if not opt.force and cacheinfo.cuda then
+ return cacheinfo.cuda
end
+
+ -- find cuda
+ local cuda = _find_cuda(sdkdir or config.get("cuda") or global.get("cuda") or config.get("sdk"))
+ if cuda then
- -- not found?
- if not cudadir or not os.isdir(cudadir) then
- return nil
- end
+ -- save to config
+ config.set("cuda", cuda.sdkdir, {force = true, readonly = true})
- -- get the bin directory
- local bindir = path.join(cudadir, "bin")
- if not os.isexec(path.join(bindir, "nvcc")) then
- return nil
- end
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the Cuda SDK directory ... ${color.success}%s", cuda.sdkdir)
+ end
+ else
- -- get linkdirs
- local linkdirs = {path.join(cudadir, "lib")}
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the Cuda SDK directory ... ${color.nothing}${text.nothing}")
+ end
+ end
- -- get includedirs
- local includedirs = {path.join(cudadir, "include")}
+ -- save to cache
+ cacheinfo.cuda = cuda or false
+ cache.save(key, cacheinfo)
- -- get toolchains
- return {cudadir = cudadir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs}
+ -- ok?
+ return cuda
end
diff --git a/xmake/modules/private/platform/check_cuda.lua b/xmake/modules/private/platform/check_cuda.lua
index 0ab59a28b..ba86fbb01 100644
--- a/xmake/modules/private/platform/check_cuda.lua
+++ b/xmake/modules/private/platform/check_cuda.lua
@@ -24,21 +24,9 @@ import("detect.sdks.find_cuda")
-- check the cuda sdk toolchains
function main(config)
-
- -- get the cuda directory
- local cuda_dir = config.get("cuda")
- if not cuda_dir then
-
- -- check ok? update it
- local toolchains = find_cuda()
- if toolchains then
-
- -- save it
- config.set("cuda", toolchains.cudadir)
-
- -- trace
- cprint("checking for the Cuda SDK directory ... ${green}%s", toolchains.cudadir)
- end
+ local cuda = find_cuda(config.get("cuda"), {verbose = true})
+ if cuda then
+ config.set("cuda", cuda.sdkdir, {force = true, readonly = true})
end
end
diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua
index 4c8318a23..22aa9239a 100644
--- a/xmake/platforms/linux/global.lua
+++ b/xmake/platforms/linux/global.lua
@@ -20,7 +20,6 @@
-- imports
import("core.base.global")
-import("private.platform.check_cuda")
-- check it
function main(platform, name)
@@ -29,8 +28,5 @@ function main(platform, name)
if name then
raise("we cannot check global." .. name)
end
-
- -- check cuda
- check_cuda(global)
end
diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua
index 5b8ac731b..1db907fa7 100644
--- a/xmake/platforms/macosx/global.lua
+++ b/xmake/platforms/macosx/global.lua
@@ -20,7 +20,6 @@
-- imports
import("core.base.global")
-import("private.platform.check_cuda")
import("private.platform.check_xcode")
-- check it
@@ -33,8 +32,5 @@ function main(platform, name)
-- check xcode
check_xcode(global, true)
-
- -- check cuda
- check_cuda(global)
end
diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua
index 3068b81b7..2c5d7afda 100644
--- a/xmake/platforms/windows/global.lua
+++ b/xmake/platforms/windows/global.lua
@@ -21,7 +21,6 @@
-- imports
import("core.base.global")
import("private.platform.check_arch")
-import("private.platform.check_cuda")
import("private.platform.check_vstudio")
-- clean temporary global configs
@@ -44,9 +43,6 @@ function main(platform, name)
-- check vstudio
check_vstudio(global)
- -- check cuda
- check_cuda(global)
-
-- clean temporary global configs
_clean_global()
end
diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua
index 876b85ad7..713695e69 100644
--- a/xmake/rules/cuda/env/xmake.lua
+++ b/xmake/rules/cuda/env/xmake.lua
@@ -23,16 +23,9 @@ rule("cuda.env")
-- before load
before_load(function (target)
+ import("detect.sdks.find_cuda")
if not target:data("cuda") then
- local cuda = get_config("cuda")
- if not cuda then
- -- TODO improve find_cuda + cache
- local toolchain = import("detect.sdks.find_cuda")()
- if toolchain then
- cuda = toolchain.cudadir
- end
- end
- target:data_set("cuda", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!"))
+ target:data_set("cuda", assert(find_cuda(), "Cuda SDK not found!"))
end
end)