Skip to content

Commit 57ca681

Browse files
committed
Fix libcds on MinGW
1 parent ef83529 commit 57ca681

File tree

11 files changed

+106
-7
lines changed

11 files changed

+106
-7
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434
[submodule "src/3rdparty/libcds"]
3535
path = src/3rdparty/libcds
3636
url = https://github.com/khizmax/libcds.git
37+
[submodule "src/3rdparty/mingw-std-threads"]
38+
path = src/3rdparty/mingw-std-threads
39+
url = https://github.com/meganz/mingw-std-threads.git

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ INCLUDE_DIRECTORIES(
147147
${Qt5Xml_INCLUDE_DIRS}
148148
)
149149

150+
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src/3rdparty/mingw-std-threads")
151+
150152
SET(QT_LIBRARIES
151153
Qt5::Core
152154
Qt5::Gui

cmake/modules/DetectMachine.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
INCLUDE(CheckCXXSourceCompiles)
2+
13
IF(WIN32)
24
SET(LMMS_BUILD_WIN32 1)
35
ELSEIF(APPLE)
@@ -86,3 +88,27 @@ IF(LMMS_BUILD_APPLE)
8688
STRING(REGEX REPLACE "\\.[0-9]*$" "" APPLE_OS_VER "${APPLE_OS_VER}")
8789
SET(CMAKE_MACOSX_RPATH 1)
8890
ENDIF()
91+
92+
# Detect MinGW
93+
IF(WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
94+
SET(MINGW TRUE)
95+
ENDIF()
96+
97+
# Detect MINGW thread support
98+
IF(MINGW)
99+
CHECK_CXX_SOURCE_COMPILES("
100+
#include <mutex>
101+
#include <thread>
102+
int main(int argc, const char* argv[]) {
103+
std::mutex m;
104+
std::this_thread::yield();
105+
return 0;
106+
}
107+
" HAS_STD_THREADS)
108+
IF(NOT HAS_STD_THREADS)
109+
SET(NEED_MINGW_THREADS_REPLACEMENT TRUE)
110+
ELSE()
111+
SET(NEED_MINGW_THREADS_REPLACEMENT FALSE)
112+
ENDIF()
113+
MESSAGE(NEED_MINGW_THREADS_REPLACEMENT ${NEED_MINGW_THREADS_REPLACEMENT})
114+
ENDIF()

cmake/toolchains/common/Ubuntu-MinGW-W64.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
55
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
66
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
77

8-
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
8+
set(MINGW_PREFIX /usr/${TOOLCHAIN_PREFIX})
9+
10+
set(CMAKE_FIND_ROOT_PATH ${MINGW_PREFIX})
911
SET(PKG_CONFIG_EXECUTABLE /usr/bin/${TOOLCHAIN_PREFIX}-pkg-config)
1012

1113
IF(WIN64)
1214
SET(TOOLCHAIN_PREFIX32 ${CMAKE_SYSTEM_PROCESSOR32}-w64-mingw32)
1315
SET(CMAKE_C_COMPILER32 ${TOOLCHAIN_PREFIX32}-gcc)
1416
SET(CMAKE_CXX_COMPILER32 ${TOOLCHAIN_PREFIX32}-g++)
17+
set(MINGW_PREFIX32 /usr/${TOOLCHAIN_PREFIX32})
1518
ENDIF()
1619

1720
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/WinCrossCompile.cmake)

include/libcds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#pragma once
22

3+
#include <thread>
4+
35
#include "NiftyCounter.h"
46

7+
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
8+
# include "mingw-std-threads/thread"
9+
# include "mingw-std-threads/mutex"
10+
#endif
11+
512
namespace _cdslib
613
{
714
void init();

include/mingw-std-threads/mutex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "mingw.mutex.h"

include/mingw-std-threads/thread

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "mingw.thread.h"

plugins/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ IF(LMMS_BUILD_APPLE)
99
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
1010
ENDIF()
1111

12+
IF(MINGW_PREFIX)
13+
# There's a bug in some CMake or MinGW versions that passes -std=c++11 when
14+
# compiling C files (e.g. fmopl.c). Remove -Werror for plugins to work
15+
# around this.
16+
STRING(REPLACE "-Werror " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
17+
ENDIF()
18+
1219
INCLUDE_DIRECTORIES(
1320
${SAMPLERATE_INCLUDE_DIRS}
1421
"${CMAKE_BINARY_DIR}/src"

src/3rdparty/CMakeLists.txt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,53 @@ ENDIF()
1111
ADD_SUBDIRECTORY(rpmalloc)
1212
ADD_SUBDIRECTORY(weakjack)
1313

14-
ADD_SUBDIRECTORY(libcds)
14+
IF(WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
15+
SET(MINGW TRUE)
16+
ENDIF()
17+
18+
IF(MINGW)
19+
# Work around linking errors with MinGW
20+
SET(CDS_LIBRARY_TYPE SHARED)
21+
ELSE()
22+
SET(CDS_LIBRARY_TYPE STATIC)
23+
ENDIF()
24+
25+
ADD_LIBRARY(cds ${CDS_LIBRARY_TYPE}
26+
libcds/src/init.cpp
27+
libcds/src/hp.cpp
28+
libcds/src/dhp.cpp
29+
libcds/src/urcu_gp.cpp
30+
libcds/src/urcu_sh.cpp
31+
libcds/src/thread_data.cpp
32+
libcds/src/topology_hpux.cpp
33+
libcds/src/topology_linux.cpp
34+
libcds/src/topology_osx.cpp
35+
libcds/src/dllmain.cpp
36+
)
37+
SET_TARGET_PROPERTIES(cds PROPERTIES
38+
CXX_STANDARD 11
39+
CXX_STANDARD_REQUIRED ON
40+
)
41+
TARGET_INCLUDE_DIRECTORIES(cds
42+
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libcds"
43+
)
44+
45+
IF(NEED_MINGW_THREADS_REPLACEMENT)
46+
# Provide win32 threads implementation
47+
TARGET_INCLUDE_DIRECTORIES(cds BEFORE
48+
PRIVATE "${CMAKE_SOURCE_DIR}/include/mingw-std-threads"
49+
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/mingw-std-threads"
50+
)
51+
ENDIF()
52+
53+
IF(CDS_LIBRARY_TYPE STREQUAL "STATIC")
54+
TARGET_COMPILE_DEFINITIONS(cds
55+
PRIVATE CDS_BUILD_STATIC_LIB
56+
)
57+
ELSE()
58+
TARGET_COMPILE_DEFINITIONS(cds
59+
PRIVATE CDS_BUILD_LIB
60+
)
61+
# Install DLL
62+
install(TARGETS cds RUNTIME DESTINATION .)
63+
ENDIF()

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS}
165165
${SNDFILE_LIBRARIES}
166166
${EXTRA_LIBRARIES}
167167
rpmalloc
168-
cds-s
168+
cds
169169
)
170170

171171
# Expose required libs for tests binary

0 commit comments

Comments
 (0)