diff options
| author | ruki <[email protected]> | 2018-03-09 23:15:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-03-09 13:34:53 +0800 |
| commit | a6f86e9466987f5e14006245bb35cefc5339dfc0 (patch) | |
| tree | edea0be538ee40cb15bf42679f751c96799d5151 | |
| parent | af7fafb3c03680052207039cae975628192d3109 (diff) | |
support cuda for windows
| -rw-r--r-- | xmake/modules/detect/sdks/find_cuda_toolchains.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_nvcc.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 8 | ||||
| -rw-r--r-- | xmake/platforms/windows/check.lua | 7 | ||||
| -rw-r--r-- | xmake/platforms/windows/xmake.lua | 18 |
5 files changed, 35 insertions, 9 deletions
diff --git a/xmake/modules/detect/sdks/find_cuda_toolchains.lua b/xmake/modules/detect/sdks/find_cuda_toolchains.lua index 0d84f69b7..f6163ad54 100644 --- a/xmake/modules/detect/sdks/find_cuda_toolchains.lua +++ b/xmake/modules/detect/sdks/find_cuda_toolchains.lua @@ -33,12 +33,13 @@ function _find_cudadir() if os.host() == "macosx" then table.insert(pathes, "/Developer/NVIDIA/CUDA**/bin") elseif os.host() == "windows" then + table.insert(pathes, "$(env CUDA_PATH)/bin") else table.insert(pathes, "/usr/local/cuda/bin") end -- attempt to find nvcc - local nvcc = find_file("nvcc", pathes) + local nvcc = find_file(os.host() == "windows" and "nvcc.exe" or "nvcc", pathes) if nvcc then return path.directory(path.directory(nvcc)) end @@ -69,13 +70,13 @@ function main(cudadir, opt) -- not found? if not cudadir or not os.isdir(cudadir) then - return {} + return nil end -- get the bin directory local bindir = path.join(cudadir, "bin") - if not os.isfile(path.join(bindir, "nvcc")) then - return {} + if not os.isexec(path.join(bindir, "nvcc")) then + return nil end -- get linkdirs diff --git a/xmake/modules/detect/tools/find_nvcc.lua b/xmake/modules/detect/tools/find_nvcc.lua index 7892726a1..1944915af 100644 --- a/xmake/modules/detect/tools/find_nvcc.lua +++ b/xmake/modules/detect/tools/find_nvcc.lua @@ -54,7 +54,7 @@ function main(opt) local cudadir = config.get("cuda_dir") if cudadir then local toolchains = find_cuda_toolchains(cudadir) - if toolchains then + if toolchains and toolchains.bindir then program = find_program(path.join(toolchains.bindir, "nvcc"), opt) end end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 2984793a0..35dabe581 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -98,10 +98,10 @@ function main() _g["cu-ldflags"] = {"-ccbin", "clang++", cu_archs[arch] or ""} local cuda_dir = config.get("cuda_dir") if cuda_dir then - table.insert(_g.cuflags, "-I" .. path.join(cuda_dir, "include")) - table.insert(_g["cu-ldflags"], "-L" .. path.join(cuda_dir, "lib")) - table.insert(_g["cu-shflags"], "-L" .. path.join(cuda_dir, "lib")) - table.insert(_g["cu-ldflags"], "-Xlinker -rpath -Xlinker " .. path.join(cuda_dir, "lib")) + table.insert(_g.cuflags, "-I" .. os.args(path.join(cuda_dir, "include"))) + table.insert(_g["cu-ldflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) + table.insert(_g["cu-shflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) + table.insert(_g["cu-ldflags"], "-Xlinker -rpath -Xlinker " .. os.args(path.join(cuda_dir, "lib"))) end -- ok diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua index 157491f43..2225f5dc9 100644 --- a/xmake/platforms/windows/check.lua +++ b/xmake/platforms/windows/check.lua @@ -166,6 +166,11 @@ function _toolchains(config) checker.toolchain_insert(toolchains, "as", "", "ml.exe", "the assember") end + -- insert cuda tools to toolchains + checker.toolchain_insert(toolchains, "cu", "", "nvcc", "the cuda compiler") + checker.toolchain_insert(toolchains, "cu-sh", "", "nvcc", "the cuda shared library linker") + checker.toolchain_insert(toolchains, "cu-ld", "", "nvcc", "the cuda linker") + -- save toolchains _g.TOOLCHAINS = toolchains @@ -197,6 +202,7 @@ function main(kind, toolkind) { { checker.check_arch, "x86" } , _check_vs + , checker.check_cuda_toolchains } -- init the check list of global @@ -204,6 +210,7 @@ function main(kind, toolkind) { { checker.check_arch, "x86" } , _check_vs + , checker.check_cuda_toolchains , _clean_global } diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index f7353f442..dbcc42b80 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -43,6 +43,12 @@ platform("windows") -- on load on_load(function () + -- imports + import("core.project.config") + + -- init flags for architecture + local arch = config.get("arch") + -- init the file formats _g.formats = {} _g.formats.static = {"", ".lib"} @@ -57,6 +63,18 @@ platform("windows") _g["dc-shflags"] = { dc_archs[arch] } _g["dc-ldflags"] = { dc_archs[arch] } + -- init flags for cuda + local cu_archs = { x86 = "-m32 -Xcompiler -m32", x64 = "-m64 -Xcompiler -m64" } + _g.cuflags = {cu_archs[arch] or ""} + _g["cu-shflags"] = {cu_archs[arch] or ""} + _g["cu-ldflags"] = {cu_archs[arch] or ""} + local cuda_dir = config.get("cuda_dir") + if cuda_dir then + table.insert(_g.cuflags, "-I" .. os.args(path.join(cuda_dir, "include"))) + table.insert(_g["cu-ldflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) + table.insert(_g["cu-shflags"], "-L" .. os.args(path.join(cuda_dir, "lib"))) + end + -- ok return _g end) |
