diff options
| author | ruki <[email protected]> | 2020-12-24 23:08:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-24 23:08:39 +0800 |
| commit | 70865b36f34647bda2bdd218b428bcca0cecc9da (patch) | |
| tree | 98fba7be3efef8668b971d733a07c7eb285d6163 | |
| parent | 5beced53d4ba81070c79a777ac5f5f0233e22e4e (diff) | |
add utils.compiler.runtime rule
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/mode/xmake.lua | 78 | ||||
| -rw-r--r-- | xmake/rules/utils/compiler_runtime/xmake.lua | 31 |
4 files changed, 35 insertions, 79 deletions
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 391afc4ca..115a5fbe8 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -33,7 +33,7 @@ function _get_configs(package, configs) if package:is_plat("windows") then local vs_runtime = package:config("vs_runtime") if vs_runtime then - table.insert(cxflags, "--vs_runtime=" .. vs_runtime) + table.insert(configs, "--vs_runtime=" .. vs_runtime) end end table.insert(configs, "--mode=" .. (package:debug() and "debug" or "release")) diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 926662975..1b188566a 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -48,6 +48,9 @@ rule("c++") -- add build rules add_deps("c++.build", "c.build") + -- set compiler runtime, e.g. vs runtime + add_deps("utils.compiler.runtime") + -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua index 17503802d..b4bcdfe71 100644 --- a/xmake/rules/mode/xmake.lua +++ b/xmake/rules/mode/xmake.lua @@ -34,12 +34,6 @@ rule("mode.debug") if not target:get("optimize") then target:set("optimize", "none") end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime .. "d") - end end end) @@ -68,12 +62,6 @@ rule("mode.release") if not target:get("strip") then target:set("strip", "all") end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -102,12 +90,6 @@ rule("mode.releasedbg") if not target:get("strip") then target:set("strip", "all") end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -132,12 +114,6 @@ rule("mode.minsizerel") if not target:get("strip") then target:set("strip", "all") end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -166,12 +142,6 @@ rule("mode.profile") target:add("cxflags", "-pg") target:add("mxflags", "-pg") target:add("ldflags", "-pg") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -196,12 +166,6 @@ rule("mode.coverage") target:add("cxflags", "--coverage") target:add("mxflags", "--coverage") target:add("ldflags", "--coverage") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -231,12 +195,6 @@ rule("mode.asan") target:add("mxflags", "-fsanitize=address") target:add("ldflags", "-fsanitize=address") target:add("shflags", "-fsanitize=address") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -266,12 +224,6 @@ rule("mode.tsan") target:add("mxflags", "-fsanitize=thread") target:add("ldflags", "-fsanitize=thread") target:add("shflags", "-fsanitize=thread") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -301,12 +253,6 @@ rule("mode.msan") target:add("mxflags", "-fsanitize=memory") target:add("ldflags", "-fsanitize=memory") target:add("shflags", "-fsanitize=memory") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -336,12 +282,6 @@ rule("mode.lsan") target:add("mxflags", "-fsanitize=leak") target:add("ldflags", "-fsanitize=leak") target:add("shflags", "-fsanitize=leak") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -371,12 +311,6 @@ rule("mode.ubsan") target:add("mxflags", "-fsanitize=undefined") target:add("ldflags", "-fsanitize=undefined") target:add("shflags", "-fsanitize=undefined") - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -400,12 +334,6 @@ rule("mode.valgrind") target:set("optimize", "fastest") end end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) @@ -433,11 +361,5 @@ rule("mode.check") target:add("ldflags", "-fsanitize=address") target:add("shflags", "-fsanitize=address") end - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) - end end end) diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua new file mode 100644 index 000000000..a9ca1ac49 --- /dev/null +++ b/xmake/rules/utils/compiler_runtime/xmake.lua @@ -0,0 +1,31 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define rule: utils.compiler.runtime +rule("utils.compiler.runtime") + after_load(function (target) + + -- set vs runtime + local vs_runtime = get_config("vs_runtime") + if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then + target:set("runtimes", vs_runtime .. (is_mode("debug") and "d" or "")) + end + end) + |
