From 18902c6529c7c7da981aac28a5f1bb0343a368f7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 25 May 2023 19:49:20 +0200 Subject: [PATCH] setup pthreads for msvc Signed-off-by: falkTX --- cmake/CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++----- source/utils/CarlaMutex.hpp | 4 ++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6a9c557f1..9a13ea775 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -140,6 +140,41 @@ function(set_common_target_properties TARGET) endif() endfunction() +####################################################################################################################### +# setup pthreads for msvc + +if(MSVC) + include(FetchContent) + FetchContent_Declare(pthreads4w + GIT_REPOSITORY https://git.code.sf.net/p/pthreads4w/code + GIT_TAG f12b445b336ee0117b43fca1d4b9f22c9af82c36 + ) + FetchContent_MakeAvailable(pthreads4w) + + add_library(pthreads4w STATIC) + add_library(carla::pthreads4w ALIAS pthreads4w) + + target_sources(pthreads4w PRIVATE ${pthreads4w_SOURCE_DIR}/pthread.c) + target_compile_definitions(pthreads4w + PRIVATE + HAVE_CONFIG_H + HAVE_STDINT_H=1 + _POSIX_C_SOURCE=200112L + PUBLIC + INCLUDE_NP + PTW32_DLLPORT + __PTW32_STATIC_LIB + ) + + target_include_directories(pthreads4w + PUBLIC + ${pthreads4w_SOURCE_DIR} + ) + set(CARLA_PTHREADS carla::pthreads4w) +else() + set(CARLA_PTHREADS ${CMAKE_THREAD_LIBS_INIT}) +endif() + ####################################################################################################################### # audio_decoder @@ -531,7 +566,6 @@ target_compile_options(carla-ysfx $<$:-U_UNICODE> $<$:/wd4018> $<$:/wd4297> - $<$:/wd9025> $<$:/UUNICODE> $<$:/U_UNICODE> $<$:-Wno-extra> @@ -651,7 +685,7 @@ target_link_libraries(carla-bridge-native PkgConfig::LIBLO PkgConfig::LIBMAGIC PkgConfig::X11 - ${CMAKE_THREAD_LIBS_INIT} + ${CARLA_PTHREADS} ) target_sources(carla-bridge-native @@ -706,7 +740,7 @@ target_link_libraries(carla-discovery-native carla-water-files carla-ysfx PkgConfig::FLUIDSYNTH - ${CMAKE_THREAD_LIBS_INIT} + ${CARLA_PTHREADS} ) target_sources(carla-discovery-native @@ -765,7 +799,7 @@ target_link_libraries(carla-standalone PkgConfig::LIBLO PkgConfig::LIBMAGIC PkgConfig::X11 - ${CMAKE_THREAD_LIBS_INIT} + ${CARLA_PTHREADS} ) target_sources(carla-standalone @@ -832,7 +866,7 @@ target_link_libraries(carla-utils carla-ysfx PkgConfig::FLUIDSYNTH PkgConfig::X11 - ${CMAKE_THREAD_LIBS_INIT} + ${CARLA_PTHREADS} ) target_sources(carla-utils diff --git a/source/utils/CarlaMutex.hpp b/source/utils/CarlaMutex.hpp index dab04e8a5..e1076a513 100644 --- a/source/utils/CarlaMutex.hpp +++ b/source/utils/CarlaMutex.hpp @@ -39,7 +39,7 @@ public: { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); - #ifdef __GNUC__ + #ifndef PTW32_DLLPORT pthread_mutexattr_setprotocol(&attr, inheritPriority ? PTHREAD_PRIO_INHERIT : PTHREAD_PRIO_NONE); #else // unsupported? @@ -215,7 +215,7 @@ public: pthread_mutexattr_t mattr; pthread_mutexattr_init(&mattr); - #ifdef __GNUC__ + #ifndef PTW32_DLLPORT pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); #endif pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_NORMAL);