From d1628f8c57ecc60823a5d0b59bf070cddc794443 Mon Sep 17 00:00:00 2001
From: xq114 <1140735506@qq.com>
Date: Thu, 24 Feb 2022 22:50:10 +0800
Subject: try to support cuda for vs generator
---
.../project/vstudio/impl/vs201x_vcxproj.lua | 65 +++++++++++++++++++---
.../vstudio/impl/vs201x_vcxproj_filters.lua | 11 +++-
2 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index 9317312a0..c813a07cf 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -26,6 +26,7 @@ import("core.project.project")
import("core.language.language")
import("core.tool.toolchain")
import("private.utils.batchcmds")
+import("detect.sdks.find_cuda")
import("vsfile")
function _make_dirs(dir, vcxprojdir)
@@ -40,6 +41,22 @@ function _make_dirs(dir, vcxprojdir)
return dir
end
+-- check for CUDA
+function _check_cuda(target)
+ local sourcekinds = target:sourcekinds()
+ if table.contains(sourcekinds, "cu") then
+ return
+ end
+ local cuda = find_cuda()
+ if cuda then
+ if cuda.msbuildextensionsdir and cuda.version and os.isfile(path.join(cuda.msbuildextensionsdir, format("CUDA %s.props", cuda.version))) then
+ return cuda
+ else
+ os.raise("The Visual Studio Integration for CUDA %s is not found. Please check your CUDA installation.", cuda.version)
+ end
+ end
+end
+
-- get toolset version
function _get_toolset_ver(targetinfo, vsinfo)
@@ -159,9 +176,13 @@ function _make_header(vcxprojfile, vsinfo)
end
-- make tailer
-function _make_tailer(vcxprojfile, vsinfo)
+function _make_tailer(vcxprojfile, vsinfo, target)
vcxprojfile:print("")
vcxprojfile:enter("")
+ local cuda = _check_cuda(target)
+ if cuda then
+ vcxprojfile:print("", path.join(cuda.msbuildextensionsdir, format("CUDA %s.targets", cuda.version)))
+ end
vcxprojfile:leave("")
vcxprojfile:leave("")
end
@@ -219,6 +240,10 @@ function _make_configurations(vcxprojfile, vsinfo, target)
-- make ExtensionSettings
vcxprojfile:enter("")
+ local cuda = _check_cuda(target)
+ if cuda then
+ vcxprojfile:print("", path.join(cuda.msbuildextensionsdir, format("CUDA %s.props", cuda.version)))
+ end
vcxprojfile:leave("")
-- make PropertySheets
@@ -562,7 +587,7 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
vcxprojfile:leave("%s>", linkerkinds[targetinfo.targetkind])
- -- for compiler?
+ -- for C/C++ compiler?
vcxprojfile:enter("")
-- make source options
@@ -628,6 +653,17 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
end
vcxprojfile:leave("")
+
+ -- for CUDA compiler?
+ local cuda = _check_cuda(target)
+ if cuda then
+ vcxprojfile:enter("")
+
+ -- architecture
+ vcxprojfile:print("%s", targetinfo.mode:endswith("64") and "64" or "32")
+
+ vcxprojfile:leave("")
+ end
-- make custom commands
_make_custom_commands(vcxprojfile, targetinfo)
@@ -725,7 +761,12 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc
end
-- enter it
- local nodename = (sourcekind == "as" and "CustomBuild" or (sourcekind == "mrc" and "ResourceCompile" or "ClCompile"))
+ local nodename
+ if sourcekind == "as" then nodename = "CustomBuild"
+ elseif sourcekind == "mrc" then nodename = "ResourceCompile"
+ elseif sourcekind == "cu" then nodename = "CudaCompile"
+ elseif sourcekind == "cc" or sourcekind == "cxx" then nodename = "ClCompile"
+ end
sourcefile = path.relative(path.absolute(sourcefile), target.project_dir)
vcxprojfile:enter("<%s Include=\"%s\">", nodename, sourcefile)
@@ -749,7 +790,7 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc
info.mode, info.arch, objectfile)
end
- -- for *.c/cpp files
+ -- for *.c/cpp/cu files
else
-- we need use different object directory and allow parallel building
@@ -858,7 +899,12 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour
for _, info in ipairs(sourceinfo) do
-- enter it
- local nodename = (info.sourcekind == "as" and "CustomBuild" or (info.sourcekind == "mrc" and "ResourceCompile" or "ClCompile"))
+ local nodename
+ if info.sourcekind == "as" then nodename = "CustomBuild"
+ elseif info.sourcekind == "mrc" then nodename = "ResourceCompile"
+ elseif info.sourcekind == "cu" then nodename = "CudaCompile"
+ elseif info.sourcekind == "cc" or info.sourcekind == "cxx" then nodename = "ClCompile"
+ end
vcxprojfile:enter("<%s Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Include=\"%s\">",
nodename, info.mode, info.arch, sourcefile)
@@ -872,11 +918,11 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour
vcxprojfile:print("%s", compcmd)
-- for *.rc files
- elseif sourcekind == "mrc" then
+ elseif info.sourcekind == "mrc" then
vcxprojfile:print("%s",
info.mode, info.arch, objectfile)
- -- for *.c/cpp files
+ -- for *.c/cpp/cu files
else
-- we need use different object directory and allow parallel building
--
@@ -888,6 +934,7 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour
targetinfo.objectnames = hashset:new()
end
local targetinfo = info.targetinfo
+ local outputnode = (info.sourcekind == "cu" and "CompileOut" or "ObjectFileName")
if targetinfo.objectnames:has(objectname) then
vcxprojfile:print("%s",
info.mode, info.arch, objectfile)
@@ -897,7 +944,7 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour
-- disable the precompiled header if sourcekind ~= headerkind
local pcheader = target.pcxxheader or target.pcheader
- if pcheader and language.sourcekind_of(sourcefile) ~= (target.pcxxheader and "cxx" or "cc") then
+ if pcheader and info.sourcekind ~= "cu" and language.sourcekind_of(sourcefile) ~= (target.pcxxheader and "cxx" or "cc") then
vcxprojfile:print("NotUsing")
end
vcxprojfile:print("%s %%(AdditionalOptions)", os.args(info.flags))
@@ -1017,7 +1064,7 @@ function make(vsinfo, target)
_make_source_files(vcxprojfile, vsinfo, target)
-- make tailer
- _make_tailer(vcxprojfile, vsinfo)
+ _make_tailer(vcxprojfile, vsinfo, target)
-- exit solution file
vcxprojfile:close()
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
index 90253940b..fb47926ed 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
@@ -95,10 +95,15 @@ function _make_sources(filtersfile, vsinfo, target, vcxprojdir)
for _, sourcefile in ipairs(target.sourcefiles) do
local filter = _make_filter(sourcefile, target, vcxprojdir)
if filter then
- local as = sourcefile:endswith(".asm")
- filtersfile:enter("<%s Include=\"%s\">", (as and "CustomBuild" or "ClCompile"), path.relative(path.absolute(sourcefile), vcxprojdir))
+ local nodename
+ local ext = path.extension(sourcefile)
+ if ext == "asm" then nodename = "CustomBuild"
+ elseif ext == "cu" then nodename = "CudaCompile"
+ else nodename = "ClCompile"
+ end
+ filtersfile:enter("<%s Include=\"%s\">", nodename, path.relative(path.absolute(sourcefile), vcxprojdir))
filtersfile:print("%s", filter)
- filtersfile:leave("%s>", (as and "CustomBuild" or "ClCompile"))
+ filtersfile:leave("%s>", nodename)
end
local pcheader = target.pcxxheader or target.pcheader
if pcheader then
--
cgit v1.3.1