diff options
| author | xq114 <[email protected]> | 2022-02-24 22:50:10 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2022-02-24 22:50:10 +0800 |
| commit | d1628f8c57ecc60823a5d0b59bf070cddc794443 (patch) | |
| tree | 65181ce438522154cd3249b787edaf7471f42b9e | |
| parent | a3df2d13c8da2019b254b8f8a453d04fba3ac26e (diff) | |
try to support cuda for vs generator
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 65 | ||||
| -rw-r--r-- | xmake/plugins/project/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("<Import Project=\"%$(VCTargetsPath)\\Microsoft.Cpp.targets\" />") vcxprojfile:enter("<ImportGroup Label=\"ExtensionTargets\">") + local cuda = _check_cuda(target) + if cuda then + vcxprojfile:print("<Import Project=\"%s\" />", path.join(cuda.msbuildextensionsdir, format("CUDA %s.targets", cuda.version))) + end vcxprojfile:leave("</ImportGroup>") vcxprojfile:leave("</Project>") end @@ -219,6 +240,10 @@ function _make_configurations(vcxprojfile, vsinfo, target) -- make ExtensionSettings vcxprojfile:enter("<ImportGroup Label=\"ExtensionSettings\">") + local cuda = _check_cuda(target) + if cuda then + vcxprojfile:print("<Import Project=\"%s\" />", path.join(cuda.msbuildextensionsdir, format("CUDA %s.props", cuda.version))) + end vcxprojfile:leave("</ImportGroup>") -- 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("<ClCompile>") -- make source options @@ -628,6 +653,17 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo) end vcxprojfile:leave("</ClCompile>") + + -- for CUDA compiler? + local cuda = _check_cuda(target) + if cuda then + vcxprojfile:enter("<CudaCompile>") + + -- architecture + vcxprojfile:print("<TargetMachinePlatform>%s</TargetMachinePlatform>", targetinfo.mode:endswith("64") and "64" or "32") + + vcxprojfile:leave("</CudaCompile>") + 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("<Command>%s</Command>", compcmd) -- for *.rc files - elseif sourcekind == "mrc" then + elseif info.sourcekind == "mrc" then vcxprojfile:print("<ResourceOutputFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ResourceOutputFileName>", 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("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", 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("<PrecompiledHeader>NotUsing</PrecompiledHeader>") end vcxprojfile:print("<AdditionalOptions>%s %%(AdditionalOptions)</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("<Filter>%s</Filter>", filter) - filtersfile:leave("</%s>", (as and "CustomBuild" or "ClCompile")) + filtersfile:leave("</%s>", nodename) end local pcheader = target.pcxxheader or target.pcheader if pcheader then |
