Skip to content

Commit 64aa543

Browse files
committed
Fix build on msys2 mingw64
Something changed over night with pthread and `nanosleep()` in msys2 causing build failure for Shotcut CI. The ugly thing about it is that pthread must be manually linked in a manner unknown by CMake's FindThreads module. My workaround uses CMake `string()` over the iconv lib until someone finds a better way because there is no (win)pthread for pkg-config.
1 parent 2620b0b commit 64aa543

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ src/modules/glaxnimate/mltglaxnimate-qt6_autogen/
6767
out
6868
src/swig/ruby/markdown/
6969
CMakeLists.txt.user
70+
.cache/
7071

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ if(WIN32)
183183
find_package(dlfcn-win32 REQUIRED)
184184
set(CMAKE_DL_LIBS dlfcn-win32::dl)
185185
endif()
186+
if(MINGW)
187+
string(REPLACE "iconv" "pthread" MLT_PTHREAD_LIBS "${Iconv_LIBRARY}")
188+
endif()
186189
endif()
187190

188191
pkg_check_modules(sdl2 IMPORTED_TARGET sdl2)

src/framework/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ set_target_properties(mlt PROPERTIES
9696

9797
if(WIN32)
9898
if(MINGW)
99+
target_link_libraries(mlt PRIVATE ${MLT_PTHREAD_LIBS})
99100
target_link_options(mlt PRIVATE -Wl,--output-def,${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def)
100101
install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/libmlt-${MLT_VERSION_MAJOR}.def" DESTINATION ${CMAKE_INSTALL_LIBDIR})
101102
endif()

src/framework/mlt_types.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* \file mlt_types.h
33
* \brief Provides forward definitions of all public types
44
*
5-
* Copyright (C) 2003-2023 Meltytech, LLC
5+
* Copyright (C) 2003-2025 Meltytech, LLC
66
*
77
* This library is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU Lesser General Public
@@ -22,10 +22,6 @@
2222
#ifndef MLT_TYPES_H
2323
#define MLT_TYPES_H
2424

25-
#ifndef GCC_VERSION
26-
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
27-
#endif
28-
2925
#ifdef __cplusplus
3026
extern "C" {
3127
#endif

src/melt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if(TARGET PkgConfig::sdl2 AND NOT ANDROID)
1010
target_link_libraries(melt PRIVATE PkgConfig::sdl2)
1111
target_compile_definitions(melt PRIVATE HAVE_SDL2)
1212
if(MINGW)
13+
target_link_libraries(melt PRIVATE ${MLT_PTHREAD_LIBS})
1314
target_link_libraries(melt PRIVATE mingw32)
1415
endif()
1516
endif()

src/modules/avformat/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ target_compile_definitions(mltavformat PRIVATE FILTERS)
2828

2929
if(WIN32)
3030
target_compile_definitions(mltavformat PRIVATE AVDATADIR="share/ffmpeg/")
31+
if(MINGW)
32+
target_link_libraries(mltavformat PRIVATE ${MLT_PTHREAD_LIBS})
33+
endif()
3134
endif()
3235

3336
if(TARGET PkgConfig::libavcodec)

src/modules/sdl2/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ target_compile_options(mltsdl2 PRIVATE ${MLT_COMPILE_OPTIONS})
1414

1515
target_link_libraries(mltsdl2 PRIVATE mlt m Threads::Threads PkgConfig::sdl2)
1616

17+
if(MINGW)
18+
target_link_libraries(mltsdl2 PRIVATE ${MLT_PTHREAD_LIBS})
19+
endif()
20+
1721
set_target_properties(mltsdl2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${MLT_MODULE_OUTPUT_DIRECTORY}")
1822

1923
install(TARGETS mltsdl2 LIBRARY DESTINATION ${MLT_INSTALL_MODULE_DIR})

src/win32/win32.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ int usleep(unsigned int useconds)
4646
return 0;
4747
}
4848

49-
50-
int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
49+
#ifndef WIN_PTHREADS_TIME_H
50+
int nanosleep(const struct timespec * rqtp, struct timespec * rmtp)
5151
{
5252
if (rqtp->tv_nsec > 999999999) {
5353
/* The time interval specified 1,000,000 or more microseconds. */
5454
errno = EINVAL;
5555
return -1;
5656
}
57-
return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 );
58-
}
57+
return usleep(rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000);
58+
}
59+
#endif
5960

6061
int setenv(const char *name, const char *value, int overwrite)
6162
{

0 commit comments

Comments
 (0)