diff options
| author | ruki <[email protected]> | 2020-12-24 22:53:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-24 22:53:35 +0800 |
| commit | 5beced53d4ba81070c79a777ac5f5f0233e22e4e (patch) | |
| tree | b2c6aa0654e0e68a2a40dc2870928551539b9805 | |
| parent | 381e3c74967cfab1c5d42e9ee7fcb68a5a1533f7 (diff) | |
add vs_runtime config and set_runtimes api
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 1 | ||||
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/platforms/windows/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/mode/xmake.lua | 78 |
8 files changed, 99 insertions, 16 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index a9d536c68..ccb12ac7a 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -243,7 +243,7 @@ function _add_package_configurations(package) package:add("configs", "cxflags", {builtin = true, description = "Set the C/C++ compiler flags."}) package:add("configs", "cxxflags", {builtin = true, description = "Set the C++ compiler flags."}) package:add("configs", "asflags", {builtin = true, description = "Set the assembler flags."}) - package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = "MT", values = {"MT", "MD"}}) + package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = get_config("vs_runtime") or "MT", values = {"MT", "MD"}}) end -- select package version diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 76b4d0cbb..204236394 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1880,6 +1880,7 @@ function target.apis() , "target.set_warnings" , "target.set_fpmodels" , "target.set_optimize" + , "target.set_runtimes" , "target.set_languages" , "target.set_toolchains" -- target.add_xxx diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index ef324f548..f21db9e5b 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -62,6 +62,7 @@ language("c++") , "target.optimize:check" , "target.vectorexts:check" , "target.languages" + , "target.runtimes" , "target.includedirs" , "target.defines" , "target.undefines" @@ -100,6 +101,7 @@ language("c++") , "target.rpathdirs" , "target.strip" , "target.symbols" + , "target.runtimes" , "option.strip" , "option.symbols" , "option.linkdirs" @@ -130,6 +132,7 @@ language("c++") , "target.rpathdirs" , "target.strip" , "target.symbols" + , "target.runtimes" , "option.strip" , "option.symbols" , "option.linkdirs" diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index ba9e82d84..64d4d2773 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -142,8 +142,6 @@ end -- make the warning flag function nf_warning(self, level) - - -- the maps local maps = { none = "-W0" @@ -154,15 +152,11 @@ function nf_warning(self, level) , everything = "-Wall" , error = "-WX" } - - -- make it return maps[level] end -- make the optimize flag function nf_optimize(self, level) - - -- the maps local maps = { none = "-Od" @@ -171,15 +165,18 @@ function nf_optimize(self, level) , smallest = "-O1 -GL" -- /GL and (/OPT:REF is on by default in linker), we need enable /ltcg , aggressive = "-Ox -fp:fast" } - - -- make it return maps[level] end +-- make vs runtime flag +function nf_runtime(self, vs_runtime) + if vs_runtime then + return "-" .. vs_runtime + end +end + -- make the vector extension flag function nf_vectorext(self, extension) - - -- the maps local maps = { sse = "-arch:SSE" @@ -187,8 +184,6 @@ function nf_vectorext(self, extension) , avx = "-arch:AVX" , avx2 = "-arch:AVX2" } - - -- check it local flag = maps[extension] if flag and self:has_flags(flag, "cxflags") then return flag diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 844b5d67a..26abc8983 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -96,6 +96,13 @@ function nf_syslink(self, lib) return nf_link(self, lib) end +-- make vs runtime flag +function nf_runtime(self, vs_runtime) + if vs_runtime and vs_runtime:startswith("MT") then + return "-nodefaultlib:msvcrt.lib" + end +end + -- make the linkdir flag function nf_linkdir(self, dir) return "-libpath:" .. os.args(path.translate(dir)) diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 84ef7ef5b..391afc4ca 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -33,8 +33,7 @@ function _get_configs(package, configs) if package:is_plat("windows") then local vs_runtime = package:config("vs_runtime") if vs_runtime then - local vs_runtime_cxflags = "/" .. vs_runtime .. (package:debug() and "d" or "") - table.insert(cxflags, vs_runtime_cxflags) + table.insert(cxflags, "--vs_runtime=" .. vs_runtime) end end table.insert(configs, "--mode=" .. (package:debug() and "debug" or "release")) diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 2cdc04f21..5a2169e29 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -51,7 +51,7 @@ platform("windows") , " e.g. --vs_toolset=14.0" } , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio" , " e.g. --vs_sdkver=10.0.15063.0" } - , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio", + , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio" , values = {"MT", "MD"} } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua index b4bcdfe71..17503802d 100644 --- a/xmake/rules/mode/xmake.lua +++ b/xmake/rules/mode/xmake.lua @@ -34,6 +34,12 @@ 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) @@ -62,6 +68,12 @@ 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) @@ -90,6 +102,12 @@ 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) @@ -114,6 +132,12 @@ 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) @@ -142,6 +166,12 @@ 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) @@ -166,6 +196,12 @@ 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) @@ -195,6 +231,12 @@ 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) @@ -224,6 +266,12 @@ 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) @@ -253,6 +301,12 @@ 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) @@ -282,6 +336,12 @@ 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) @@ -311,6 +371,12 @@ 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) @@ -334,6 +400,12 @@ 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) @@ -361,5 +433,11 @@ 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) |
