Skip to content

Commit 445488a

Browse files
committed
fix(windows): launch GUI applications without a console
1 parent d1d2daa commit 445488a

11 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎cmake/HuxerUIApp.cmake‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ function(huxerui_add_app target_name)
203203
add_executable(${target_name} ${HUXERUI_APP_SOURCES})
204204
endif ()
205205

206+
if (WIN32)
207+
set_target_properties(${target_name} PROPERTIES WIN32_EXECUTABLE TRUE)
208+
if (MSVC)
209+
# Preserve CRT initialization and the portable main() entry.
210+
set_property(TARGET ${target_name} PROPERTY HUXERUI_WINDOWS_CRT_ENTRY mainCRTStartup)
211+
target_link_options(${target_name} PRIVATE
212+
"LINKER:/ENTRY:$<TARGET_PROPERTY:${target_name},HUXERUI_WINDOWS_CRT_ENTRY>"
213+
)
214+
endif ()
215+
endif ()
216+
206217
set_property(TARGET ${target_name} PROPERTY
207218
HUXERUI_APPLICATION_INSTALL_COMPONENT
208219
"${HUXERUI_APP_INSTALL_COMPONENT}"

‎cmake/HuxerUIWindowsInstaller.cmake‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function(huxerui_add_windows_installer target_name)
171171
NOMINMAX
172172
WIN32_LEAN_AND_MEAN
173173
)
174-
set_target_properties(${target_name} PROPERTIES WIN32_EXECUTABLE TRUE)
174+
set_property(TARGET ${target_name} PROPERTY HUXERUI_WINDOWS_CRT_ENTRY wWinMainCRTStartup)
175175
add_custom_command(TARGET ${target_name} POST_BUILD
176176
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
177177
"${HUXERUI_WIX_BOOTSTRAPPER_RUNTIME}"

‎docs/design/mcpp-build-system.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ either: `CMAKE_CXX_STANDARD_LIBRARIES` adds kernel32, gdi32, winspool, uuid and
205205
comdlg32 implicitly, and mcpp links exactly what the manifest names. Omitting
206206
them surfaces at the link as `undefined symbol: CreateDIBSection`.
207207
208+
Windows application templates and examples select the GUI subsystem and `mainCRTStartup` with MSVC-compatible linker directives in their `main.cpp` entry, preserving CRT initialization and the portable `main()` signature without creating a console. This selection belongs to the entry object: mcpp currently has no per-target link flags, and package-level `ldflags` or `link-flag` directives also reach tests and consumers. `huxerui.rules::configure()` therefore does not emit these flags, since component libraries use it too. CMake makes the equivalent selection on each application target in `huxerui_add_app`.
209+
208210
**macOS.** `.mm` is a first-class source kind but is not in the default glob,
209211
so `platform/macos/*.mm` is listed explicitly. `frameworks` is a **top-level**
210212
`[runtime]` key — the per-target vocabulary is `libraries` only, and a

‎docs/design/sdk-cli.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ Desktop builds configure the root CMake project and then build it.
345345
Fresh Linux and macOS builds use Ninja when it is available unless an explicit generator, `CMAKE_GENERATOR`, or an existing CMake cache takes precedence.
346346
Windows discovers the latest Visual Studio installation that provides the C++ x64 tools without constraining its product version, imports its developer environment, and explicitly selects MSVC.
347347
Fresh Windows builds use Ninja when available and NMake otherwise; an existing Windows cache retains its compatible generator while the compiler remains MSVC.
348+
`huxerui_add_app` selects the Windows GUI subsystem on the application target only. MSVC applications retain `main()` through `mainCRTStartup`; the installer helper selects `wWinMainCRTStartup` through the private `HUXERUI_WINDOWS_CRT_ENTRY` target property for its existing `wWinMain()` entry. Both paths preserve CRT initialization. The framework's public link interface carries no subsystem or entry-point option, and Runtime does not allocate or hide a console.
348349
The Windows SDK packages matching Debug and Release shared and static libraries so the CLI's default Debug profile and explicit Release profile use the corresponding MSVC runtime.
349350
`--generator` applies to Linux, macOS, and Web builds. Windows, Android, and iOS reject it because their platform drivers own the supported generator and toolchain selection.
350351

‎docs/development/building.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ The example supplies its own light ThemeSpec to MaterialTheme: neutral surfaces,
190190
The same application CMake contract supports a source checkout and an installed SDK.
191191
Consumers use `huxerui_add_app`, `huxerui_add_library`, `huxerui_add_resources`, and the exported `HuxerUI::huxerui` or `HuxerUI::huxerui_static` targets.
192192
Consumer projects never include private `src` headers or checkout-specific platform paths.
193+
On Windows, `huxerui_add_app` creates a GUI executable that keeps the portable `main()` entry and does not allocate a console on launch in either Debug or Release builds. Standard output and standard error have no automatically created console; use debugger output or application-owned logging when diagnosing a GUI application. Ordinary executables that only link HuxerUI, including CLI tools and tests, retain their own subsystem selection.

‎mcpp/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ path arrive through the dependency edge: a dependency's `build.mcpp` emits
6464
`link-lib` / `link-search` that reach the **final** link, so an application
6565
never restates them. `mcpp/examples/` holds three worked examples.
6666
67+
On Windows with the MSVC ABI, the application templates and examples keep `main()` and place GUI subsystem and CRT entry linker directives in that entry source. Double-clicking the resulting executable does not create a console; standard output and standard error have no automatically created console. Keep these directives in the application entry rather than package-wide link flags, which also affect tests and consumers. See [Platform interfaces](../docs/design/mcpp-build-system.md#6-platform-interfaces) for the build-system boundary.
68+
6769
## Three things worth knowing before editing
6870
6971
**The GTK stack is NOT the machine's.** mcpp compiles with its own toolchain and

‎mcpp/examples/01-import/src/main.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
import huxerui;
1414
import app;
1515

16+
#if defined(_WIN32) && defined(_MSC_VER)
17+
// Keep GUI linking local to this entry; mcpp package link flags also reach tests and consumers.
18+
#pragma comment(linker, "/subsystem:windows")
19+
#pragma comment(linker, "/entry:mainCRTStartup")
20+
#endif
21+
1622
int main() { return huxerui::RunApplication(); }

‎mcpp/examples/02-module-units/src/main.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
import huxerui;
55
import app;
66

7+
#if defined(_WIN32) && defined(_MSC_VER)
8+
// Keep GUI linking local to this entry; mcpp package link flags also reach tests and consumers.
9+
#pragma comment(linker, "/subsystem:windows")
10+
#pragma comment(linker, "/entry:mainCRTStartup")
11+
#endif
12+
713
int main() { return huxerui::RunApplication(); }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import huxerui;
22
import app;
33

4+
#if defined(_WIN32) && defined(_MSC_VER)
5+
// Keep GUI linking local to this entry; mcpp package link flags also reach tests and consumers.
6+
#pragma comment(linker, "/subsystem:windows")
7+
#pragma comment(linker, "/entry:mainCRTStartup")
8+
#endif
9+
410
int main() { return huxerui::RunApplication(); }

‎templates/app/src/main.cpp.in‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
import huxerui;
1616
import app;
1717

18+
#if defined(_WIN32) && defined(_MSC_VER)
19+
// Keep GUI linking local to this entry; mcpp package link flags also reach tests and consumers.
20+
#pragma comment(linker, "/subsystem:windows")
21+
#pragma comment(linker, "/entry:mainCRTStartup")
22+
#endif
23+
1824
int main() { return huxerui::RunApplication(); }

0 commit comments

Comments
 (0)