From 103cc006578d6f43a9ada074ead326e172d0894c Mon Sep 17 00:00:00 2001 From: Dmitry Kazakov Date: Wed, 10 Jun 2026 17:29:53 +0200 Subject: [PATCH 1/3] Revert "Fix build on msys2 mingw64" This reverts commit 64aa54375d2816d82210144bb5cebaf1ba911aa5. --- CMakeLists.txt | 3 --- src/framework/CMakeLists.txt | 1 - src/framework/mlt_types.h | 6 +++++- src/melt/CMakeLists.txt | 1 - src/modules/avformat/CMakeLists.txt | 3 --- src/modules/sdl2/CMakeLists.txt | 4 ---- src/win32/win32.c | 9 ++++----- 7 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb52cd417..9957f1145 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,9 +207,6 @@ if(WIN32) find_package(dlfcn-win32 REQUIRED) set(CMAKE_DL_LIBS dlfcn-win32::dl) endif() - if(MINGW) - string(REPLACE "iconv" "pthread" MLT_PTHREAD_LIBS "${Iconv_LIBRARY}") - endif() endif() find_package(SDL2) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 6d16e0938..4ef43fb67 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -107,7 +107,6 @@ set_target_properties(mlt PROPERTIES if(WIN32) if(MINGW) - target_link_libraries(mlt PRIVATE ${MLT_PTHREAD_LIBS}) target_link_options(mlt PRIVATE -Wl,--output-def,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def) install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def" DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() diff --git a/src/framework/mlt_types.h b/src/framework/mlt_types.h index 23f0c1884..999b43689 100644 --- a/src/framework/mlt_types.h +++ b/src/framework/mlt_types.h @@ -2,7 +2,7 @@ * \file mlt_types.h * \brief Provides forward definitions of all public types * - * Copyright (C) 2003-2025 Meltytech, LLC + * Copyright (C) 2003-2023 Meltytech, LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,10 @@ #ifndef MLT_TYPES_H #define MLT_TYPES_H +#ifndef GCC_VERSION +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/src/melt/CMakeLists.txt b/src/melt/CMakeLists.txt index 557bac728..750b02509 100644 --- a/src/melt/CMakeLists.txt +++ b/src/melt/CMakeLists.txt @@ -10,7 +10,6 @@ if(SDL2_FOUND AND NOT ANDROID) target_link_libraries(melt PRIVATE SDL2::SDL2) target_compile_definitions(melt PRIVATE HAVE_SDL2) if(MINGW) - target_link_libraries(melt PRIVATE ${MLT_PTHREAD_LIBS}) target_compile_definitions(melt PRIVATE main=SDL_main) target_link_libraries(melt PRIVATE mingw32 SDL2main SDL2) endif() diff --git a/src/modules/avformat/CMakeLists.txt b/src/modules/avformat/CMakeLists.txt index 883604642..33b73c683 100644 --- a/src/modules/avformat/CMakeLists.txt +++ b/src/modules/avformat/CMakeLists.txt @@ -46,9 +46,6 @@ endif() if(WIN32) target_compile_definitions(mltavformat PRIVATE AVDATADIR="share/ffmpeg/") - if(MINGW) - target_link_libraries(mltavformat PRIVATE ${MLT_PTHREAD_LIBS}) - endif() endif() if(CPU_MMX) diff --git a/src/modules/sdl2/CMakeLists.txt b/src/modules/sdl2/CMakeLists.txt index e46abb04f..844686d2f 100644 --- a/src/modules/sdl2/CMakeLists.txt +++ b/src/modules/sdl2/CMakeLists.txt @@ -20,10 +20,6 @@ else() target_link_libraries(mltsdl2 PRIVATE m) endif() -if(MINGW) - target_link_libraries(mltsdl2 PRIVATE ${MLT_PTHREAD_LIBS}) -endif() - set_target_properties(mltsdl2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${MLT_MODULE_OUTPUT_DIRECTORY}") install(TARGETS mltsdl2 LIBRARY DESTINATION ${MLT_INSTALL_MODULE_DIR}) diff --git a/src/win32/win32.c b/src/win32/win32.c index 29e443647..9085639fd 100644 --- a/src/win32/win32.c +++ b/src/win32/win32.c @@ -46,17 +46,16 @@ int usleep(unsigned int useconds) return 0; } -#ifndef WIN_PTHREADS_TIME_H -int nanosleep(const struct timespec * rqtp, struct timespec * rmtp) + +int nanosleep( const struct timespec * rqtp, struct timespec * rmtp ) { if (rqtp->tv_nsec > 999999999) { /* The time interval specified 1,000,000 or more microseconds. */ errno = EINVAL; return -1; } - return usleep(rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000); -} -#endif + return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 ); +} int setenv(const char *name, const char *value, int overwrite) { From 17488b4eb454a827be097872f4f731860998b789 Mon Sep 17 00:00:00 2001 From: Dmitry Kazakov Date: Wed, 10 Jun 2026 17:34:42 +0200 Subject: [PATCH 2/3] [win] Don't build a custom nanosleep() when not needed Instead of relying of the includes order we should properly check if the function is actually provided by our version of pthread library. --- src/framework/CMakeLists.txt | 9 +++++++++ src/melt/CMakeLists.txt | 2 +- src/win32/win32.c | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 4ef43fb67..cd7f5f17b 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -110,7 +110,16 @@ if(WIN32) target_link_options(mlt PRIVATE -Wl,--output-def,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def) install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def" DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() + + include(CheckSymbolExists) + set(CMAKE_REQUIRED_LIBRARIES Threads::Threads) + check_symbol_exists(nanosleep "pthread.h;pthread_time.h" HAVE_PTHREAD_NANOSLEEP) + unset(CMAKE_REQUIRED_LIBRARIES) + target_sources(mlt PRIVATE ../win32/win32.c) + set_source_files_properties(../win32/win32.c PROPERTIES + COMPILE_DEFINITIONS "HAVE_PTHREAD_NANOSLEEP=${HAVE_PTHREAD_NANOSLEEP}") + target_link_libraries(mlt PRIVATE Iconv::Iconv) if(NOT WINDOWS_DEPLOY) target_compile_definitions(mlt PRIVATE NODEPLOY) diff --git a/src/melt/CMakeLists.txt b/src/melt/CMakeLists.txt index 750b02509..8a8a84d55 100644 --- a/src/melt/CMakeLists.txt +++ b/src/melt/CMakeLists.txt @@ -11,7 +11,7 @@ if(SDL2_FOUND AND NOT ANDROID) target_compile_definitions(melt PRIVATE HAVE_SDL2) if(MINGW) target_compile_definitions(melt PRIVATE main=SDL_main) - target_link_libraries(melt PRIVATE mingw32 SDL2main SDL2) + target_link_libraries(melt PRIVATE mingw32 SDL2::SDL2main) endif() endif() diff --git a/src/win32/win32.c b/src/win32/win32.c index 9085639fd..6f485d071 100644 --- a/src/win32/win32.c +++ b/src/win32/win32.c @@ -46,7 +46,7 @@ int usleep(unsigned int useconds) return 0; } - +#if !HAVE_PTHREAD_NANOSLEEP int nanosleep( const struct timespec * rqtp, struct timespec * rmtp ) { if (rqtp->tv_nsec > 999999999) { @@ -56,6 +56,7 @@ int nanosleep( const struct timespec * rqtp, struct timespec * rmtp ) } return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 ); } +#endif int setenv(const char *name, const char *value, int overwrite) { From e2460b72730d804511fa03d37b9abde252b260c5 Mon Sep 17 00:00:00 2001 From: Dmitry Kazakov Date: Wed, 10 Jun 2026 18:10:57 +0200 Subject: [PATCH 3/3] Fix order of linking SDL2 targets to melt It seems like there is some issue with that with MSYS2: https://github.com/msys2/MINGW-packages/issues/10459 --- src/melt/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/melt/CMakeLists.txt b/src/melt/CMakeLists.txt index 8a8a84d55..68f00266b 100644 --- a/src/melt/CMakeLists.txt +++ b/src/melt/CMakeLists.txt @@ -7,11 +7,12 @@ target_link_libraries(melt PRIVATE mlt Threads::Threads) target_compile_definitions(melt PRIVATE VERSION="${MLT_VERSION}") if(SDL2_FOUND AND NOT ANDROID) - target_link_libraries(melt PRIVATE SDL2::SDL2) target_compile_definitions(melt PRIVATE HAVE_SDL2) if(MINGW) target_compile_definitions(melt PRIVATE main=SDL_main) - target_link_libraries(melt PRIVATE mingw32 SDL2::SDL2main) + target_link_libraries(melt PRIVATE mingw32 SDL2::SDL2main SDL2::SDL2) + else() + target_link_libraries(melt PRIVATE SDL2::SDL2) endif() endif()