From c3d7fd6efa2058a9f254c5c06d803286e4b6350f Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 26 Aug 2024 12:00:24 +0200 Subject: [PATCH] fxlink: find SDL2 without -mwindows to stay in console [Windows] When loading SDL2 with pkg-config the -mwindows flag is added, which instructs the loader to load the program through WinMain() and not create a console for it. This is intended for GUI programs. However, fxlink is a CLI program with just occasionally an SDL window on top of it. Disable -mwindows to keep the console and terminal output. I don't know how to do that with the pkg-config CMake module, so use the SDL2 module for the Windows build instead. --- CMakeLists.txt | 12 ++++++++++-- fxlink/main.c | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7771c04..054db11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,14 @@ if(NOT FXLINK_DISABLE_UDISKS2) pkg_check_modules(udisks2 REQUIRED udisks2 IMPORTED_TARGET) endif() if(NOT FXLINK_DISABLE_SDL2) - pkg_check_modules(sdl2 REQUIRED sdl2 IMPORTED_TARGET) + if(WIN32) + set(SDL2_NO_MWINDOWS 1) + find_package(SDL2 REQUIRED) + else() + pkg_check_modules(sdl2 REQUIRED sdl2 IMPORTED_TARGET) + set(SDL2_LIBRARIES PkgConfig::sdl2) + set(SDL2_INCLUDE_DIRS) + endif() endif() pkg_check_modules(ncurses REQUIRED ncursesw IMPORTED_TARGET) @@ -87,7 +94,8 @@ if(NOT FXLINK_DISABLE_UDISKS2) target_link_libraries(fxlink PkgConfig::udisks2) endif() if(NOT FXLINK_DISABLE_SDL2) - target_link_libraries(fxlink PkgConfig::sdl2) + target_link_libraries(fxlink ${SDL2_LIBRARIES}) + target_include_directories(fxlink PRIVATE ${SDL2_INCLUDE_DIRS}) endif() # fxsdk-gdb-bridge diff --git a/fxlink/main.c b/fxlink/main.c index 9db1a64..3bd04b5 100644 --- a/fxlink/main.c +++ b/fxlink/main.c @@ -16,6 +16,11 @@ #include #include +#ifndef FXLINK_DISABLE_SDL2 +/* Grab main()-related macros */ +#include +#endif + static const char *help_string = "usage: %1$s (-l|-b|-t) [General options]\n" " %1$s -i [-r] [--fxlink-log[=]] [General options]\n"