From c39dadaef967d5ea5e334af442ca4c8c56959a3a Mon Sep 17 00:00:00 2001 From: 夕伽 Date: Mon, 3 Sep 2018 11:02:14 +0800 Subject: add *.rc files to vsproject --- .../plugins/project/vstudio/impl/vs200x_vcproj.lua | 79 +++++++++++++++++++--- .../project/vstudio/impl/vs201x_vcxproj.lua | 25 +++++-- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index e907f0599..2b6af017f 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -401,7 +401,7 @@ function _make_references(vcprojfile, vsinfo, target) vcprojfile:leave("") end --- make file +-- make cxfile -- -- .e.g -- -- -- -function _make_file(vcprojfile, vsinfo, target, sourcefile, objectfile, vcprojdir) +function _make_cxfile(vcprojfile, vsinfo, target, sourcefile, objectfile, vcprojdir) -- get the target key local key = tostring(target) @@ -457,6 +457,48 @@ function _make_file(vcprojfile, vsinfo, target, sourcefile, objectfile, vcprojdi vcprojfile:leave("") end +-- make file +-- +-- .e.g +-- +-- +-- +-- +-- +function _make_rcfile(vcprojfile, vsinfo, target, sourcefile, objectfile, vcprojdir) + + -- enter file + vcprojfile:enter("") + + -- add file configuration + vcprojfile:enter("") + + -- add compiling options + vcprojfile:enter("") + vcprojfile:leave("") + + -- leave file + vcprojfile:leave("") +end + -- make files -- -- .e.g @@ -492,18 +534,35 @@ function _make_files(vcprojfile, vsinfo, target, vcprojdir) -- enter files vcprojfile:enter("") - vcprojfile:enter("") - - -- add files - local objectfiles = target:objectfiles() - for idx, sourcefile in ipairs(target:sourcefiles()) do - _make_file(vcprojfile, vsinfo, target, sourcefile, objectfiles[idx], vcprojdir) + local sourcebatches = target:sourcebatches() + -- *.rc files + vcprojfile:enter("") + for sourcekind, sourcebatch in pairs(sourcebatches) do + if sourcekind ~= "mrc" then + local objectfiles = sourcebatch.objectfiles + for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do + _make_cxfile(vcprojfile, vsinfo, target, sourcefile, objectfiles[idx], vcprojdir) + end + end end -- leave files vcprojfile:leave("") + + -- *.rc files + vcprojfile:enter("") + for sourcekind, sourcebatch in pairs(sourcebatches) do + if sourcekind == "mrc" then + local objectfiles = sourcebatch.objectfiles + for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do + _make_rcfile(vcprojfile, vsinfo, target, sourcefile, objectfiles[idx], vcprojdir) + end + end + end + + -- leave *.rc files + vcprojfile:leave("") + vcprojfile:leave("") end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 547414307..575e339ae 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -416,7 +416,7 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) local first_flags = nil targetinfo.sourceflags = {} for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do - if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as") then + if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do -- make compiler flags @@ -485,8 +485,9 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc end -- enter it + local nodename = ifelse(sourcekind == "as", "CustomBuild", ifelse(sourcekind == "mrc", "ResourceCompile", "ClCompile")) sourcefile = path.relative(path.absolute(sourcefile), vcxprojdir) - vcxprojfile:enter("<%s Include=\"%s\">", ifelse(sourcekind == "as", "CustomBuild", "ClCompile"), sourcefile) + vcxprojfile:enter("<%s Include=\"%s\">", nodename, sourcefile) -- for *.asm files if sourcekind == "as" then @@ -498,6 +499,13 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc vcxprojfile:print("%s /nologo /c %s -Fo%s %s", info.mode .. '|' .. info.arch, ifelse(info.arch == "x64", "ml64", "ml"), os.args(info.flags), objectfile, sourcefile) end + -- for *.rc files + elseif sourcekind == "mrc" then + for _, info in ipairs(sourceinfo) do + local objectfile = path.relative(path.absolute(info.objectfile), vcxprojdir) + vcxprojfile:print("%s",info.mode,info.arch,objectfile) + end + -- for *.c/cpp files else @@ -582,7 +590,7 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc end -- leave it - vcxprojfile:leave("", ifelse(sourcekind == "as", "CustomBuild", "ClCompile")) + vcxprojfile:leave("", nodename) end -- make source file for specific modes @@ -593,7 +601,8 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour for _, info in ipairs(sourceinfo) do -- enter it - vcxprojfile:enter("<%s Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Include=\"%s\">", ifelse(info.sourcekind == "as", "CustomBuild", "ClCompile"), info.mode, info.arch, sourcefile) + local nodename = ifelse(info.sourcekind == "as", "CustomBuild", ifelse(info.sourcekind == "mrc", "ResourceCompile", "ClCompile")) + vcxprojfile:enter("<%s Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Include=\"%s\">", nodename, info.mode, info.arch, sourcefile) -- for *.asm files local objectfile = path.relative(path.absolute(info.objectfile), vcxprojdir) @@ -603,6 +612,10 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour vcxprojfile:print("%s", objectfile) vcxprojfile:print("%s /nologo /c %s -Fo%s %s", ifelse(info.arch == "x64", "ml64", "ml"), os.args(info.flags), objectfile, sourcefile) + -- for *.rc files + elseif sourcekind == "mrc" then + vcxprojfile:print("%s",info.mode,info.arch,objectfile) + -- for *.c/cpp files else @@ -616,7 +629,7 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour end -- leave it - vcxprojfile:leave("", ifelse(info.sourcekind == "as", "CustomBuild", "ClCompile")) + vcxprojfile:leave("", nodename) end end @@ -658,7 +671,7 @@ function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir) local sourceinfos = {} for _, targetinfo in ipairs(target.info) do for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do - if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as") then + if not sourcebatch.rulename and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then local objectfiles = sourcebatch.objectfiles for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = objectfiles[idx] -- cgit v1.3.1