diff options
| author | ruki <[email protected]> | 2024-02-22 17:13:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-22 17:13:28 +0800 |
| commit | 67412d490d1e88a17b4e873de75ae19c284cb7bc (patch) | |
| tree | d174354e0597def09fdc60e97f13328cb93b7233 | |
| parent | 91255a64bce02ee61600271b49964ed9c65727f2 (diff) | |
| parent | e283b55ac049f45685d78399f50178cdb03f448d (diff) | |
Merge pull request #4759 from xmake-io/msvc
Fix msvc envs for tools.cmake
| -rw-r--r-- | xmake/toolchains/clang-cl/load.lua | 15 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/load.lua | 15 |
2 files changed, 24 insertions, 6 deletions
diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua index 3b0da0e0a..3763b8d2e 100644 --- a/xmake/toolchains/clang-cl/load.lua +++ b/xmake/toolchains/clang-cl/load.lua @@ -24,7 +24,7 @@ import("core.project.config") import("detect.sdks.find_vstudio") -- 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 +35,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 @@ -57,12 +65,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 diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 51b851c00..90aec06a9 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -24,7 +24,7 @@ import("core.project.config") import("detect.sdks.find_vstudio") -- 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 +35,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 +69,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 |
