summaryrefslogtreecommitdiff
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
parentece589bf99c7d1e83c58a4a8f44a02a09801e0fb (diff)
fix ucrt version for find_vstudio
-rw-r--r--README_zh.md24
-rw-r--r--tests/projects/wdk/kmdf/ioctl/xmake.lua25
-rw-r--r--tests/projects/wdk/umdf/echo/xmake.lua25
-rw-r--r--xmake/modules/detect/sdks/find_vstudio.lua56
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua114
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua2
-rw-r--r--xmake/rules/qt/xmake.lua15
-rw-r--r--xmake/rules/wdk/xmake.lua61
8 files changed, 280 insertions, 42 deletions
diff --git a/README_zh.md b/README_zh.md
index 6b24d654e..432748b8b 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -320,28 +320,8 @@ or xmake macro --help
## 简单例子
```c
--- the debug mode
-if is_mode("debug") then
-
- -- enable the debug symbols
- set_symbols("debug")
-
- -- disable optimization
- set_optimize("none")
-end
-
--- the release mode
-if is_mode("release") then
-
- -- set the symbols visibility: hidden
- set_symbols("hidden")
-
- -- enable fastest optimization
- set_optimize("fastest")
-
- -- strip all symbols
- set_strip("all")
-end
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
-- add target
target("test")
diff --git a/tests/projects/wdk/kmdf/ioctl/xmake.lua b/tests/projects/wdk/kmdf/ioctl/xmake.lua
new file mode 100644
index 000000000..33b446f0d
--- /dev/null
+++ b/tests/projects/wdk/kmdf/ioctl/xmake.lua
@@ -0,0 +1,25 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("nonpnp")
+
+ -- add rules
+ add_rules("wdk.driver.kmdf")
+
+ -- add files
+ add_files("driver/*.c")
+
+-- add target
+target("app")
+
+ -- add deps
+ add_deps("nonpnp")
+
+ -- add rules
+ add_rules("wdk.binary")
+
+ -- add files
+ add_files("exe/*.c")
+
diff --git a/tests/projects/wdk/umdf/echo/xmake.lua b/tests/projects/wdk/umdf/echo/xmake.lua
new file mode 100644
index 000000000..3dd38ee62
--- /dev/null
+++ b/tests/projects/wdk/umdf/echo/xmake.lua
@@ -0,0 +1,25 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("echo")
+
+ -- add rules
+ add_rules("wdk.driver.umdf")
+
+ -- add files
+ add_files("driver/*.c")
+
+-- add target
+target("app")
+
+ -- add deps
+ add_deps("echo")
+
+ -- add rules
+ add_rules("wdk.binary")
+
+ -- add files
+ add_files("exe/*.cpp")
+
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
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 24db00cb5..9c580599b 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -44,7 +44,7 @@ function _make_targetinfo(mode, arch, target)
-- get sdk version
local vcvarsall = config.get("__vcvarsall")
if vcvarsall then
- targetinfo.sdkver = (vcvarsall[arch] or {}).sdkver
+ targetinfo.sdkver = (vcvarsall[arch] or {}).WindowsSDKVersion
end
-- save c/c++ precompiled output file (.pch)
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index 435c36383..1ef4b3dd8 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -41,6 +41,14 @@ rule("qt.env")
end
end)
+ -- clean files
+ after_clean(function (target)
+ for _, file in ipairs(target:data("qt.cleanfiles")) do
+ os.rm(file)
+ end
+ target:data_set("qt.cleanfiles", nil)
+ end)
+
-- define rule: *.ui
rule("qt.ui")
@@ -243,10 +251,3 @@ rule("qt.application")
import("load")(target, {kind = "binary", frameworks = {"QtGui", "QtQml", "QtNetwork", "QtCore"}})
end)
- -- clean files
- after_clean(function (target)
- for _, file in ipairs(target:data("qt.cleanfiles")) do
- os.rm(file)
- end
- target:data_set("qt.cleanfiles", nil)
- end)
diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua
new file mode 100644
index 000000000..a4dacb64c
--- /dev/null
+++ b/xmake/rules/wdk/xmake.lua
@@ -0,0 +1,61 @@
+--!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 xmake.lua
+--
+
+-- define rule: environment
+rule("wdk.env")
+
+ -- on load
+ on_load(function (target)
+ import("detect.sdks.find_wdk")
+ if not target:data("wdk") then
+ target:data_set("wdk", assert(find_wdk(nil, {verbose = true}), "WDK not found!"))
+ end
+ end)
+
+ -- clean files
+ after_clean(function (target)
+ for _, file in ipairs(target:data("wdk.cleanfiles")) do
+ os.rm(file)
+ end
+ target:data_set("wdk.cleanfiles", nil)
+ end)
+
+-- define rule: umdf driver
+rule("wdk.driver.umdf")
+
+ -- add rules
+ add_deps("wdk.env")
+
+-- define rule: kmdf driver
+rule("wdk.driver.kmdf")
+
+ -- add rules
+ add_deps("wdk.env")
+
+-- define rule: binary
+rule("wdk.binary")
+
+ -- add rules
+ add_deps("wdk.env")
+