summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-28 14:24:42 +0800
committerruki <[email protected]>2018-04-28 14:24:42 +0800
commita39107c492d254b4b2c26be69956c61a42e21702 (patch)
tree473ddec55403569b3ffe822457a5a901d5ac5b4f /xmake/modules
parentece589bf99c7d1e83c58a4a8f44a02a09801e0fb (diff)
fix ucrt version for find_vstudio
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/sdks/find_vstudio.lua56
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua114
2 files changed, 158 insertions, 12 deletions
diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua
index 0d8d7a1fd..f5a122b58 100644
--- a/xmake/modules/detect/sdks/find_vstudio.lua
+++ b/xmake/modules/detect/sdks/find_vstudio.lua
@@ -25,6 +25,21 @@
-- imports
import("lib.detect.find_file")
+-- init vc variables
+local vcvars = {"path",
+ "lib",
+ "libpath",
+ "include",
+ "DevEnvdir",
+ "VSInstallDir",
+ "VCInstallDir",
+ "WindowsSdkDir",
+ "WindowsLibPath",
+ "WindowsSDKVersion",
+ "WindowsSdkBinPath",
+ "UniversalCRTSdkDir",
+ "UCRTVersion"}
+
-- load vcvarsall environment variables
function _load_vcvarsall(vcvarsall, arch)
@@ -35,13 +50,9 @@ function _load_vcvarsall(vcvarsall, arch)
file:print("@echo off")
file:print("call \"%s\" %s > nul", vcvarsall, arch)
file:print("echo { > %s", genvcvars_dat)
- file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat)
- file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat)
- file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat)
- file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat)
- file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat)
- file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat)
- file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat)
+ for idx, var in ipairs(vcvars) do
+ file:print("echo " .. (idx == 1 and "" or ",") .. " " .. var .. " = \"%%" .. var .. "%%\" >> %s", genvcvars_dat)
+ end
file:print("echo } >> %s", genvcvars_dat)
file:close()
@@ -58,16 +69,37 @@ function _load_vcvarsall(vcvarsall, arch)
end
-- remove some empty entries
- for _, name in ipairs({"path", "lib", "libpath", "include", "devenvdir", "vsinstalldir", "vcinstalldir"}) do
+ for _, name in ipairs(vcvars) do
if variables[name] and #variables[name]:trim() == 0 then
variables[name] = nil
end
end
- -- get sdk version
- local include = variables["include"]
- if include then
- variables["sdkver"] = include:match("Windows Kits\\%d+\\include\\(%d+%.%d+%.%d+%.%d+)\\")
+ -- fix WindowsSDKVersion
+ local WindowsSDKVersion = variables["WindowsSDKVersion"]
+ if WindowsSDKVersion then
+ WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim()
+ variables["WindowsSDKVersion"] = WindowsSDKVersion
+ end
+
+ -- fix UCRTVersion
+ --
+ -- @note vcvarsall.bat maybe detect error if install WDK and SDK at same time (multi-sdk version exists in include directory).
+ --
+ local UCRTVersion = variables["UCRTVersion"]
+ if UCRTVersion and UCRTVersion ~= WindowsSDKVersion then
+ local lib = variables["lib"]
+ if lib then
+ lib = lib:gsub(UCRTVersion, WindowsSDKVersion)
+ variables["lib"] = lib
+ end
+ local include = variables["include"]
+ if include then
+ include = include:gsub(UCRTVersion, WindowsSDKVersion)
+ variables["include"] = include
+ end
+ UCRTVersion = WindowsSDKVersion
+ variables["UCRTVersion"] = UCRTVersion
end
-- ok
diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua
new file mode 100644
index 000000000..c05925946
--- /dev/null
+++ b/xmake/modules/detect/sdks/find_wdk.lua
@@ -0,0 +1,114 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_wdk.lua
+--
+
+-- imports
+import("lib.detect.cache")
+import("lib.detect.find_file")
+import("core.base.option")
+import("core.base.global")
+import("core.project.config")
+
+-- find WDK directory
+function _find_sdkdir(sdkdir, sdkver)
+
+end
+
+-- find WDK toolchains
+function _find_wdk(sdkdir, sdkver)
+
+ -- find wdk directory
+ sdkdir = _find_sdkdir(sdkdir, sdkver)
+ if not sdkdir or not os.isdir(sdkdir) then
+ return nil
+ end
+
+ -- get the bin directory
+ local bindir = path.join(sdkdir, "bin")
+
+ -- get linkdirs
+ local linkdirs = {path.join(sdkdir, "lib")}
+
+ -- get includedirs
+ local includedirs = {path.join(sdkdir, "include")}
+
+ -- get sdk version
+ sdkver = sdkver or sdkdir:match("(%d+%.?%d*%.?%d*.-)")
+
+ -- get toolchains
+ return {sdkdir = sdkdir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs, sdkver = sdkver}
+end
+
+-- find WDK toolchains
+--
+-- @param sdkdir the WDK directory
+-- @param opt the argument options, .e.g {verbose = true, force = false, version = "5.9.1"}
+--
+-- @return the WDK toolchains. .e.g {sdkver = ..., sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. }
+--
+-- @code
+--
+-- local toolchains = find_wdk("~/wdk")
+--
+-- @endcode
+--
+function main(sdkdir, opt)
+
+ -- init arguments
+ opt = opt or {}
+
+ -- attempt to load cache first
+ local key = "detect.sdks.find_wdk." .. (sdkdir or "")
+ local cacheinfo = cache.load(key)
+ if not opt.force and cacheinfo.wdk then
+ return cacheinfo.wdk
+ end
+
+ -- find wdk
+ local wdk = _find_wdk(sdkdir or config.get("wdk") or global.get("wdk"), opt.version or config.get("wdk_sdkver"))
+ if wdk then
+
+ -- save to config
+ config.set("wdk", wdk.sdkdir, {force = true, readonly = true})
+ config.set("wdk_sdkver", wdk.sdkver, {force = true, readonly = true})
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the WDK directory ... ${green}%s", wdk.sdkdir)
+ cprint("checking for the WDK version ... ${green}%s", wdk.sdkver)
+ end
+ else
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the WDK directory ... ${red}no")
+ end
+ end
+
+ -- save to cache
+ cacheinfo.wdk = wdk or false
+ cache.save(key, cacheinfo)
+
+ -- ok?
+ return wdk
+end