From 7f1419e4de981f5cc38aa3a9684369b1de27ba46 Mon Sep 17 00:00:00 2001 From: majekw Date: Mon, 8 Oct 2018 00:16:38 +0200 Subject: [PATCH] Fix mosquitto_pub -l if compiled using cmake. Since dde005ef92190dffd1bab0ddbfcfd8c5dbe17bc8 mosquito_pub is throwing error that 'threading support has not been compiled' when compiled using cmake. It looks like WITH_THREADING flag is not set at top level Makefile and used only in lib/ directory, so library is correctly compiled with threading. But for client this flag is undefined, so it gives error on '-l' option. This commit moves part related to WITH_THREADING flag out of lib/CMakeLists.txt to top levele CMakeLists.txt, so it could be accessible to all subdirectories. Signed-off-by: Marek Wodzinski --- CMakeLists.txt | 24 ++++++++++++++++++++++++ ChangeLog.txt | 3 +++ client/CMakeLists.txt | 2 +- lib/CMakeLists.txt | 24 ------------------------ 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9a86362..5e55f119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,30 @@ endif (${WITH_SOCKS} STREQUAL ON) option(WITH_SRV "Include SRV lookup support?" OFF) +option(WITH_THREADING "Include client library threading support?" ON) +if (${WITH_THREADING} STREQUAL ON) + add_definitions("-DWITH_THREADING") + if (WIN32) + if (CMAKE_CL_64) + set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x64\\pthreadVC2.lib) + else (CMAKE_CL_64) + set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib) + endif (CMAKE_CL_64) + set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include) + else (WIN32) + find_library(LIBPTHREAD pthread) + if (LIBPTHREAD) + set (PTHREAD_LIBRARIES pthread) + else (LIBPTHREAD) + set (PTHREAD_LIBRARIES "") + endif() + set (PTHREAD_INCLUDE_DIR "") + endif (WIN32) +else (${WITH_THREADING} STREQUAL ON) + set (PTHREAD_LIBRARIES "") + set (PTHREAD_INCLUDE_DIR "") +endif (${WITH_THREADING} STREQUAL ON) + option(DOCUMENTATION "Build documentation?" ON) # ======================================== diff --git a/ChangeLog.txt b/ChangeLog.txt index 50f02d9c..bfb4a856 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,9 @@ Library: - Fix memory leak that occurred if mosquitto_reconnect() was used when TLS errors were present. Closes #592. +Build: +- Fix clients not being compiled with threading support when using CMake. + Closes #983. 1.5.3 - 20180925 ================ diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index a6b2c018..a34198d5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,5 +1,5 @@ include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/lib - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) + ${STDBOOL_H_PATH} ${STDINT_H_PATH} ${PTHREAD_INCLUDE_DIR}) link_directories(${mosquitto_BINARY_DIR}/lib) set(shared_src client_shared.c client_shared.h) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d537e776..c92571aa 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -2,30 +2,6 @@ option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libra option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF) add_subdirectory(cpp) -option(WITH_THREADING "Include client library threading support?" ON) -if (${WITH_THREADING} STREQUAL ON) - add_definitions("-DWITH_THREADING") - if (WIN32) - if (CMAKE_CL_64) - set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x64\\pthreadVC2.lib) - else (CMAKE_CL_64) - set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib) - endif (CMAKE_CL_64) - set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include) - else (WIN32) - find_library(LIBPTHREAD pthread) - if (LIBPTHREAD) - set (PTHREAD_LIBRARIES pthread) - else (LIBPTHREAD) - set (PTHREAD_LIBRARIES "") - endif() - set (PTHREAD_INCLUDE_DIR "") - endif (WIN32) -else (${WITH_THREADING} STREQUAL ON) - set (PTHREAD_LIBRARIES "") - set (PTHREAD_INCLUDE_DIR "") -endif (${WITH_THREADING} STREQUAL ON) - include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/lib ${STDBOOL_H_PATH} ${STDINT_H_PATH} ${OPENSSL_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR})