diff options
| author | ruki <[email protected]> | 2022-08-04 22:37:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-08-04 22:37:59 +0800 |
| commit | 0e52b4967cd20677c1dcc7656e2016c076ed2647 (patch) | |
| tree | 67d13c3ee93e036a3429c269b9578a3ddaab625b | |
| parent | cc8ee163098a464937769641377fd98c33bdfca2 (diff) | |
improve load modules
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/common.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/gcc.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/xmake.lua | 9 |
5 files changed, 26 insertions, 41 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index e1e136c97..04ea0ab6e 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -27,20 +27,8 @@ import("utils.progress") import("private.action.build.object", {alias = "objectbuilder"}) import("common") --- load parent target with modules files -function load_parent(target, opt) - local cachedir = common.modules_cachedir(target) - - local prebuiltmodulepathflag = get_prebuiltmodulepathflag(target) - - for _, dep in ipairs(target:orderdeps()) do - cachedir = common.modules_cachedir(dep) - target:add("cxxflags", prebuiltmodulepathflag .. cachedir, {force = true}) - end -end - --- check C++20 module support -function check_module_support(target) +-- load module support for the current target +function load(target) local compinst = compiler.load("cxx", {target = target}) local cachedir = common.modules_cachedir(target) local stlcachedir = common.stlmodules_cachedir(target) @@ -57,8 +45,14 @@ function check_module_support(target) -- add the module cache directory target:add("cxxflags", implicitmodulesflag, {force = true}) target:add("cxxflags", implicitmodulemapsflag, {force = true}) - target:add("cxxflags", prebuiltmodulepathflag .. cachedir, prebuiltmodulepathflag .. stlcachedir, {force = true}) + + -- add module cachedirs of all dependent targets with modules + -- this target maybe does not contain module files + for _, dep in ipairs(target:orderdeps()) do + cachedir = common.modules_cachedir(dep) + target:add("cxxflags", prebuiltmodulepathflag .. cachedir, {force = true}) + end end function toolchain_include_directories(target) diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 57b9c0c7c..ae3de7493 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -108,7 +108,7 @@ function contains_modules(target) end -- load module infos -function load(target, sourcebatch, opt) +function load_moduleinfos(target, sourcebatch, opt) local moduleinfos for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local dependfile = target:dependfile(sourcefile) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 9812115b8..fc346d753 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -52,12 +52,8 @@ function add_module_to_mapper(file, module, bmi) return true end --- load parent target with modules files -function load_parent(target, opt) -end - --- check C++20 module support -function check_module_support(target) +-- load module support for the current target +function load(target) local compinst = compiler.load("cxx", {target = target}) local modulesflag = get_modulesflag(target) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index c7a6f6c15..98d244626 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -14,7 +14,7 @@ -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- --- @author ruki +-- @author ruki, Arthapz -- @file msvc.lua -- @@ -26,18 +26,8 @@ import("utils.progress") import("private.action.build.object", {alias = "objectbuilder"}) import("common") --- load parent target with modules files -function load_parent(target, opt) - local ifcsearchdirflag = get_ifcsearchdirflag(target) - - for _, dep in ipairs(target:orderdeps()) do - cachedir = common.modules_cachedir(dep) - target:add("cxxflags", {ifcsearchdirflag, cachedir}, {force = true, expand = false}) - end -end - --- check C++20 module support -function check_module_support(target) +-- load module support for the current target +function load(target) local compinst = target:compiler("cxx") local cachedir = common.modules_cachedir(target) local stlcachedir = common.stlmodules_cachedir(target) @@ -65,6 +55,14 @@ function check_module_support(target) break end end + + -- add module cachedirs of all dependent targets with modules + -- this target maybe does not contain module files + local ifcsearchdirflag = get_ifcsearchdirflag(target) + for _, dep in ipairs(target:orderdeps()) do + cachedir = common.modules_cachedir(dep) + target:add("cxxflags", {ifcsearchdirflag, cachedir}, {force = true, expand = false}) + end end -- provide toolchain include dir for stl headerunit when p1689 is not supported diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 7b6697eeb..9a7599358 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -41,14 +41,11 @@ rule("c++.build.modules") -- get modules support local modules_support = common.modules_support(target) - -- check C++20 module support - modules_support.check_module_support(target) + -- load module support + modules_support.load(target) -- mark this target with modules target:data_set("cxx.has_modules", true) - - -- load parent - modules_support.load_parent(target, opt) end end) @@ -69,7 +66,7 @@ rule("c++.build.modules.dependencies") modules_support.generate_dependencies(target, sourcebatch, opt) -- load and parse module dependencies - local moduleinfos = common.load(target, sourcebatch, opt) + local moduleinfos = common.load_moduleinfos(target, sourcebatch, opt) local modules = common.parse_dependency_data(target, moduleinfos, opt) target:data_set("cxx.modules", modules) end) |
