From a24bd33103828f5b10be0f872047e1797007c7d6 Mon Sep 17 00:00:00 2001 From: Nesbox Date: Wed, 16 Dec 2020 15:29:25 +0300 Subject: [PATCH] #1269: fixed mingw console app --- CMakeLists.txt | 8 ++++---- src/system/sdl/main.c | 7 +++++-- src/system/sokol/sokol.c | 12 ++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fdfbfb92..21a74b572 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,6 +336,7 @@ if(BUILD_SDL AND BUILD_PLAYER AND NOT RPI) if(MINGW) target_link_libraries(player-sdl mingw32) + target_link_options(player-sdl PRIVATE -static) endif() target_link_libraries(player-sdl tic80core SDL2-static SDL2main) @@ -399,6 +400,7 @@ if(BUILD_PLAYER AND BUILD_SOKOL) if(MINGW) target_link_libraries(player-sokol mingw32) + target_link_options(player-sokol PRIVATE -static) endif() target_include_directories(player-sokol PRIVATE @@ -677,10 +679,6 @@ endif() endif() -if(MINGW) - set(CMAKE_EXE_LINKER_FLAGS "-static") -endif() - ################################ # CURL ################################ @@ -756,6 +754,7 @@ if(BUILD_SDL) if(MINGW) target_link_libraries(tic80 mingw32) + target_link_options(tic80 PRIVATE -static -mconsole) endif() if(EMSCRIPTEN) @@ -833,6 +832,7 @@ if(BUILD_SOKOL) if(MINGW) target_link_libraries(tic80-sokol mingw32) + target_link_options(tic80-sokol PRIVATE -static -mconsole) endif() target_link_libraries(tic80-sokol tic80studio sokol net) diff --git a/src/system/sdl/main.c b/src/system/sdl/main.c index a609d5fb2..d1b8c5fef 100644 --- a/src/system/sdl/main.c +++ b/src/system/sdl/main.c @@ -1761,8 +1761,11 @@ static s32 emsStart(s32 argc, char **argv, const char* folder) s32 main(s32 argc, char **argv) { #if defined(__TIC_WINDOWS__) - if (argc == 1) - FreeConsole(); + { + CONSOLE_SCREEN_BUFFER_INFO info; + if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info) && !info.dwCursorPosition.X && !info.dwCursorPosition.Y) + FreeConsole(); + } #endif const char* folder = getAppFolder(); diff --git a/src/system/sokol/sokol.c b/src/system/sokol/sokol.c index 478fe7479..dab7db00e 100644 --- a/src/system/sokol/sokol.c +++ b/src/system/sokol/sokol.c @@ -30,6 +30,10 @@ #include "system/sokol/sokol.h" #include "net/net.h" +#if defined(__TIC_WINDOWS__) +#include +#endif + static struct { Studio* studio; @@ -419,6 +423,14 @@ static void app_cleanup(void) sapp_desc sokol_main(s32 argc, char* argv[]) { +#if defined(__TIC_WINDOWS__) + { + CONSOLE_SCREEN_BUFFER_INFO info; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info) && !info.dwCursorPosition.X && !info.dwCursorPosition.Y) + FreeConsole(); + } +#endif + memset(&platform, 0, sizeof platform); platform.audio.desc.num_channels = TIC_STEREO_CHANNELS;