From 0e9df05d0d4ccc62bf5c6abc230762ffe4ee7db6 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 18:59:02 +0200 Subject: [PATCH 1/3] Add imported target for cJSON Signed-off-by: Kai Buschulte --- CMakeLists.txt | 2 +- apps/mosquitto_ctrl/CMakeLists.txt | 7 +------ client/CMakeLists.txt | 17 +++-------------- cmake/FindcJSON.cmake | 11 +++++++++++ plugins/dynamic-security/CMakeLists.txt | 9 +++++---- plugins/persist-sqlite/CMakeLists.txt | 7 +++++-- src/CMakeLists.txt | 2 +- 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e733aa..9624bdbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,7 @@ if(WITH_CJSON) FIND_PACKAGE(cJSON) if(CJSON_FOUND) message(STATUS ${CJSON_FOUND}) - add_definitions(-DWITH_CJSON) + target_compile_definitions(cJSON INTERFACE WITH_CJSON) else() message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") endif() diff --git a/apps/mosquitto_ctrl/CMakeLists.txt b/apps/mosquitto_ctrl/CMakeLists.txt index dd6ba27f..201d07ac 100644 --- a/apps/mosquitto_ctrl/CMakeLists.txt +++ b/apps/mosquitto_ctrl/CMakeLists.txt @@ -1,8 +1,4 @@ if(WITH_TLS AND CJSON_FOUND) - add_definitions("-DWITH_CJSON") - - link_directories(${CJSON_DIR}) - add_executable(mosquitto_ctrl mosquitto_ctrl.c mosquitto_ctrl.h ../../common/base64_mosq.c ../../common/base64_mosq.h @@ -21,7 +17,6 @@ if(WITH_TLS AND CJSON_FOUND) ) target_include_directories(mosquitto_ctrl PRIVATE - "${CJSON_INCLUDE_DIRS}" "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" @@ -63,7 +58,7 @@ if(WITH_TLS AND CJSON_FOUND) target_link_libraries(mosquitto_ctrl PRIVATE ${OPENSSL_LIBRARIES} - ${CJSON_LIBRARIES} + cJSON ) if (WITH_THREADING AND NOT WIN32) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 6b988213..3d99b253 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -12,14 +12,6 @@ set(CLIENT_INC "${mosquitto_SOURCE_DIR}/include" ) -set(CLIENT_DIR ${mosquitto_BINARY_DIR}/lib) - -if(CJSON_FOUND) - add_definitions("-DWITH_CJSON") - set(CLIENT_DIR "${CLIENT_DIR};${CJSON_DIR}") - set(CLIENT_INC "${CLIENT_INC};${CJSON_INCLUDE_DIRS}") -endif() - if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN) add_definitions("-DWITH_WEBSOCKETS=WS_IS_BUILTIN") endif() @@ -46,13 +38,10 @@ if(WITH_BUNDLED_DEPS) target_include_directories(mosquitto_rr PRIVATE "${mosquitto_SOURCE_DIR}/deps") endif() -link_directories(${CLIENT_DIR}) - - if(CJSON_FOUND) - target_link_libraries(mosquitto_pub PRIVATE ${CJSON_LIBRARIES}) - target_link_libraries(mosquitto_sub PRIVATE ${CJSON_LIBRARIES}) - target_link_libraries(mosquitto_rr PRIVATE ${CJSON_LIBRARIES}) + target_link_libraries(mosquitto_pub PRIVATE cJSON) + target_link_libraries(mosquitto_sub PRIVATE cJSON) + target_link_libraries(mosquitto_rr PRIVATE cJSON) endif() if(WITH_STATIC_LIBRARIES) diff --git a/cmake/FindcJSON.cmake b/cmake/FindcJSON.cmake index 1b1455d0..5458e07a 100644 --- a/cmake/FindcJSON.cmake +++ b/cmake/FindcJSON.cmake @@ -31,6 +31,17 @@ IF( CJSON_FOUND ) CJSON_INCLUDE_DIR CJSON_DIR ) + + add_library(cJSON SHARED IMPORTED) + set_target_properties(cJSON + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CJSON_INCLUDE_DIRS}" + ) + + set_target_properties(cJSON + PROPERTIES + IMPORTED_LOCATION "${CJSON_LIBRARY}" + ) ELSE() SET( CJSON_DIR "" CACHE STRING "An optional hint to a directory for finding `cJSON`" diff --git a/plugins/dynamic-security/CMakeLists.txt b/plugins/dynamic-security/CMakeLists.txt index f5804f1a..fd5b542f 100644 --- a/plugins/dynamic-security/CMakeLists.txt +++ b/plugins/dynamic-security/CMakeLists.txt @@ -1,9 +1,6 @@ if(CJSON_FOUND AND WITH_TLS) - add_definitions("-DWITH_CJSON") - set(CLIENT_INC "${CJSON_INCLUDE_DIRS}" - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" @@ -57,7 +54,11 @@ if(CJSON_FOUND AND WITH_TLS) POSITION_INDEPENDENT_CODE 1 ) - target_link_libraries(mosquitto_dynamic_security PRIVATE ${CJSON_LIBRARIES} ${OPENSSL_LIBRARIES}) + target_link_libraries(mosquitto_dynamic_security + PRIVATE + cJSON + OpenSSL::SSL + ) if(WIN32) target_link_libraries(mosquitto_dynamic_security PRIVATE mosquitto) install(TARGETS mosquitto_dynamic_security diff --git a/plugins/persist-sqlite/CMakeLists.txt b/plugins/persist-sqlite/CMakeLists.txt index c53db27f..89b551ee 100644 --- a/plugins/persist-sqlite/CMakeLists.txt +++ b/plugins/persist-sqlite/CMakeLists.txt @@ -1,5 +1,4 @@ if(SQLITE3_FOUND AND CJSON_FOUND) - add_definitions("-DWITH_CJSON") set(CLIENT_INC "${SQLITE3_INCLUDE_DIRS}" "${STDBOOL_H_PATH}" @@ -34,7 +33,11 @@ if(SQLITE3_FOUND AND CJSON_FOUND) POSITION_INDEPENDENT_CODE 1 ) - target_link_libraries(mosquitto_persist_sqlite PRIVATE ${SQLITE3_LIBRARIES}) + target_link_libraries(mosquitto_persist_sqlite + PRIVATE + ${SQLITE3_LIBRARIES} + cJSON + ) if(WIN32) target_link_libraries(mosquitto_persist_sqlite PRIVATE mosquitto) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c053fb5c..711c1fed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -219,7 +219,7 @@ if(WITH_WEBSOCKETS) endif() if(CJSON_FOUND) - set (MOSQ_LIBS ${MOSQ_LIBS} cjson) + target_link_libraries(mosquitto PRIVATE cJSON) endif() target_include_directories(mosquitto PRIVATE From 7e4746aac4e3a65655cff2ff80ed0e090c17fe88 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 19:15:13 +0200 Subject: [PATCH 2/3] Fix missing symbols MacOS Core symbols needed by plugins are now properly linked to their objects * Remove link_directories() call: This specification is not necessary for our own libraries as cmake shares this information over the targets. If needed they should be specified target specific, like done for the external DLT library. Signed-off-by: Kai Buschulte --- CMakeLists.txt | 4 +- lib/CMakeLists.txt | 20 ++++----- lib/cpp/CMakeLists.txt | 16 +++---- plugins/dynamic-security/CMakeLists.txt | 3 +- .../examples/add-properties/CMakeLists.txt | 4 +- plugins/examples/auth-by-ip/CMakeLists.txt | 4 +- .../client-lifetime-stats/CMakeLists.txt | 8 +--- .../examples/client-properties/CMakeLists.txt | 6 +-- .../examples/connection-state/CMakeLists.txt | 4 +- plugins/examples/delayed-auth/CMakeLists.txt | 4 +- plugins/examples/force-retain/CMakeLists.txt | 7 +--- .../examples/message-timestamp/CMakeLists.txt | 5 +-- .../payload-modification/CMakeLists.txt | 8 +--- .../payload-size-stats/CMakeLists.txt | 8 +--- .../plugin-event-stats/CMakeLists.txt | 8 +--- .../print-ip-on-publish/CMakeLists.txt | 8 +--- .../topic-modification/CMakeLists.txt | 8 +--- plugins/examples/wildcard-temp/CMakeLists.txt | 4 +- plugins/persist-sqlite/CMakeLists.txt | 5 +-- src/CMakeLists.txt | 42 +++++++++---------- 20 files changed, 63 insertions(+), 113 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9624bdbc..d8448bdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,10 +79,8 @@ endif() option(WITH_DLT "Include DLT support?" OFF) message(STATUS "WITH_DLT = ${WITH_DLT}") if(WITH_DLT) - #find_package(DLT REQUIRED) find_package(PkgConfig) - pkg_check_modules(DLT "automotive-dlt >= 2.11") - add_definitions("-DWITH_DLT") + pkg_check_modules(DLT "automotive-dlt >= 2.11" REQUIRED) endif() option(WITH_CJSON "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)?" ON) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e5c26f03..606a18a0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -101,18 +101,18 @@ if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN) "${mosquitto_SOURCE_DIR}/deps/picohttpparser") endif() -target_include_directories(libmosquitto PRIVATE - "${OPENSSL_INCLUDE_DIR}" - "${STDBOOL_H_PATH}" - "${STDINT_H_PATH}" - "${mosquitto_SOURCE_DIR}" - "${mosquitto_SOURCE_DIR}/common" - "${mosquitto_SOURCE_DIR}/include" - "${mosquitto_SOURCE_DIR}/lib" +target_include_directories(libmosquitto + PUBLIC + "${mosquitto_SOURCE_DIR}/include" + "${OPENSSL_INCLUDE_DIR}" + PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/common" + "${mosquitto_SOURCE_DIR}/lib" ) -link_directories("${mosquitto_SOURCE_DIR}/lib") - if(WITH_BUNDLED_DEPS) target_include_directories(libmosquitto PRIVATE "${mosquitto_SOURCE_DIR}/deps" diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 03329d7c..c7fe00c4 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -8,16 +8,16 @@ set_target_properties(mosquittopp PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -target_include_directories(mosquittopp PRIVATE - "${STDBOOL_H_PATH}" - "${STDINT_H_PATH}" - "${mosquitto_SOURCE_DIR}/include" - "${mosquitto_SOURCE_DIR}/lib" - "${mosquitto_SOURCE_DIR}/lib/cpp" +target_include_directories(mosquittopp + PUBLIC + "${mosquitto_SOURCE_DIR}/include" + PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/lib/cpp" ) -link_directories(${mosquitto_BINARY_DIR}/lib) - target_link_libraries(mosquittopp PRIVATE libmosquitto) if (WITH_THREADING AND NOT WIN32) diff --git a/plugins/dynamic-security/CMakeLists.txt b/plugins/dynamic-security/CMakeLists.txt index fd5b542f..cda3945d 100644 --- a/plugins/dynamic-security/CMakeLists.txt +++ b/plugins/dynamic-security/CMakeLists.txt @@ -47,7 +47,6 @@ if(CJSON_FOUND AND WITH_TLS) "${mosquitto_SOURCE_DIR}/deps" ) endif() - link_directories(${CLIENT_DIR} "${mosquitto_SOURCE_DIR}") set_target_properties(mosquitto_dynamic_security PROPERTIES PREFIX "" @@ -59,8 +58,8 @@ if(CJSON_FOUND AND WITH_TLS) cJSON OpenSSL::SSL ) + target_link_libraries(mosquitto_dynamic_security PRIVATE mosquitto) if(WIN32) - target_link_libraries(mosquitto_dynamic_security PRIVATE mosquitto) install(TARGETS mosquitto_dynamic_security DESTINATION "${CMAKE_INSTALL_BINDIR}") else() diff --git a/plugins/examples/add-properties/CMakeLists.txt b/plugins/examples/add-properties/CMakeLists.txt index 88f7e4dd..afc4d4ef 100644 --- a/plugins/examples/add-properties/CMakeLists.txt +++ b/plugins/examples/add-properties/CMakeLists.txt @@ -16,9 +16,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/auth-by-ip/CMakeLists.txt b/plugins/examples/auth-by-ip/CMakeLists.txt index 23390bdf..340c2429 100644 --- a/plugins/examples/auth-by-ip/CMakeLists.txt +++ b/plugins/examples/auth-by-ip/CMakeLists.txt @@ -16,9 +16,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/client-lifetime-stats/CMakeLists.txt b/plugins/examples/client-lifetime-stats/CMakeLists.txt index ddabc98b..6e4fe0fb 100644 --- a/plugins/examples/client-lifetime-stats/CMakeLists.txt +++ b/plugins/examples/client-lifetime-stats/CMakeLists.txt @@ -5,7 +5,6 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" @@ -13,15 +12,12 @@ target_include_directories(${PLUGIN_NAME} PRIVATE "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/client-properties/CMakeLists.txt b/plugins/examples/client-properties/CMakeLists.txt index 39121881..7b262bff 100644 --- a/plugins/examples/client-properties/CMakeLists.txt +++ b/plugins/examples/client-properties/CMakeLists.txt @@ -11,16 +11,12 @@ target_include_directories(${PLUGIN_NAME} PRIVATE "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/connection-state/CMakeLists.txt b/plugins/examples/connection-state/CMakeLists.txt index b2cc2a46..3a6f4996 100644 --- a/plugins/examples/connection-state/CMakeLists.txt +++ b/plugins/examples/connection-state/CMakeLists.txt @@ -16,9 +16,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/delayed-auth/CMakeLists.txt b/plugins/examples/delayed-auth/CMakeLists.txt index e2811968..903db900 100644 --- a/plugins/examples/delayed-auth/CMakeLists.txt +++ b/plugins/examples/delayed-auth/CMakeLists.txt @@ -22,9 +22,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/force-retain/CMakeLists.txt b/plugins/examples/force-retain/CMakeLists.txt index b8984c65..d4d872ef 100644 --- a/plugins/examples/force-retain/CMakeLists.txt +++ b/plugins/examples/force-retain/CMakeLists.txt @@ -12,15 +12,12 @@ target_include_directories(${PLUGIN_NAME} PRIVATE "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/message-timestamp/CMakeLists.txt b/plugins/examples/message-timestamp/CMakeLists.txt index e40f528c..8a674285 100644 --- a/plugins/examples/message-timestamp/CMakeLists.txt +++ b/plugins/examples/message-timestamp/CMakeLists.txt @@ -5,7 +5,6 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" @@ -17,9 +16,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/payload-modification/CMakeLists.txt b/plugins/examples/payload-modification/CMakeLists.txt index dbeaa4dc..0c9ad1c1 100644 --- a/plugins/examples/payload-modification/CMakeLists.txt +++ b/plugins/examples/payload-modification/CMakeLists.txt @@ -5,22 +5,18 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/payload-size-stats/CMakeLists.txt b/plugins/examples/payload-size-stats/CMakeLists.txt index f504f52b..f3c62875 100644 --- a/plugins/examples/payload-size-stats/CMakeLists.txt +++ b/plugins/examples/payload-size-stats/CMakeLists.txt @@ -5,22 +5,18 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/plugin-event-stats/CMakeLists.txt b/plugins/examples/plugin-event-stats/CMakeLists.txt index d12adce8..972994a3 100644 --- a/plugins/examples/plugin-event-stats/CMakeLists.txt +++ b/plugins/examples/plugin-event-stats/CMakeLists.txt @@ -5,22 +5,18 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/print-ip-on-publish/CMakeLists.txt b/plugins/examples/print-ip-on-publish/CMakeLists.txt index 2528f75e..1cf4b30d 100644 --- a/plugins/examples/print-ip-on-publish/CMakeLists.txt +++ b/plugins/examples/print-ip-on-publish/CMakeLists.txt @@ -5,22 +5,18 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/topic-modification/CMakeLists.txt b/plugins/examples/topic-modification/CMakeLists.txt index 361d7433..1063ddee 100644 --- a/plugins/examples/topic-modification/CMakeLists.txt +++ b/plugins/examples/topic-modification/CMakeLists.txt @@ -5,22 +5,18 @@ add_library(${PLUGIN_NAME} MODULE ) target_include_directories(${PLUGIN_NAME} PRIVATE - "${OPENSSL_INCLUDE_DIR}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" "${mosquitto_SOURCE_DIR}/include" ) -link_directories(${mosquitto_SOURCE_DIR}) - set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() + +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/examples/wildcard-temp/CMakeLists.txt b/plugins/examples/wildcard-temp/CMakeLists.txt index 9e74e568..ff41a8a8 100644 --- a/plugins/examples/wildcard-temp/CMakeLists.txt +++ b/plugins/examples/wildcard-temp/CMakeLists.txt @@ -23,9 +23,7 @@ set_target_properties(${PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -if(WIN32) - target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) -endif() +target_link_libraries(${PLUGIN_NAME} PRIVATE mosquitto) # Don't install, these are example plugins only. #install(TARGETS ${PLUGIN_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/plugins/persist-sqlite/CMakeLists.txt b/plugins/persist-sqlite/CMakeLists.txt index 89b551ee..1489908b 100644 --- a/plugins/persist-sqlite/CMakeLists.txt +++ b/plugins/persist-sqlite/CMakeLists.txt @@ -26,7 +26,6 @@ if(SQLITE3_FOUND AND CJSON_FOUND) target_include_directories(mosquitto_persist_sqlite PRIVATE ${CLIENT_INC} ${SQLITE3_INCLUDE_DIR} ) - link_directories(${CLIENT_DIR} "${mosquitto_SOURCE_DIR}") set_target_properties(mosquitto_persist_sqlite PROPERTIES PREFIX "" @@ -38,9 +37,7 @@ if(SQLITE3_FOUND AND CJSON_FOUND) ${SQLITE3_LIBRARIES} cJSON ) - if(WIN32) - target_link_libraries(mosquitto_persist_sqlite PRIVATE mosquitto) - endif() + target_link_libraries(mosquitto_persist_sqlite PRIVATE mosquitto) install(TARGETS mosquitto_persist_sqlite RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 711c1fed..250bcfd5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,12 +148,6 @@ endif() add_definitions (-DWITH_BROKER) -if(WITH_DLT) - message(STATUS "DLT_LIBDIR = ${DLT_LIBDIR}") - link_directories(${DLT_LIBDIR}) - set (MOSQ_LIBS ${MOSQ_LIBS} ${DLT_LIBRARIES}) -endif() - set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES}) # Check for getaddrinfo_a include(CheckLibraryExists) @@ -210,7 +204,6 @@ if(WITH_WEBSOCKETS) set (MOSQ_LIBS ${MOSQ_LIBS} websockets_static) if(WIN32) set (MOSQ_LIBS ${MOSQ_LIBS} iphlpapi) - link_directories(${mosquitto_SOURCE_DIR}) endif() else(STATIC_WEBSOCKETS) set (MOSQ_LIBS ${MOSQ_LIBS} websockets) @@ -218,19 +211,28 @@ if(WITH_WEBSOCKETS) endif() endif() +if(WITH_DLT) + message(STATUS "DLT_LIBDIR = ${DLT_LIBDIR}") + target_link_directories(mosquitto PRIVATE ${DLT_LIBDIR}) + set (MOSQ_LIBS ${MOSQ_LIBS} ${DLT_LIBRARIES}) + target_compile_definitions(mosquitto PRIVATE "WITH_DLT") +endif() + if(CJSON_FOUND) target_link_libraries(mosquitto PRIVATE cJSON) endif() -target_include_directories(mosquitto PRIVATE - "${OPENSSL_INCLUDE_DIR}" - "${STDBOOL_H_PATH}" - "${STDINT_H_PATH}" - "${mosquitto_SOURCE_DIR}" - "${mosquitto_SOURCE_DIR}/common" - "${mosquitto_SOURCE_DIR}/include" - "${mosquitto_SOURCE_DIR}/lib" - "${mosquitto_SOURCE_DIR}/src" +target_include_directories(mosquitto + PUBLIC + "${mosquitto_SOURCE_DIR}/include" + "${OPENSSL_INCLUDE_DIR}" + PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/common" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/src" ) if(WITH_BUNDLED_DEPS) target_include_directories(mosquitto PRIVATE @@ -250,11 +252,9 @@ if (WITH_THREADING AND NOT WIN32) target_link_libraries(mosquitto PRIVATE Threads::Threads) endif() -if(WIN32) - set_target_properties(mosquitto PROPERTIES - ENABLE_EXPORTS 1 - ) -endif() +set_target_properties(mosquitto PROPERTIES + ENABLE_EXPORTS 1 +) if(UNIX) if(APPLE) From a3125934dd3dbd5646fead5c068f492d2240322d Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 19:18:49 +0200 Subject: [PATCH 3/3] Fix macOS compile issues Signed-off-by: Kai Buschulte --- common/time_mosq.c | 1 + src/bridge.c | 2 ++ src/context.c | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/time_mosq.c b/common/time_mosq.c index 8e45963d..468d80a3 100644 --- a/common/time_mosq.c +++ b/common/time_mosq.c @@ -21,6 +21,7 @@ Contributors: #ifdef __APPLE__ #include #include +#include #endif #ifdef WIN32 diff --git a/src/bridge.c b/src/bridge.c index aea28feb..793a15fc 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -197,7 +197,9 @@ static int bridge__set_tcp_keepalive(struct mosquitto *context) #else ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (const void*)&enabled, sizeof(enabled)) || +#ifndef __APPLE__ setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (const void*)&idle, sizeof(idle)) || +#endif setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (const void*)&interval, sizeof(interval)) || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (const void*)&counter, sizeof(counter)); #endif diff --git a/src/context.c b/src/context.c index 5fc27e66..9d3a07ec 100644 --- a/src/context.c +++ b/src/context.c @@ -20,6 +20,9 @@ Contributors: #include #include +#ifdef __APPLE__ +#include +#endif #include "mosquitto_broker_internal.h" #include "alias_mosq.h" @@ -318,4 +321,3 @@ void context__remove_from_by_id(struct mosquitto *context) context->in_by_id = false; } } -