diff options
| author | ruki <[email protected]> | 2022-01-07 22:30:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-01-07 22:30:49 +0800 |
| commit | 704332f0dbb224ed4ef0fb6d4096e5eaf9f3e47b (patch) | |
| tree | 8858b5cca5a364b97b72da041c7f52b3a00bf9b6 | |
| parent | a4943a509a8534cf1372b95162efd31fe532a8e5 (diff) | |
improve c++ modules
| -rw-r--r-- | xmake/core/project/target.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/xmake.lua | 16 | ||||
| -rw-r--r-- | xmake/rules/c++/openmp/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/rules/platform/windows/def/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/platform/windows/manifest/xmake.lua | 3 |
5 files changed, 15 insertions, 17 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 8ba375fb3..9a4ca698c 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -166,6 +166,7 @@ function _instance:_load_after() -- leave the environments of the target packages os.setenvs(oldenvs) + self._LOADED_AFTER = true return true end @@ -1946,8 +1947,9 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) - if not self:_is_loaded() then - os.raise("we cannot get tool(%s) before target(%s) is loaded, maybe it is called on_load() now.", toolkind, self:name()) + -- we cannot get tool in on_load, because target:toolchains() has been not checked in configuration stage. + if not self._LOADED_AFTER then + os.raise("we cannot get tool(%s) before target(%s) is loaded, maybe it is called on_load(), please call it in on_config().", toolkind, self:name()) end return toolchain.tool(self:toolchains(), toolkind, {cachekey = "target_" .. self:name(), plat = self:plat(), arch = self:arch(), before_get = function() diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 78f754521..c587a3912 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -21,7 +21,7 @@ -- define rule: c++.build.modules rule("c++.build.modules") set_extensions(".mpp", ".mxx", ".cppm", ".ixx") - after_load(function (target) + on_config(function (target) -- we disable to build across targets in parallel, because the source files may depend on other target modules -- @see https://github.com/xmake-io/xmake/issues/1858 local target_with_modules @@ -38,12 +38,11 @@ rule("c++.build.modules") -- -- maybe we will have a more fine-grained configuration strategy to disable it in the future. target:set("policy", "build.across_targets_in_parallel", false) - local _, toolname = target:tool("cxx") - if toolname:find("clang", 1, true) then + if target:has_tool("cxx", "clang", "clangxx") then import("build_modules.clang").load_parent(target, opt) - elseif toolname:find("gcc", 1, true) then + elseif target:has_tool("cxx", "gcc", "gxx") then import("build_modules.gcc").load_parent(target, opt) - elseif toolname == "cl" then + elseif target:has_tool("cxx", "cl") then import("build_modules.msvc").load_parent(target, opt) else raise("compiler(%s): does not support c++ module!", toolname) @@ -51,12 +50,11 @@ rule("c++.build.modules") end end) before_build_files(function (target, batchjobs, sourcebatch, opt) - local _, toolname = target:tool("cxx") - if toolname:find("clang", 1, true) then + if target:has_tool("cxx", "clang", "clangxx") then import("build_modules.clang").build_with_batchjobs(target, batchjobs, sourcebatch, opt) - elseif toolname:find("gcc", 1, true) then + elseif target:has_tool("cxx", "gcc", "gxx") then import("build_modules.gcc").build_with_batchjobs(target, batchjobs, sourcebatch, opt) - elseif toolname == "cl" then + elseif target:has_tool("cxx", "cl") then import("build_modules.msvc").build_with_batchjobs(target, batchjobs, sourcebatch, opt) else raise("compiler(%s): does not support c++ module!", toolname) diff --git a/xmake/rules/c++/openmp/xmake.lua b/xmake/rules/c++/openmp/xmake.lua index 47dd2d07f..82e3cc562 100644 --- a/xmake/rules/c++/openmp/xmake.lua +++ b/xmake/rules/c++/openmp/xmake.lua @@ -20,12 +20,12 @@ -- define rule: c.openmp rule("c.openmp") - on_load(function (target) + on_config(function (target) import("load")(target, "cc") end) -- define rule: c++.openmp rule("c++.openmp") - on_load(function (target) + on_config(function (target) import("load")(target, "cxx") end) diff --git a/xmake/rules/platform/windows/def/xmake.lua b/xmake/rules/platform/windows/def/xmake.lua index 06e960380..7919553de 100644 --- a/xmake/rules/platform/windows/def/xmake.lua +++ b/xmake/rules/platform/windows/def/xmake.lua @@ -22,8 +22,7 @@ rule("platform.windows.def") set_extensions(".def") on_config("windows", function (target) - local _, toolname = target:tool("ld") - if toolname == "link" then + if target:has_tool("ld", "link") then for _, sourcebatch in pairs(target:sourcebatches()) do if sourcebatch.rulename == "platform.windows.def" then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index efb750edd..b476faeed 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -23,8 +23,7 @@ rule("platform.windows.manifest") set_extensions(".manifest") on_config("windows", function (target) - local _, toolname = target:tool("ld") - if toolname == "link" then + if target:has_tool("ld", "link") then local manifest = false for _, sourcebatch in pairs(target:sourcebatches()) do if sourcebatch.rulename == "platform.windows.manifest" then |
