From a0e7165a9cfa639a4c2cefe967e09bade4955998 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 6 Aug 2019 12:01:29 +0100 Subject: [PATCH] Fix WITH_STATIC_LIBRARIES using CMake on Windows Closes #1369. Thanks to TimmvonderMehden --- CMakeLists.txt | 3 +++ ChangeLog.txt | 1 + client/CMakeLists.txt | 13 +++++++++---- lib/CMakeLists.txt | 4 +--- lib/cpp/CMakeLists.txt | 2 +- lib/cpp/mosquittopp.h | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c670628d..ff1c4e23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,9 @@ endif (WITH_SOCKS) 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) if (WITH_THREADING) add_definitions("-DWITH_THREADING") diff --git a/ChangeLog.txt b/ChangeLog.txt index f449d651..22bdc2d8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ Broker: Build: - Fix missing function warnings on NetBSD. +- Fix WITH_STATIC_LIBRARIES using CMake on Windows. Closes #1369. 1.6.4 - 20190801 diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index d928650c..6aa24b2b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -13,10 +13,15 @@ add_executable(mosquitto_pub pub_client.c pub_shared.c ${shared_src}) add_executable(mosquitto_sub sub_client.c sub_client_output.c ${shared_src}) add_executable(mosquitto_rr rr_client.c pub_shared.c sub_client_output.c ${shared_src}) - -target_link_libraries(mosquitto_pub libmosquitto) -target_link_libraries(mosquitto_sub libmosquitto) -target_link_libraries(mosquitto_rr libmosquitto) +if (WITH_STATIC_LIBRARIES) + target_link_libraries(mosquitto_pub libmosquitto_static) + target_link_libraries(mosquitto_sub libmosquitto_static) + target_link_libraries(mosquitto_rr libmosquitto_static) +else() + target_link_libraries(mosquitto_pub libmosquitto) + target_link_libraries(mosquitto_sub libmosquitto) + target_link_libraries(mosquitto_rr libmosquitto) +endif() if (QNX) target_link_libraries(mosquitto_pub socket) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 221c2307..e1521f12 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,3 @@ -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) add_subdirectory(cpp) include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/lib @@ -102,7 +100,7 @@ if (WITH_STATIC_LIBRARIES) target_link_libraries(libmosquitto_static ${LIBRARIES}) set_target_properties(libmosquitto_static PROPERTIES - OUTPUT_NAME mosquitto + OUTPUT_NAME mosquitto_static VERSION ${VERSION} ) diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 89eb560f..b39ac3f5 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -29,7 +29,7 @@ if (WITH_STATIC_LIBRARIES) target_link_libraries(mosquittopp_static ${LIBRARIES}) set_target_properties(mosquittopp_static PROPERTIES - OUTPUT_NAME mosquittopp + OUTPUT_NAME mosquittopp_static VERSION ${VERSION} ) diff --git a/lib/cpp/mosquittopp.h b/lib/cpp/mosquittopp.h index 8d2e98b0..d3f388c0 100644 --- a/lib/cpp/mosquittopp.h +++ b/lib/cpp/mosquittopp.h @@ -17,7 +17,7 @@ Contributors: #ifndef MOSQUITTOPP_H #define MOSQUITTOPP_H -#ifdef _WIN32 +#if defined(_WIN32) && !defined(LIBMOSQUITTO_STATIC) # ifdef mosquittopp_EXPORTS # define mosqpp_EXPORT __declspec(dllexport) # else