summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-16 00:31:24 +0800
committerruki <[email protected]>2022-08-16 00:31:24 +0800
commit2e502f66692119189c7425a2f7a412942d3a992a (patch)
tree8adc1be801ce268e275e62c9c2c1a87eb01ac611
parent39981ebf8e9e5cdbe9103c7019957a04485a4444 (diff)
improve cmake and vs generator
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua2
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua6
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua21
3 files changed, 17 insertions, 12 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index aae7186a2..130c1ad38 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -114,7 +114,7 @@ end
function _sourcebatch_is_built(sourcebatch)
-- we can only use rulename to filter them because sourcekind may be bound to multiple rules
local rulename = sourcebatch.rulename
- if rulename == "c++.build" or rulename == "asm.build" or rulename == "cuda.build" then
+ if rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or rulename == "cuda.build" then
return true
end
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index dbeb9a9b5..ce843d725 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -213,8 +213,9 @@ function _make_custom_commands(target, vcxprojdir)
_make_custom_commands_for_target(commands, target, vcxprojdir, "before")
_make_custom_commands_for_target(commands, target, vcxprojdir)
for _, sourcebatch in pairs(target:sourcebatches()) do
+ local rulename = sourcebatch.rulename
local sourcekind = sourcebatch.sourcekind
- if sourcekind ~= "cc" and sourcekind ~= "cxx" and sourcekind ~= "as" then
+ if rulename ~= "c.build" and rulename ~= "c++.build" and rulename ~= "asm.build" and rulename ~= "cuda.build" and sourcekind ~= "mrc" then
_make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, "before")
_make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, nil)
_make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, "after")
@@ -281,10 +282,11 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
targetinfo.compargvs = {}
for _, sourcebatch in pairs(target:sourcebatches()) do
local sourcekind = sourcebatch.sourcekind
+ local rulename = sourcebatch.rulename
if sourcekind then
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind})
- if not firstcompflags and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "cu") then
+ if not firstcompflags and (rulename == "c.build" or rulename == "c++.build" or rulename == "cuda.build") then
firstcompflags = compflags
end
targetinfo.compflags[sourcefile] = compflags
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index 452292abc..f9842bff1 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -713,18 +713,18 @@ function _make_custom_commands_item(vcxprojfile, commands, suffix)
vcxprojfile:print("<PreLinkEvent>")
end
vcxprojfile:print("<Message></Message>")
- vcxprojfile:print("<Command>setlocal")
+ local cmdstr = "setlocal"
for _, command in ipairs(commands) do
- vcxprojfile:print("%s", command)
+ cmdstr = cmdstr .. "\n" .. command
+ cmdstr = cmdstr .. "\nif %errorlevel% neq 0 goto :xmEnd"
end
- vcxprojfile:write([[if %errorlevel% neq 0 goto :xmEnd
-:xmEnd
+ cmdstr = cmdstr .. "\n" .. [[:xmEnd
endlocal &amp; call :xmErrorLevel %errorlevel% &amp; goto :xmDone
:xmErrorLevel
exit /b %1
:xmDone
-if %errorlevel% neq 0 goto :VCEnd</Command>
-]])
+if %errorlevel% neq 0 goto :VCEnd]]
+ vcxprojfile:print("<Command>%s</Command>", cmdstr)
if suffix == "after" or suffix == "after_link" then
vcxprojfile:print("</PostBuildEvent>")
elseif suffix == "before" then
@@ -957,7 +957,8 @@ function _build_common_items(vsinfo, target)
targetinfo.sourceflags = {}
for _, sourcebatch in pairs(targetinfo.sourcebatches) do
local sourcekind = sourcebatch.sourcekind
- if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then
+ local rulename = sourcebatch.rulename
+ if (rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or sourcekind == "mrc") then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
-- make compiler flags
@@ -1020,12 +1021,13 @@ function _build_common_items(vsinfo, target)
local sourceflags = {}
for _, sourcebatch in pairs(targetinfo.sourcebatches) do
local sourcekind = sourcebatch.sourcekind
+ local rulename = sourcebatch.rulename
if (sourcekind == "as" or sourcekind == "mrc") then
-- no common flags for as/mrc files
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
sourceflags[sourcefile] = targetinfo.sourceflags[sourcefile]
end
- elseif (sourcekind == "cc" or sourcekind == "cxx") then
+ elseif rulename == "c.build" or rulename == "c++.build" then -- sourcekind maybe bind multiple rules, e.g. c++modules
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local flags = targetinfo.sourceflags[sourcefile]
local otherflags = {}
@@ -1313,7 +1315,8 @@ function _make_source_files(vcxprojfile, vsinfo, target)
for _, targetinfo in ipairs(target.info) do
for _, sourcebatch in pairs(targetinfo.sourcebatches) do
local sourcekind = sourcebatch.sourcekind
- if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc" or sourcekind == "cu") then
+ local rulename = sourcebatch.rulename
+ if (rulename == "c.build" or rulename == "c++.build" or sourcekind == "as" or sourcekind == "mrc" or sourcekind == "cu") then
local objectfiles = sourcebatch.objectfiles
for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
local objectfile = objectfiles[idx]