summaryrefslogtreecommitdiff
path: root/xmake/rules/wdk/env/xmake.lua
blob: 93f848921d8069c4cc5448b0c5837bf7c0f9e662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--!A cross-platform build utility based on Lua
--
-- Licensed 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-present, Xmake Open Source Community.
--
-- @author      ruki
-- @file        xmake.lua
--

-- define rule: environment
rule("wdk.env")

    -- before load
    on_load(function (target)

        -- imports
        import("os.winver", {alias = "os_winver"})
        import("core.project.config")
        import("detect.sdks.find_wdk")

        -- load wdk environment
        if not target:data("wdk") then

            -- find wdk
            local wdk = assert(find_wdk(nil, {verbose = true}), "WDK not found!")

            -- update the umdf sdk version from the xmake.lua
            local umdfver = target:values("wdk.umdf.sdkver")
            if umdfver then
                wdk.umdfver = umdfver
            end

            -- update the kmdf sdk version from the xmake.lua
            local kmdfver = target:values("wdk.kmdf.sdkver")
            if kmdfver then
                wdk.kmdfver = kmdfver
            end

            -- add definitions for debug
            if is_mode("debug") then
                target:add("defines", "DBG=1")
            end

            -- get winver name
            local winver = target:values("wdk.env.winver") or config.get("wdk_winver")

            -- get winver version
            local winver_version = os_winver.version(winver or "") or "0x0A00"

            -- get target version
            local target_version = os_winver.target_version(winver or "") or "0x0A00"

            -- get winnt version
            local winnt_version = os_winver.winnt_version(winver or "") or "0x0A00"

            -- get ntddi version
            local ntddi_version = os_winver.ntddi_version(winver or "") or "0x0A000000"

            -- add definitions for winver
            target:add("defines", "_WIN32_WINNT=" .. winnt_version, "WINVER=" .. winver_version, "NTDDI_VERSION=" .. ntddi_version, "_NT_TARGET_VERSION=" .. target_version)

            -- set builtin version values
            target:values_set("wdk.env.winnt_version", winnt_version)
            target:values_set("wdk.env.ntddi_version", ntddi_version)
            target:values_set("wdk.env.winver_version", winver_version)
            target:values_set("wdk.env.target_version", target_version)

            -- save wdk
            target:data_set("wdk", wdk)
        end
    end)

-- define rule: umdf
rule("wdk.env.umdf")

    -- add rules
    add_deps("wdk.env")

    -- after load
    after_load(function (target)
        import("load").umdf(target)
    end)

-- define rule: kmdf
rule("wdk.env.kmdf")

    -- add rules
    add_deps("wdk.env")

    -- after load
    after_load(function (target)
        import("load").kmdf(target)
    end)

-- define rule: wdm
rule("wdk.env.wdm")

    -- add rules
    add_deps("wdk.env")

    -- after load
    after_load(function (target)
        import("load").wdm(target)
    end)