From b922c135090c8d1cc3d155d2c9032d292dfc8a09 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 1 Apr 2022 13:48:26 +0100 Subject: [PATCH] Compile broker against pthreads if threading enabled. This allows plugins to *carefully* use threads. --- CMakeLists.txt | 2 +- apps/mosquitto_ctrl/CMakeLists.txt | 8 ++++++++ config.mk | 2 ++ src/CMakeLists.txt | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f37575b..a3e733aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ option(WITH_SRV "Include SRV lookup support?" OFF) option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF) option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF) -option(WITH_THREADING "Include client library threading support?" ON) +option(WITH_THREADING "Include threading support?" ON) if(WITH_THREADING) add_definitions("-DWITH_THREADING") endif() diff --git a/apps/mosquitto_ctrl/CMakeLists.txt b/apps/mosquitto_ctrl/CMakeLists.txt index c203b757..6d241cfb 100644 --- a/apps/mosquitto_ctrl/CMakeLists.txt +++ b/apps/mosquitto_ctrl/CMakeLists.txt @@ -65,6 +65,14 @@ if(WITH_TLS AND CJSON_FOUND) ${CJSON_LIBRARIES} ) + if (WITH_THREADING AND NOT WIN32) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + + target_link_libraries(mosquitto_ctrl PRIVATE Threads::Threads) + endif() + + install(TARGETS mosquitto_ctrl RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) diff --git a/config.mk b/config.mk index c7f8decb..1f296729 100644 --- a/config.mk +++ b/config.mk @@ -269,6 +269,8 @@ ifeq ($(WITH_TLS),yes) endif ifeq ($(WITH_THREADING),yes) + BROKER_CFLAGS:=$(BROKER_CFLAGS) -pthread + BROKER_LDFLAGS:=$(BROKER_LDFLAGS) -pthread LIB_CFLAGS:=$(LIB_CFLAGS) -pthread LIB_CPPFLAGS:=$(LIB_CPPFLAGS) -DWITH_THREADING LIB_LDFLAGS:=$(LIB_LDFLAGS) -pthread diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9bb48d5c..eaf7cec3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,6 +240,13 @@ target_link_libraries(mosquitto ${MOSQ_LIBS} ) +if (WITH_THREADING AND NOT WIN32) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + + target_link_libraries(mosquitto PRIVATE Threads::Threads) +endif() + if(WIN32) set_target_properties(mosquitto PROPERTIES ENABLE_EXPORTS 1