summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-02-07 16:56:02 +0100
committerArthur LAURENT <[email protected]>2024-02-07 18:04:29 +0100
commit6e3d6c4cf7166e093ba77fac1d221ff6daef1792 (patch)
tree1f6f4164c145d0ab90641af56aa1d4350ac46f70
parent6f520cf8320ddb4424560b9094fb74844dd8e40b (diff)
update vs project generator to support moduleonly target kind
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua20
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua35
-rw-r--r--xmake/rules/c++/modules/modules_support/dependency_scanner.lua1
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc/builder.lua6
-rw-r--r--xmake/rules/c++/modules/xmake.lua2
5 files changed, 44 insertions, 20 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index a8b48dada..d67a3f7a3 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -185,7 +185,6 @@ function _make_custom_commands_for_objectrules(commands, target, sourcebatch, vc
scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "")
script = ruleinst:script(scriptname)
if script then
- local sourcekind = sourcebatch.sourcekind
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local batchcmds_ = batchcmds.new({target = target})
script(target, batchcmds_, sourcefile, {})
@@ -219,7 +218,7 @@ function _make_custom_commands(target, vcxprojdir)
for _, sourcebatch in table.orderpairs(sourcebatches) do
local rulename = sourcebatch.rulename
local sourcekind = sourcebatch.sourcekind
- if rulename ~= "c.build" and rulename ~= "c++.build" and rulename ~= "asm.build" and rulename ~= "cuda.build" and sourcekind ~= "mrc" then
+ if rulename ~= "c.build" and rulename ~= "c++.build" and not rulename:startswith("c++.build.modules") 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")
@@ -256,6 +255,9 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
-- save symbols
targetinfo.symbols = target:get("symbols")
+ -- has modules
+ targetinfo.has_modules = target:data("cxx.has_modules")
+
-- save target kind
targetinfo.targetkind = target:kind()
if target:is_phony() or target:is_headeronly() then
@@ -268,9 +270,6 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
-- save symbol file
targetinfo.symbolfile = target:symbolfile()
- -- save sourcebatches
- targetinfo.sourcebatches = target:sourcebatches()
-
-- save sourcekinds
targetinfo.sourcekinds = target:sourcekinds()
@@ -289,9 +288,9 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
local sourcekind = sourcebatch.sourcekind
local rulename = sourcebatch.rulename
if sourcekind then
- for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind})
- if not firstcompflags and (rulename == "c.build" or rulename == "c++.build" or rulename == "cuda.build") then
+ if not firstcompflags and (rulename == "c.build" or rulename == "c++.build" or rulename == "c++.build.modules" or rulename == "cuda.build") then
firstcompflags = compflags
end
targetinfo.compflags[sourcefile] = compflags
@@ -309,8 +308,11 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
end
end
+ -- save sourcebatches
+ targetinfo.sourcebatches = target:sourcebatches()
+
-- save linker flags
- local linkflags = linker.linkflags(target:kind(), target:sourcekinds(), {target = target})
+ local linkflags = linker.linkflags(target:is_moduleonly() and 'static' or target:kind(), target:sourcekinds(), {target = target})
targetinfo.linkflags = linkflags
if table.contains(target:sourcekinds(), "cu") then
@@ -323,7 +325,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir)
end
-- save execution dir (when executed from VS)
- targetinfo.rundir = target:rundir()
+ targetinfo.rundir = target:is_moduleonly() and "" or target:rundir()
-- save runenvs
local targetrunenvs = {}
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index f5bb88d73..56850bbe3 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -242,6 +242,7 @@ function _make_configurations(vcxprojfile, vsinfo, target)
binary = "Application"
, shared = "DynamicLibrary"
, static = "StaticLibrary"
+ , moduleonly = "StaticLibrary" -- emulate moduleonly with staticlib
}
-- make ProjectConfigurations
@@ -307,8 +308,10 @@ function _make_configurations(vcxprojfile, vsinfo, target)
vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch)
vcxprojfile:print("<OutDir>%s\\</OutDir>", _make_dirs(targetinfo.targetdir, target.project_dir))
vcxprojfile:print("<IntDir>%s\\</IntDir>", _make_dirs(targetinfo.objectdir, target.project_dir))
- vcxprojfile:print("<TargetName>%s</TargetName>", path.basename(targetinfo.targetfile))
- vcxprojfile:print("<TargetExt>%s</TargetExt>", path.extension(targetinfo.targetfile))
+ if targetinfo.targetfile then
+ vcxprojfile:print("<TargetName>%s</TargetName>", path.basename(targetinfo.targetfile))
+ vcxprojfile:print("<TargetExt>%s</TargetExt>", path.extension(targetinfo.targetfile))
+ end
if target.kind == "binary" then
vcxprojfile:print("<LinkIncremental>true</LinkIncremental>")
@@ -723,7 +726,7 @@ endlocal &amp; call :xmErrorLevel %errorlevel% &amp; goto :xmDone
exit /b %1
:xmDone
if %errorlevel% neq 0 goto :VCEnd]]
- vcxprojfile:print("<Command>%s</Command>", cmdstr)
+ vcxprojfile:print("<Command>%s</Command>", cmdstr:replace("<", " &lt;"):replace(">", "&gt;"):replace("/Fo ", "/Fo"))
if suffix == "after" or suffix == "after_link" then
vcxprojfile:print("</PostBuildEvent>")
elseif suffix == "before" then
@@ -742,12 +745,12 @@ end
-- make common item
function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
-
-- init the linker kinds
local linkerkinds =
{
binary = "Link"
, static = "Lib"
+ , moduleonly = "Lib" -- emulate moduleonly with staticlib
, shared = "Link"
}
if not linkerkinds[targetinfo.targetkind] then
@@ -892,6 +895,10 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
vcxprojfile:print("<LanguageStandard_C>%s</LanguageStandard_C>", cstandard)
end
+ if targetinfo.has_modules then
+ vcxprojfile:enter("<ScanSourceForModuleDependencies>true</ScanSourceForModuleDependencies>")
+ end
+
-- use c or c++ precompiled header
local pcheader = target.pcxxheader or target.pcheader
if pcheader then
@@ -959,9 +966,8 @@ function _build_common_items(vsinfo, target)
for _, sourcebatch in pairs(targetinfo.sourcebatches) do
local sourcekind = sourcebatch.sourcekind
local rulename = sourcebatch.rulename
- if (rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or sourcekind == "mrc") then
+ if (rulename == "c.build" or rulename == "c++.build" or rulename == "c++.build.modules" or rulename == "asm.build" or sourcekind == "mrc") then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
-
-- make compiler flags
local flags = _make_compflags(sourcefile, targetinfo, target.project_dir)
@@ -1028,7 +1034,7 @@ function _build_common_items(vsinfo, target)
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
sourceflags[sourcefile] = targetinfo.sourceflags[sourcefile]
end
- elseif rulename == "c.build" or rulename == "c++.build" then -- sourcekind maybe bind multiple rules, e.g. c++modules
+ elseif rulename == "c.build" or rulename == "c++.build" or rulename == "c++.build.modules" then -- sourcekind maybe bind multiple rules, e.g. c++modules
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local flags = targetinfo.sourceflags[sourcefile]
local otherflags = {}
@@ -1062,7 +1068,7 @@ function _make_common_items(vcxprojfile, vsinfo, target)
-- for each mode and arch
for _, targetinfo in ipairs(target.info) do
-- make common item
- _make_common_item(vcxprojfile, vsinfo, target, targetinfo, target.project_dir)
+ _make_common_item(vcxprojfile, vsinfo, target, targetinfo)
end
end
@@ -1325,6 +1331,19 @@ function _make_source_files(vcxprojfile, vsinfo, target)
sourceinfos[sourcefile] = sourceinfos[sourcefile] or {}
table.insert(sourceinfos[sourcefile], {targetinfo = targetinfo, mode = targetinfo.mode, arch = targetinfo.arch, sourcekind = sourcekind, objectfile = objectfile, flags = flags, compargv = targetinfo.compargvs[sourcefile]})
end
+ elseif rulename == "c++.build.modules" then
+ local builder_batch = targetinfo.sourcebatches["c++.build.modules.builder"]
+ table.sort(builder_batch.objectfiles)
+ local objectfiles = builder_batch.objectfiles
+ for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local is_named_module = table.contains(builder_batch.sourcefiles, sourcefile)
+ if is_named_module then
+ local objectfile = objectfiles[idx]
+ local flags = targetinfo.sourceflags[sourcefile]
+ sourceinfos[sourcefile] = sourceinfos[sourcefile] or {}
+ table.insert(sourceinfos[sourcefile], {targetinfo = targetinfo, mode = targetinfo.mode, arch = targetinfo.arch, sourcekind = "cxx", objectfile = objectfile, flags = flags, compargv = targetinfo.compargvs[sourcefile]})
+ end
+ end
end
end
end
diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
index 0b02292ef..1dc55bcb8 100644
--- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
@@ -224,6 +224,7 @@ function _generate_dependencies(target, sourcebatch, opt)
end
-- get module dependencies
function get_module_dependencies(target, sourcebatch, opt)
+ print(sourcebatch)
local cachekey = target:name() .. "/" .. sourcebatch.rulename
local modules = compiler_support.memcache():get2("modules", cachekey)
if modules == nil or opt.regenerate then
diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
index fad853577..015e04db5 100644
--- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
@@ -41,7 +41,7 @@ function _make_modulebuildflags(target, provide, bmifile, opt)
local flags
if provide then -- named module
- flags = table.join({"-TP", ifcoutputflag, bmifile, provide.interface and interfaceflag or internalpartitionflag}, ifconly or {})
+ flags = table.join({"-TP", ifcoutputflag, path(bmifile), provide.interface and interfaceflag or internalpartitionflag}, ifconly or {})
else
flags = {"-TP"}
end
@@ -102,8 +102,8 @@ function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile)
opt = opt or {}
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
- flags = table.join("-c", compflags or {}, flags, {"/Fo", outputfile, sourcefile})
- batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
+ flags = table.join(compflags or {}, flags)
+ batchcmds:compile(sourcefile, outputfile, {sourcekind = "cxx", compflags = flags})
end
-- get module requires flags
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 13fb405d8..922841cd1 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -101,6 +101,7 @@ rule("c++.build.modules.builder")
end
end
+ opt = opt or {}
opt.batchjobs = true
compiler_support.patch_sourcebatch(target, sourcebatch, opt)
@@ -163,6 +164,7 @@ rule("c++.build.modules.builder")
end
end
+ opt = opt or {}
opt.batchjobs = false
compiler_support.patch_sourcebatch(target, sourcebatch, opt)