Skip to content

Commit 221ca3c

Browse files
committed
(rules) use values/values_set instead of data and rename windows.subsystem rule to platform.windows.subsystem
1 parent df0df78 commit 221ca3c

File tree

8 files changed

+39
-60
lines changed

8 files changed

+39
-60
lines changed

xmake/rules/qt/load.lua

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,30 +518,15 @@ function main(target, opt)
518518

519519
-- is gui application?
520520
if opt.gui then
521-
-- add windows subsystem for windows and mingw platforms
522-
if target:is_plat("windows") then
523-
target:add("defines", "_WINDOWS")
524-
local subsystem = false
525-
for _, ldflag in ipairs(target:get("ldflags")) do
526-
if type(ldflag) == "string" then
527-
ldflag = ldflag:lower()
528-
if ldflag:find("[/%-]subsystem:") then
529-
subsystem = true
530-
break
531-
end
532-
end
533-
end
534-
-- maybe user will set subsystem to console
535-
if not subsystem then
536-
target:add("rules", "win.subsystem.windows")
537-
local linker = target:tool("ld")
538-
linker = path.filename(linker)
539-
if linker:startswith("link") or linker:startswith("lld-link") then
540-
target:add("ldflags", "-entry:mainCRTStartup", {force = true})
541-
end
521+
if not target:values("windows.subsystem") then
522+
target:values_set("windows.subsystem", "windows")
523+
if target:has_tool("ld", "link", "lld-link") then
524+
target:add("ldflags", "-entry:mainCRTStartup", {force = true})
542525
end
543-
elseif target:is_plat("mingw") then
544-
target:add("ldflags", "-mwindows", {force = true})
526+
end
527+
else
528+
if not target:values("windows.subsystem") then
529+
target:values_set("windows.subsystem", "console")
545530
end
546531
end
547532

xmake/rules/qt/xmake.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ rule("qt.shared")
6767

6868
-- define rule: qt console
6969
rule("qt.console")
70-
add_deps("qt.qrc", "qt.ui", "qt.moc", "qt.ts")
70+
add_deps("qt.qrc", "qt.ui", "qt.moc", "qt.ts", "platform.windows.subsystem")
7171

