Skip to content

Commit 0b5e5a6

Browse files
committed
(rules) update rules that set subsystem manually to use new subsystem rule
1 parent 7d1f8a0 commit 0b5e5a6

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

xmake/rules/qt/load.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function main(target, opt)
518518

519519
-- is gui application?
520520
if opt.gui then
521-
-- add -subsystem:windows for windows platform
521+
-- add windows subsystem for windows and mingw platforms
522522
if target:is_plat("windows") then
523523
target:add("defines", "_WINDOWS")
524524
local subsystem = false
@@ -533,7 +533,12 @@ function main(target, opt)
533533
end
534534
-- maybe user will set subsystem to console
535535
if not subsystem then
536-
target:add("ldflags", "-subsystem:windows", "-entry:mainCRTStartup", {force = true})
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
537542
end
538543
elseif target:is_plat("mingw") then
539544
target:add("ldflags", "-mwindows", {force = true})

xmake/rules/wdk/load.lua

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

3535
-- add subsystem
3636
local winver = target:values("wdk.env.winver") or config.get("wdk_winver")
37-
target:add("shflags", "-subsystem:windows," .. os_winver.subsystem(winver), {force = true})
37+
target:data_set("win.subsystem", "windows," .. os_winver.subsystem(winver))
38+
target:add("rules", "win.subsystem")
3839

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

7677
-- add subsystem
77-
target:add("ldflags", "-subsystem:native," .. os_winver.subsystem(winver), {force = true})
78+
target:data_set("win.subsystem", "native," .. os_winver.subsystem(winver))
79+
target:add("rules", "win.subsystem")
7880

7981
-- set default driver entry if does not exist
8082
local entry = false
@@ -117,7 +119,8 @@ function driver_wdm(target)
117119
target:add("ldflags", "-nodefaultlib", {force = true})
118120

119121
-- add subsystem
120-
target:add("ldflags", "-subsystem:native," .. os_winver.subsystem(winver), {force = true})
122+
target:data_set("win.subsystem", "native," .. os_winver.subsystem(winver))
123+
target:add("rules", "win.subsystem")
121124

122125
-- set default driver entry if does not exist
123126
local entry = false

xmake/rules/winsdk/mfc/mfc.lua

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

8989
-- set windows subsystem
90-
target:add("ldflags", "-subsystem:windows", {force = true})
90+
target:add("rules", "win.subsystem.windows")
9191

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

xmake/rules/winsdk/xmake.lua

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,10 @@ rule("win.sdk.application")
2929
target:set("kind", "binary")
3030
end)
3131

32-
after_load(function (target)
32+
-- set subsystem: windows
33+
add_deps("win.subsystem.windows")
3334

34-
-- set subsystem: windows
35-
if target:is_plat("mingw") then
36-
target:add("ldflags", "-mwindows", {force = true})
37-
else
38-
local subsystem = false
39-
for _, ldflag in ipairs(target:get("ldflags")) do
40-
if type(ldflag) == "string" then
41-
ldflag = ldflag:lower()
42-
if ldflag:find("[/%-]subsystem:") then
43-
subsystem = true
44-
break
45-
end
46-
end
47-
end
48-
if not subsystem then
49-
target:add("ldflags", "-subsystem:windows", {force = true, tools = {"link"}})
50-
end
51-
end
35+
after_load(function (target)
5236

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

0 commit comments

Comments
 (0)