diff options
| author | ruki <[email protected]> | 2018-10-15 22:33:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-10-15 09:20:33 +0800 |
| commit | 68a27547cfdd4157162b6b536f4dc8c2c04786e8 (patch) | |
| tree | c4eb16fdc55f32b456193a809f1954b2983eb9ec | |
| parent | dc71ced53ead25ab1757d746f49a1b0d2d32263b (diff) | |
improve find_vswhere and find_vstudio
| -rw-r--r-- | xmake/modules/detect/sdks/find_vstudio.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_vswhere.lua | 4 |
2 files changed, 18 insertions, 12 deletions
diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 9baf50bc6..b4014e2d0 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -24,7 +24,7 @@ -- imports import("lib.detect.find_file") -import("detect.tools.find_vswhere") +import("lib.detect.find_tool") -- init vc variables local vcvars = {"path", @@ -190,6 +190,9 @@ function main() end end + -- find vswhere + local vswhere = find_tool("vswhere") + -- find vs2017 -> vs4.2 local results = {} for _, version in ipairs({"15.0", "14.0", "12.0", "11.0", "10.0", "9.0", "8.0", "7.1", "7.0", "6.0", "5.0", "4.2"}) do @@ -198,12 +201,11 @@ function main() -- * version > 15.0 eschews registry entries; but `vswhere` (included with version >= 15.2) can be used to find VC install path -- ref: https://github.com/Microsoft/vswhere/blob/master/README.md @@ https://archive.is/mEmdu local vswhere_VCAuxiliaryBuildDir = nil - if ((version+0) >= 15) then - local vswhere = find_vswhere() - if vswhere then - local vswhere_vrange = format("%s,%s)", version, (version+1)) - local out, err = os.iorunv(vswhere, {"-property", "installationpath", "-products", "Microsoft.VisualStudio.Product.BuildTools", "-version", vswhere_vrange}) - if out then vswhere_VCAuxiliaryBuildDir = out:trim().."\\VC\\Auxiliary\\Build" end + if ((version + 0) >= 15) and vswhere then + local vswhere_vrange = format("%s,%s)", version, (version+1)) + local result = os.iorunv(vswhere.program, {"-property", "installationpath", "-products", "Microsoft.VisualStudio.Product.BuildTools", "-version", vswhere_vrange}) + if result then + vswhere_VCAuxiliaryBuildDir = result:trim() .."\\VC\\Auxiliary\\Build" end end @@ -214,10 +216,14 @@ function main() format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC7\\bin", version), format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version), format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version), - format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version), - format("$(env %s)\\..\\..\\VC", vsenvs[version] or ""), - (vswhere_VCAuxiliaryBuildDir or "") + format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version) } + if vsenvs[version] then + table.insert(pathes, format("$(env %s)\\..\\..\\VC", vsenvs[version])) + end + if vswhere_VCAuxiliaryBuildDir and os.isdir(vswhere_VCAuxiliaryBuildDir) then + table.insert(pathes, vswhere_VCAuxiliaryBuildDir) + end -- find vcvarsall.bat, vcvars32.bat for vs7.1 local vcvarsall = find_file("vcvarsall.bat", pathes) or find_file("vcvars32.bat", pathes) diff --git a/xmake/modules/detect/tools/find_vswhere.lua b/xmake/modules/detect/tools/find_vswhere.lua index c60a7f549..cbf5efc2d 100644 --- a/xmake/modules/detect/tools/find_vswhere.lua +++ b/xmake/modules/detect/tools/find_vswhere.lua @@ -55,8 +55,8 @@ function main(opt) opt.command = "-?" opt.pathes = opt.pathes or { - path.join(os.getenv("ProgramFiles(x86)"), "Microsoft Visual Studio", "Installer", "vswhere.exe"), - path.join(os.getenv("ProgramFiles"), "Microsoft Visual Studio", "Installer", "vswhere.exe"), + "$(env ProgramFiles%(x86%))\\Microsoft Visual Studio\\Installer", + "$(env ProgramFiles)\\Microsoft Visual Studio\\Installer" } local program = find_program(opt.program or "vswhere.exe", opt) |
