summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchooyy <[email protected]>2025-10-23 20:57:12 +0800
committerchooyy <[email protected]>2025-10-23 20:57:12 +0800
commitd6a0a93f4328dd0e136adfe12c7f950834bdf9e9 (patch)
treee6b4cc561df4c33070c8a3aeb21e9f7b09087c27
parent6796d33e9a788313207199ecc441c7e47b579168 (diff)
support specify cuda sdk version via cuda_sdkver
-rw-r--r--xmake/modules/detect/sdks/find_cuda.lua45
-rw-r--r--xmake/platforms/bsd/xmake.lua1
-rw-r--r--xmake/platforms/haiku/xmake.lua1
-rw-r--r--xmake/platforms/linux/xmake.lua1
-rw-r--r--xmake/platforms/macosx/xmake.lua1
-rw-r--r--xmake/platforms/windows/xmake.lua37
6 files changed, 54 insertions, 32 deletions
diff --git a/xmake/modules/detect/sdks/find_cuda.lua b/xmake/modules/detect/sdks/find_cuda.lua
index 0a4756bee..481ad95af 100644
--- a/xmake/modules/detect/sdks/find_cuda.lua
+++ b/xmake/modules/detect/sdks/find_cuda.lua
@@ -27,11 +27,21 @@ import("core.project.config")
import("core.cache.detectcache")
-- find cuda sdk directory
-function _find_sdkdir(version)
+function _find_sdkdir(version, sdkdir)
-- init the search directories
local paths = {}
- if version then
+ if sdkdir then
+ version = version or "*"
+ table.insert(paths, path.join(sdkdir, "bin"))
+ if is_host("macosx") then
+ table.insert(paths, path.join(sdkdir, format("CUDA-%s/bin", version)))
+ elseif is_host("windows") then
+ table.insert(paths, path.join(sdkdir, format("v%s\\bin", version)))
+ else
+ table.insert(paths, path.join(sdkdir, format("cuda-%s/bin", version)))
+ end
+ elseif version then
if is_host("macosx") then
table.insert(paths, format("/Developer/NVIDIA/CUDA-%s/bin", version))
elseif is_host("windows") then
@@ -71,22 +81,28 @@ function _find_msbuildextensionsdir(sdkdir)
end
-- find cuda sdk toolchains
-function _find_cuda(sdkdir)
+function _find_cuda(sdkdir, sdkver)
+
+ -- handle sdkdir as version
+ if sdkdir and sdkdir:match("^[%d*]+%.[%d*]+$") then
+ sdkver = sdkdir
+ sdkdir = nil
+ end
-- check sdkdir
- if sdkdir and not os.isdir(sdkdir) and not sdkdir:match("^[%d*]+%.[%d*]+$") then
- raise("invalid cuda version/location: " .. sdkdir)
+ if sdkdir and not os.isdir(sdkdir) then
+ raise("invalid cuda location: " .. sdkdir)
+ end
+
+ -- check sdkver
+ if sdkver and not sdkver:match("^[%d*]+%.[%d*]+$") then
+ raise("invalid cuda version: " .. sdkver)
end
-- find cuda directory
- if not sdkdir then
- sdkdir = _find_sdkdir()
- elseif sdkdir:match("^[%d*]+%.[%d*]+$") then
- local cudaversion = sdkdir
- sdkdir = _find_sdkdir(cudaversion)
- if not sdkdir then
- raise("cuda version %s not found!", cudaversion)
- end
+ sdkdir = _find_sdkdir(sdkver, sdkdir)
+ if not sdkdir and sdkver then
+ raise("cuda version %s not found!", sdkver)
end
-- not found?
@@ -155,11 +171,12 @@ function main(sdkdir, opt)
end
-- find cuda
- local cuda = _find_cuda(sdkdir or config.get("cuda") or global.get("cuda") or config.get("sdk"))
+ local cuda = _find_cuda(sdkdir or config.get("cuda") or global.get("cuda") or config.get("sdk"), opt.version or config.get("cuda_sdkver"))
if cuda then
-- save to config
config.set("cuda", cuda.sdkdir, {force = true, readonly = true})
+ config.set("cuda_sdkver", cuda.sdkver, {force = true, readonly = true})
-- trace
if opt.verbose or option.get("verbose") then
diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua
index d79d778d8..3c34e2420 100644
--- a/xmake/platforms/bsd/xmake.lua
+++ b/xmake/platforms/bsd/xmake.lua
@@ -37,6 +37,7 @@ platform("bsd")
{
{category = "Cuda SDK Configuration" }
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda_sdkver", "kv", "auto", "The Cuda SDK Version" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
, {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
diff --git a/xmake/platforms/haiku/xmake.lua b/xmake/platforms/haiku/xmake.lua
index 8f046de5f..1253f3231 100644
--- a/xmake/platforms/haiku/xmake.lua
+++ b/xmake/platforms/haiku/xmake.lua
@@ -35,6 +35,7 @@ platform("haiku")
{
{category = "Cuda SDK Configuration" }
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda_sdkver", "kv", "auto", "The Cuda SDK Version" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
, {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index d110788cf..ebaedf975 100644
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -36,6 +36,7 @@ platform("linux")
{
{category = "Cuda SDK Configuration" }
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda_sdkver", "kv", "auto", "The Cuda SDK Version" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
, {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua
index dbcfb889d..348c61f55 100644
--- a/xmake/platforms/macosx/xmake.lua
+++ b/xmake/platforms/macosx/xmake.lua
@@ -45,6 +45,7 @@ platform("macosx")
values = {"simulator", "iphone", "watchtv", "appletv", "catalyst"}}
, {category = "Cuda SDK Configuration" }
, {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda_sdkver", "kv", "auto", "The Cuda SDK Version" }
, {category = "Qt SDK Configuration" }
, {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
, {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 12050eb0c..4d8335171 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -35,24 +35,25 @@ platform("windows")
config =
{
{category = "Visual Studio SDK Configuration" }
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio"
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio"
, " e.g. --vs=2017" }
- , {nil, "vs_toolset", "kv", nil, "The Microsoft Visual Studio Toolset Version"
+ , {nil, "vs_toolset", "kv", nil, "The Microsoft Visual Studio Toolset Version"
, " e.g. --vs_toolset=14.0" }
- , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio"
+ , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio"
, " e.g. --vs_sdkver=10.0.15063.0" }
- , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio (deprecated, please use --runtimes)"
+ , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio (deprecated, please use --runtimes)"
, values = {"MT", "MTd", "MD", "MDd"} }
, {category = "Cuda SDK Configuration" }
- , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda_sdkver", "kv", "auto", "The Cuda SDK Version" }
, {category = "Qt SDK Configuration" }
- , {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
- , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
- , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
+ , {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
+ , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" }
, {category = "WDK Configuration" }
- , {nil, "wdk", "kv", "auto", "The WDK Directory" }
- , {nil, "wdk_sdkver", "kv", "auto", "The WDK Version" }
- , {nil, "wdk_winver", "kv", "auto", "The WDK Windows Version"
+ , {nil, "wdk", "kv", "auto", "The WDK Directory" }
+ , {nil, "wdk_sdkver", "kv", "auto", "The WDK Version" }
+ , {nil, "wdk_winver", "kv", "auto", "The WDK Windows Version"
, values = function (complete)
if complete then
return {"win10_rs3", "win10", "win81", "win8", "win7_sp3", "win7_sp2", "win7_sp1", "win7"}
@@ -61,22 +62,22 @@ platform("windows")
end
end }
, {category = "Vcpkg Configuration" }
- , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
+ , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
}
, global =
{
{category = "Visual Studio SDK Configuration" }
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" }
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" }
, {category = "Cuda SDK Configuration" }
- , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
+ , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" }
, {category = "Qt SDK Configuration" }
- , {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
- , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
+ , {nil, "qt", "kv", "auto", "The Qt SDK Directory" }
+ , {nil, "qt_host", "kv", "auto", "The Qt Host SDK Directory" }
, {category = "WDK Configuration" }
- , {nil, "wdk", "kv", "auto", "The WDK Directory" }
+ , {nil, "wdk", "kv", "auto", "The WDK Directory" }
, {category = "Vcpkg Configuration" }
- , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
+ , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
}
}