diff --git a/CMakeLists.txt b/CMakeLists.txt index 70fe073..69ab87f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,11 +91,11 @@ endif() # Define LVGL configuration as a simple include target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE) -target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread) -# Platform configuration -if(CMAKE_HOST_WIN32) - target_link_libraries(main -mconsole) +if(MSVC) + target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES}) +else() + target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread) endif() # Only link freertos_config if the FreeRTOS directory exists @@ -140,6 +140,16 @@ if(LV_USE_FREETYPE) target_link_libraries(main ${FREETYPE_LIBRARIES}) endif() +# On Windows, GUI applications do not show a console by default, +# which hides log output. This ensures a console is available for logging. +if (WIN32) + if (MSVC) + target_link_options(main PRIVATE "/SUBSYSTEM:CONSOLE") + else() + target_link_options(main PRIVATE "-mconsole") + endif() +endif() + # Apply additional compile options if the build type is Debug if(CMAKE_BUILD_TYPE STREQUAL "Debug") message(STATUS "Debug mode enabled") @@ -181,4 +191,4 @@ if (ASAN) else() message(STATUS "AddressSanitizer disabled") endif() -endif() +endif() \ No newline at end of file diff --git a/main/src/main.c b/main/src/main.c index b61664f..fe96925 100644 --- a/main/src/main.c +++ b/main/src/main.c @@ -7,11 +7,18 @@ /********************* * INCLUDES *********************/ -#define _DEFAULT_SOURCE /* needed for usleep() */ +#ifndef _DEFAULT_SOURCE + #define _DEFAULT_SOURCE /* needed for usleep() */ +#endif + #include #include -#include -#include +#ifdef _MSC_VER + #include +#else + #include + #include +#endif #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" #include "lvgl/demos/lv_demos.h" @@ -88,7 +95,11 @@ int main(int argc, char **argv) /* Periodically call the lv_task handler. * It could be done in a timer interrupt or an OS task too.*/ lv_timer_handler(); +#ifdef _MSC_VER + Sleep(5); +#else usleep(5 * 1000); +#endif } #elif LV_USE_OS == LV_OS_FREERTOS