From 1b2a5da03aea8f9082204c345e852ee69bd6cec4 Mon Sep 17 00:00:00 2001 From: Ângelo Andrade Cirino Date: Mon, 17 Jan 2022 15:49:50 -0300 Subject: Solved building submodules with clang --- xmake/rules/c++/modules/build_modules/clang.lua | 11 +++++++++-- xmake/rules/c++/modules/build_modules/module_parser.lua | 9 +++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/xmake/rules/c++/modules/build_modules/clang.lua b/xmake/rules/c++/modules/build_modules/clang.lua index 523c61ad9..49ae5b2de 100644 --- a/xmake/rules/c++/modules/build_modules/clang.lua +++ b/xmake/rules/c++/modules/build_modules/clang.lua @@ -89,7 +89,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) local sourcefiles_total = #sourcebatch.sourcefiles for i = 1, sourcefiles_total do local sourcefile = sourcebatch.sourcefiles[i] - local moduledep = assert(moduledeps_files[sourcefile], "moduledep(%s) not found!", sourcefile) + local moduledep = moduledeps_files[sourcefile] or {} moduledep.job = batchjobs:newjob(sourcefile, function (index, total) -- compile module files to *.pcm @@ -100,6 +100,14 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) opt2.objectfile = modulefiles[i] opt2.dependfile = target:dependfile(opt2.objectfile) opt2.sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile) + if moduledep["deps"] then + for _, modulefile in ipairs(modulefiles) do + local found = modulefile:find(moduledep["name"]) + if found == nil then + target:add("cxxflags", "-fmodule-file=" .. modulefile, {force = true}) + end + end + end objectbuilder.build_object(target, sourcefile, opt2) -- compile *.pcm to object files @@ -136,4 +144,3 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt) end end end - diff --git a/xmake/rules/c++/modules/build_modules/module_parser.lua b/xmake/rules/c++/modules/build_modules/module_parser.lua index b97b7e1d0..881f2b48f 100644 --- a/xmake/rules/c++/modules/build_modules/module_parser.lua +++ b/xmake/rules/c++/modules/build_modules/module_parser.lua @@ -84,15 +84,16 @@ function load(target, sourcebatch, opt) generate(target, sourcebatch, opt) -- load deps - local moduledeps + local moduledeps = moduledeps or {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local dependfile = _get_dependfile_of_modulesource(target, sourcefile) if os.isfile(dependfile) then local data = io.load(dependfile) if data then - local moduleinfo = data.moduleinfo - moduledeps = moduledeps or {} - moduledeps[moduleinfo.name] = moduleinfo + if data.moduleinfo then + local moduleinfo = data.moduleinfo + moduledeps[moduleinfo.name] = moduleinfo + end end end end -- cgit v1.3.1