7272
-- we must set kind before target.on_load(), may we will use target in on_load()
7373
on_load(function (target)
@@ -83,7 +83,7 @@ rule("qt.console")
8383

8484
-- define rule: qt widgetapp
8585
rule("qt.widgetapp")
86-
add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts")
86+
add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts", "platform.windows.subsystem")
8787

8888
-- we must set kind before target.on_load(), may we will use target in on_load()
8989
on_load(function (target)

xmake/rules/wdk/load.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ function driver_umdf(target)
3434

3535
-- add subsystem
3636
local winver = target:values("wdk.env.winver") or config.get("wdk_winver")
37-
target:data_set("win.subsystem", "windows," .. os_winver.subsystem(winver))
38-
target:add("rules", "win.subsystem")
37+
if not target:values("windows.subsystem") then
38+
target:values_set("windows.subsystem", "windows," .. os_winver.subsystem(winver))
39+
end
3940

4041
-- set default driver entry if does not exist
4142
local entry = false
@@ -75,8 +76,9 @@ function driver_kmdf(target)
7576
target:add("ldflags", "-nodefaultlib", {force = true})
7677

7778
-- add subsystem
78-
target:data_set("win.subsystem", "native," .. os_winver.subsystem(winver))
79-
target:add("rules", "win.subsystem")
79+
if not target:values("windows.subsystem") then
80+
target:values_set("windows.subsystem", "native," .. os_winver.subsystem(winver))
81+
end
8082

8183
-- set default driver entry if does not exist
8284
local entry = false
@@ -119,8 +121,9 @@ function driver_wdm(target)
119121
target:add("ldflags", "-nodefaultlib", {force = true})
120122

121123
-- add subsystem
122-
target:data_set("win.subsystem", "native," .. os_winver.subsystem(winver))
123-
target:add("rules", "win.subsystem")
124+
if not target:values("windows.subsystem") then
125+
target:values_set("windows.subsystem", "native," .. os_winver.subsystem(winver))
126+
end
124127

125128
-- set default driver entry if does not exist
126129
local entry = false

xmake/rules/wdk/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
rule("wdk.driver")
2323

2424
-- add rules
25-
add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp", "wdk.sign", "wdk.package.cab")
25+
add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp", "wdk.sign", "wdk.package.cab", "platform.windows.subsystem")
2626

2727
-- after load
2828
after_load(function (target)

xmake/rules/windows/xmake.lua

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,27 @@
1-
rule("win.subsystem.console")
2-
add_deps("win.subsystem")
3-
on_load(function(target)
4-
target:data_set("win.subsystem", "console")
5-
end)
6-
7-
rule("win.subsystem.windows")
8-
add_deps("win.subsystem")
9-
on_load(function(target)
10-
target:data_set("win.subsystem", "windows")
11-
end)
12-
13-
rule("win.subsystem")
1+
rule("platform.windows.subsystem")
142
on_config("mingw", "windows", function(target)
153
local subsystems = {
164
"BOOT_APPLICATION", "CONSOLE", "EFI_APPLICATION", "EFI_BOOT_SERVICE_DRIVER", "EFI_ROM", "EFI_RUNTIME_DRIVER", "NATIVE", "POSIX", "WINDOWS"
175
}
186

19-
local subsystem = target:data("win.subsystem")
7+
local subsystem = target:values("windows.subsystem")
208
local valid = false
21-
local startswith = string.startswith
229
local upper = string.upper
2310
for _, s in ipairs(subsystems) do
24-
if startswith(upper(subsystem), s) then
11+
if (subsystem:upper():startwiths(s)) then
2512
valid = true
2613
break
2714
end
2815
end
2916
assert(valid, "Invalid subsystem " .. subsystem)
3017

31-
local linker = target:tool("ld")
32-
linker = path.filename(linker)
33-
if startswith(linker, "clang") then
18+
if target:has_tool("ld", "clang") then
3419
target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true })
35-
elseif startswith(linker, "link") or startswith(linker, "lld-link") then
20+
elseif target:has_tool("ld", "link", "lld-link") then
3621
target:add("ldflags", "/SUBSYSTEM:" .. upper(subsystem), { force = true })
37-
elseif startswith(linker, "gcc") or startswith(linker, "g++") then
22+
elseif target:has_tool("ld", "gcc", "g++") then
3823
target:add("ldflags", "-Wl,-m" .. subsystem, { force = true })
39-
elseif startswith(linker, "ld") then
24+
elseif target:has_tool("ld", "ld") then
4025
target:add("ldflags", "-m" .. subsystem, { force = true })
4126
end
4227
end)

xmake/rules/winsdk/mfc/mfc.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ function application(target, mfc_kind)
8787
_remove_flags(target)
8888

8989
-- set windows subsystem
90-
target:add("rules", "win.subsystem.windows")
90+
if not target:values("windows.subsystem") then
91+
target:values_set("windows.subsystem", "windows")
92+
end
9193

9294
-- forces a link to complete even with unresolved symbols
9395
if mfc_kind == "static" then

xmake/rules/winsdk/mfc/xmake.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ rule("win.sdk.mfc.static")
4343
-- define rule: the application with shared mfc libraries
4444
rule("win.sdk.mfc.shared_app")
4545

46-
-- add mfc base rule
47-
add_deps("win.sdk.mfc.env")
46+
-- add mfc base and subsystem rule
47+
add_deps("win.sdk.mfc.env", "platform.windows.subsystem")
4848

4949
-- after load
5050
after_load(function (target)
@@ -54,8 +54,8 @@ rule("win.sdk.mfc.shared_app")
5454
-- define rule: the application with static mfc libraries
5555
rule("win.sdk.mfc.static_app")
5656

57-
-- add mfc base rule
58-
add_deps("win.sdk.mfc.env")
57+
-- add mfc base and subsystem rule
58+
add_deps("win.sdk.mfc.env", "platform.windows.subsystem")
5959

6060
-- after load
6161
after_load(function (target)

xmake/rules/winsdk/xmake.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ rule("win.sdk.application")
3030
end)
3131

3232
-- set subsystem: windows
33-
add_deps("win.subsystem.windows")
33+
add_deps("platform.windows.subsystem")
3434

3535
after_load(function (target)
36+
-- set windows subsystem
37+
if not target:values("windows.subsystem") then
38+
target:values_set("windows.subsystem", "windows")
39+
end
3640

3741
-- add links
3842
target:add("syslinks", "kernel32", "user32", "gdi32", "winspool", "comdlg32", "advapi32")

0 commit comments

Comments
 (0)