diff options
| author | ruki <[email protected]> | 2024-09-16 22:41:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-09-16 22:41:32 +0800 |
| commit | be182710a90a20276ac7f2ff76547ddf8e63254e (patch) | |
| tree | 15f64da10c2746bd7ffd9352ee011f86a4639317 | |
| parent | 95db53c2338b030d0dd99620d388882a3faeb653 (diff) | |
switch to MT runtime
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 48339fef3..307d1620a 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -597,7 +597,11 @@ function _finish_requireinfo(requireinfo, package) runtimes = {} end if not table.contains(runtimes, "MT", "MD", "MTd", "MDd") then - table.insert(runtimes, "MT") + local vs_runtime_default = project.policy("build.c++.msvc.runtime") + if vs_runtime_default and is_mode("debug") then + vs_runtime_default = vs_runtime_default .. "d" + end + table.insert(runtimes, vs_runtime_default or "MT") end requireinfo.configs.runtimes = table.concat(runtimes, ",") end diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 49e1963a9..432d37855 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -35,10 +35,21 @@ rule("c++.build") add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization", "c++.build.sanitizer") on_build_files("private.action.build.object", {batch = true, distcc = true}) on_config(function (target) - -- we enable c++ exceptions by default + -- enable c++ exceptions by default if target:is_plat("windows") and not target:get("exceptions") then target:set("exceptions", "cxx") end + -- enable vs runtime as MD by default + if target:is_plat("windows") and not target:get("runtimes") then + local vs_runtime_default = target:policy("build.c++.msvc.runtime") + if vs_runtime_default and vs_runtime_default == "MD" and target:has_tool("cxx", "cl", "clang_cl") then + if is_mode("debug") then + target:set("runtimes", "MDd") + else + target:set("runtimes", "MD") + end + end + end -- https://github.com/xmake-io/xmake/issues/4621 if target:is_plat("windows") and target:is_static() and target:has_tool("cxx", "tcc") then target:set("extension", ".a") |
