diff options
| author | ruki <[email protected]> | 2024-02-22 23:37:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-22 23:37:26 +0800 |
| commit | 2104e5927ecad9eb17180590c53875e1ee15b711 (patch) | |
| tree | 57034bcd2e6e2e6f1b6660eaac0d88439c8a0811 | |
| parent | f74e4e078d63bd5a7ccf699729c9f4852a4f5e33 (diff) | |
improve to load msvc envs
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 20 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/load.lua | 36 |
2 files changed, 34 insertions, 22 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index f0786091c..4c73cd5d1 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -93,25 +93,7 @@ end -- get msvc run environments function _get_msvc_runenvs(package) - local envs = {} - local curenvs = os.getenvs() - for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do - -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. - -- @see https://github.com/xmake-io/xmake/issues/4751 - local ck_found - for ck, cv in pairs(curenvs) do - if k:lower() == ck:lower() and k ~= ck then - ck_found = ck - break - end - end - if ck_found then - envs[ck_found] = v - else - envs[k] = v - end - end - return envs + return os.joinenvs(_get_msvc(package):runenvs()) end -- get vs arch diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 51b851c00..c77132e30 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -22,9 +22,30 @@ import("core.base.option") import("core.project.config") import("detect.sdks.find_vstudio") +function _get_msvc_runenvs(package) + local envs = {} + local curenvs = os.getenvs() + for k, v in pairs(os.joinenvs(_get_msvc(package):runenvs())) do + -- fix case naming conflict for msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + local ck_found + for ck, cv in pairs(curenvs) do + if k:lower() == ck:lower() and k ~= ck then + ck_found = ck + break + end + end + if ck_found then + envs[ck_found] = v + else + envs[k] = v + end + end + return envs +end -- add the given vs environment -function _add_vsenv(toolchain, name) +function _add_vsenv(toolchain, name, curenvs) -- get vcvars local vcvars = toolchain:config("vcvars") @@ -35,6 +56,14 @@ function _add_vsenv(toolchain, name) -- get the paths for the vs environment local new = vcvars[name] if new then + -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt. + -- @see https://github.com/xmake-io/xmake/issues/4751 + for k, c in pairs(curenvs) do + if name:lower() == k:lower() and name ~= k then + name = k + break + end + end toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) end end @@ -61,12 +90,13 @@ function main(toolchain) -- add vs environments local expect_vars = {"PATH", "LIB", "INCLUDE", "LIBPATH"} + local curenvs = os.getenvs() for _, name in ipairs(expect_vars) do - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end for _, name in ipairs(find_vstudio.get_vcvars()) do if not table.contains(expect_vars, name:upper()) then - _add_vsenv(toolchain, name) + _add_vsenv(toolchain, name, curenvs) end end end |
