From 102c2757644dcfd0568b49da75ed9325f7e91b70 Mon Sep 17 00:00:00 2001 From: Abilio Marques Date: Fri, 6 May 2022 16:47:53 +0200 Subject: [PATCH 1/9] broker: add command line argument to test configuration and exit Signed-off-by: Abilio Marques --- ChangeLog.txt | 2 ++ src/conf.c | 5 ++++- src/mosquitto.c | 10 ++++++++++ src/mosquitto_broker_internal.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 16982b2a..705115d5 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -55,6 +55,8 @@ Broker: - Bridge reconnection backoff improvements. - Add bridge_tls_use_os_certs option to allow bridges to be easily configured to trust default CA certificates. Closes #2473. +- Add `--test-config` option which can be used to test a configuration file + before trying to use it in a live broker. Closes #2521. Plugins / plugin interface: - Add persist-sqlite plugin. diff --git a/src/conf.c b/src/conf.c index ac470230..0439a41d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -387,9 +387,10 @@ static void print_usage(void) printf(" Not recommended in conjunction with the -c option.\n"); printf(" -v : verbose mode - enable all logging types. This overrides\n"); printf(" any logging options given in the config file.\n"); - printf(" --tls-keylog : Log TLS connection information to a file, to allow\n"); + printf(" --tls-keylog : log TLS connection information to a file, to allow\n"); printf(" debugging with e.g. wireshark. Do not use on a production\n"); printf(" server.\n"); + printf(" --test-config : test config file and exit\n"); printf("\nSee https://mosquitto.org/ for more information.\n\n"); } @@ -454,6 +455,8 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[]) #endif }else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")){ db.verbose = true; + }else if(!strcmp(argv[i], "--test-config")){ + config->test_configuration = true; }else{ fprintf(stderr, "Error: Unknown option '%s'.\n",argv[i]); print_usage(); diff --git a/src/mosquitto.c b/src/mosquitto.c index 0cdfb807..94c158f9 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -264,6 +264,16 @@ int main(int argc, char *argv[]) rc = config__parse_args(&config, argc, argv); if(rc != MOSQ_ERR_SUCCESS) return rc; + if(config.test_configuration){ + if(!db.config_file){ + log__printf(NULL, MOSQ_LOG_ERR, "Please provide a configuration file to test."); + return MOSQ_ERR_INVAL; + }else{ + log__printf(NULL, MOSQ_LOG_INFO, "Configuration file is OK."); + return MOSQ_ERR_SUCCESS; + } + } + rc = keepalive__init(); if(rc != MOSQ_ERR_SUCCESS) return rc; diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 3839728d..f1e0b2c3 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -306,6 +306,7 @@ struct mosquitto__config { uint16_t cmd_port[CMD_PORT_LIMIT]; int cmd_port_count; bool daemon; + bool test_configuration; bool enable_control_api; int global_max_clients; int global_max_connections; From 634d75a5b2a210ff5a2e09e545a8ba50c94152cf Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 8 May 2022 21:49:13 +0100 Subject: [PATCH 2/9] Alphabetise --- src/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index 0439a41d..0aa89be5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -387,10 +387,10 @@ static void print_usage(void) printf(" Not recommended in conjunction with the -c option.\n"); printf(" -v : verbose mode - enable all logging types. This overrides\n"); printf(" any logging options given in the config file.\n"); + printf(" --test-config : test config file and exit\n"); printf(" --tls-keylog : log TLS connection information to a file, to allow\n"); printf(" debugging with e.g. wireshark. Do not use on a production\n"); printf(" server.\n"); - printf(" --test-config : test config file and exit\n"); printf("\nSee https://mosquitto.org/ for more information.\n\n"); } From 4487b98dbbb586c31179c46d1c94d4dba583ce98 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 8 May 2022 21:53:14 +0100 Subject: [PATCH 3/9] Fix clean --- test/unit/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/Makefile b/test/unit/Makefile index a89110fb..7367a291 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -198,7 +198,7 @@ test-broker : build test : test-broker test-lib clean : - -rm -rf mosq_test bridge_topic_test keepalive_test persist_read_test persist_write_test + -rm -rf mosq_test bridge_topic_test keepalive_test persist_read_test persist_write_test subs_test -rm -rf *.o *.gcda *.gcno coverage.info out/ coverage : From 50dc0399050315eca16aae1b4284e08dccb45eb0 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 9 May 2022 23:07:16 +0100 Subject: [PATCH 4/9] Migrate Coverity Scan run to GH actions This is pending the addition of secrets. --- .github/workflows/coverity-scan.yml | 24 +++++++++++++++++++ .github/workflows/covsync.yml | 21 ----------------- .travis.yml | 36 ----------------------------- travis-configure.sh | 5 ---- travis-install.sh | 16 ------------- 5 files changed, 24 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/coverity-scan.yml delete mode 100644 .github/workflows/covsync.yml delete mode 100644 .travis.yml delete mode 100755 travis-configure.sh delete mode 100755 travis-install.sh diff --git a/.github/workflows/coverity-scan.yml b/.github/workflows/coverity-scan.yml new file mode 100644 index 00000000..27310bd7 --- /dev/null +++ b/.github/workflows/coverity-scan.yml @@ -0,0 +1,24 @@ +name: Coverity Scan fixes and develop branches on a weekly basis + +on: + workflow_dispatch: + schedule: + - cron: "7 3 * * 0" + +jobs: + coverity: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Dependencies + run: sudo apt-get install -y libcjson-dev libsqlite3-dev libssl-dev uthash-dev + + - uses: vapier/coverity-scan-action@v1 + with: + build_language: 'cxx' + project: "eclipse/mosquitto" + token: ${{ secrets.COVERITY_SCAN_TOKEN }} + email: ${{ secrets.COVERITY_SCAN_EMAIL }} + command: "make binary" + diff --git a/.github/workflows/covsync.yml b/.github/workflows/covsync.yml deleted file mode 100644 index 233b009e..00000000 --- a/.github/workflows/covsync.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: "Synchronise Coverity Scan branches on a weekly basis" - -on: - workflow_dispatch: - schedule: - - cron: "7 3 * * 0" - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - run: | - git checkout coverity-fixes - git reset --hard origin/fixes - git push origin coverity-fixes - git checkout coverity-develop - git reset --hard origin/develop - git push origin coverity-develop diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6938aaa2..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: c -compiler: - - gcc - - clang - -os: - - linux - - osx - -dist: - - bionic - -sudo: true - -env: - global: - # COVERITY_SCAN_TOKEN - - secure: "j58a3zOmHbWvKOfBaR2WJAU0Lz95M0u3Ji9NUn0Gj+v91z/vd0COF8dR6QO03V9fDms44ghBiUOblgfb8z/GFOaagn2FoHUrSka/Sju+gIFejgeSqwyxL3CjcX69M1f/npiePQDDtD5mb4dZTDZ4Nl3BpTqg+Qtar9/S/7LoheecWdd6kFDDMr+0yx3/nibwbC0+tpXftiB62tgaGwABQBvfQbgBXUxJ+0zaKXORiKmhwnEC15Bub0WmBhmZxahzlDMU2cEzxKVQbYrcf0TqZpbPhN7H42d3ssQJ3ogbqJmptZpoRdv9de6G0Hzq5QDLjkQxd+3z4hxRqOPzICoawkljQ6CF/JOSlqRXTP0/272MBHzgancQpQhO5yfB3eV4OFldQAdtIKHV04jQ9uSPYOi48To//HGOG8GOp6jFMrpKs6T6P8UiB+GTe57GjBdQI5uqZiEBMdc5MNaqDDoskdr+jTsnGJg6uY9ARrap3WFFEWiaTbe/wbE7+o0isb79PmgBzFLpcwpBFgfyQUiDb+e8S2d3ugKeIVlsSlrF7ZTXC40Y+qVwGzvf/RSM3+c9N/ikFmrLdzn0rBrwna4t3vPrBoU1seoCAZu5hwAU0+xNCN4P9M1s4tOnrG7Lq5URqkP0n9gTXvI8rQ7dDJibjP+5RoZUOd1XPkHbyN4Kseg=" - -script: - - ./travis-configure.sh - - if [[ "$COVERITY_SCAN_BRANCH" != 1 ]]; then make ; make test ; fi - -before_install: - - ./travis-install.sh - - -addons: - coverity_scan: - project: - name: "eclipse/mosquitto" - description: "Build submitted via Travis CI" - notification_email: roger@atchoo.org - build_command_prepend: ./travis-configure.sh - build_command: "make binary -j 4" - branch_pattern: coverity-.* diff --git a/travis-configure.sh b/travis-configure.sh deleted file mode 100755 index d9e55c49..00000000 --- a/travis-configure.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -if [ "$TRAVIS_OS_NAME" == "osx" ]; then - cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl . -fi diff --git a/travis-install.sh b/travis-install.sh deleted file mode 100755 index 4e727a65..00000000 --- a/travis-install.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - - -if [ "$TRAVIS_OS_NAME" == "linux" ]; then - sudo apt-get update -qq - sudo apt-get install -y debhelper libc-ares-dev libssl-dev libwrap0-dev python-all python3-all uthash-dev xsltproc docbook-xsl libcunit1-dev - git clone https://github.com/DaveGamble/cJSON - make -C cJSON - sudo make PREFIX=/usr -C cJSON install -fi - -if [ "$TRAVIS_OS_NAME" == "osx" ]; then - HOMEBREW_NO_AUTO_UPDATE=1 brew install c-ares cjson openssl libwebsockets -fi - -sudo pip install paho-mqtt From 6568984054cdab03d5cc80e658093200fe04fbb0 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 19:30:04 +0200 Subject: [PATCH 5/9] Fix memory issues in kqueue operations Signed-off-by: Kai Buschulte --- src/mux_kqueue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mux_kqueue.c b/src/mux_kqueue.c index 86d9a973..22288e3e 100644 --- a/src/mux_kqueue.c +++ b/src/mux_kqueue.c @@ -52,7 +52,7 @@ int mux_kqueue__add_listeners(struct mosquitto__listener_sock *listensock, int l struct kevent ev; int i; - memset(&event_list, 0, sizeof(struct kevent)*MAX_EVENTS); + memset(&ev, 0, sizeof(struct kevent)); for(i=0; ievents != EVFILT_WRITE){ - EV_SET(&ev, context->sock, EVFILT_WRITE, EV_ADD, 0, 0, &context); + EV_SET(&ev, context->sock, EVFILT_WRITE, EV_ADD, 0, 0, context); if(kevent(db.kqueuefd, &ev, 1, NULL, 0, NULL) == -1){ log__printf(NULL, MOSQ_LOG_DEBUG, "Error in kqueue re-registering to EVFILT_WRITE: %s", strerror(errno)); } @@ -107,7 +107,7 @@ int mux_kqueue__remove_out(struct mosquitto *context) struct kevent ev; if(context->events == EVFILT_WRITE){ - EV_SET(&ev, context->sock, EVFILT_WRITE, EV_DELETE, 0, 0, &context); + EV_SET(&ev, context->sock, EVFILT_WRITE, EV_DELETE, 0, 0, context); if(kevent(db.kqueuefd, &ev, 1, NULL, 0, NULL) == -1){ log__printf(NULL, MOSQ_LOG_DEBUG, "Error in kqueue removing EVFILT_WRITE: %s", strerror(errno)); } @@ -137,8 +137,8 @@ int mux_kqueue__delete(struct mosquitto *context) struct kevent ev[2]; if(context->sock != INVALID_SOCKET){ - EV_SET(&ev[0], context->sock, EVFILT_READ, EV_DELETE, 0, 0, &context); - EV_SET(&ev[1], context->sock, EVFILT_WRITE, EV_DELETE, 0, 0, &context); + EV_SET(&ev[0], context->sock, EVFILT_READ, EV_DELETE, 0, 0, context); + EV_SET(&ev[1], context->sock, EVFILT_WRITE, EV_DELETE, 0, 0, context); if(kevent(db.kqueuefd, ev, 2, NULL, 0, NULL) == -1){ return 1; } From 15208e55ccd098bc2021202a3c4af458ca2d0082 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 18:20:57 +0200 Subject: [PATCH 6/9] Use preinstalled CMake find module for SQLite3 CMake >= 3.14 comes with a preinstalled FindSQLite3 module, which now replaces the self-written one. Signed-off-by: Kai Buschulte --- CMakeLists.txt | 4 +-- ChangeLog.txt | 3 +++ cmake/Findsqlite3.cmake | 38 --------------------------- plugins/persist-sqlite/CMakeLists.txt | 10 +++---- 4 files changed, 10 insertions(+), 45 deletions(-) delete mode 100644 cmake/Findsqlite3.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e733aa..de5941f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # To configure the build options either use the CMake gui, or run the command # line utility including the "-i" option. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) set (VERSION 2.1.0) project(mosquitto @@ -50,7 +50,7 @@ endif() option(WITH_SQLITE "Include sqlite persistence support?" ON) if (WITH_SQLITE) - find_package(sqlite3 REQUIRED) + find_package(SQLite3 REQUIRED) add_definitions("-DWITH_SQLITE") endif() diff --git a/ChangeLog.txt b/ChangeLog.txt index 705115d5..19d5ffff 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -139,6 +139,9 @@ Clients: - Add float printing option to mosquitto_sub. - Fix `-f` and `-s` options in mosquitto_rr. +Build: +- Increased CMake minimal required version to 3.14, which is required for the + preinstalled SQLite3 find module. 2.0.14 - 2021-11-17 =================== diff --git a/cmake/Findsqlite3.cmake b/cmake/Findsqlite3.cmake deleted file mode 100644 index e706ce2a..00000000 --- a/cmake/Findsqlite3.cmake +++ /dev/null @@ -1,38 +0,0 @@ -INCLUDE( FindPackageHandleStandardArgs ) - -# Checks an environment variable; note that the first check -# does not require the usual CMake $-sign. -IF( DEFINED ENV{SQLITE3_DIR} ) - SET( SQLITE3_DIR "$ENV{SQLITE3_DIR}" ) -ENDIF() - -FIND_PATH( - SQLITE3_INCLUDE_DIR - sqlite3.h - HINTS - SQLITE3_DIR -) - -FIND_LIBRARY( SQLITE3_LIBRARY - NAMES sqlite3 - HINTS ${SQLITE3_DIR} -) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS( sqlite3 DEFAULT_MSG - SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY -) - -IF( SQLITE3_FOUND ) - SET( SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR} ) - SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY} ) - - MARK_AS_ADVANCED( - SQLITE3_LIBRARY - SQLITE3_INCLUDE_DIR - SQLITE3_DIR - ) -ELSE() - SET( SQLITE3_DIR "" CACHE STRING - "An optional hint to a directory for finding `sqlite3`" - ) -ENDIF() diff --git a/plugins/persist-sqlite/CMakeLists.txt b/plugins/persist-sqlite/CMakeLists.txt index c53db27f..08c67292 100644 --- a/plugins/persist-sqlite/CMakeLists.txt +++ b/plugins/persist-sqlite/CMakeLists.txt @@ -1,7 +1,6 @@ if(SQLITE3_FOUND AND CJSON_FOUND) add_definitions("-DWITH_CJSON") set(CLIENT_INC - "${SQLITE3_INCLUDE_DIRS}" "${STDBOOL_H_PATH}" "${STDINT_H_PATH}" "${mosquitto_SOURCE_DIR}" @@ -10,8 +9,6 @@ if(SQLITE3_FOUND AND CJSON_FOUND) "${mosquitto_SOURCE_DIR}/src" ) - set(CLIENT_DIR "${mosquitto_BINARY_DIR}/lib" "${SQLITE3_DIR}") - add_library(mosquitto_persist_sqlite MODULE base_msgs.c clients.c @@ -25,7 +22,7 @@ if(SQLITE3_FOUND AND CJSON_FOUND) ) target_include_directories(mosquitto_persist_sqlite PRIVATE - ${CLIENT_INC} ${SQLITE3_INCLUDE_DIR} + ${CLIENT_INC} ) link_directories(${CLIENT_DIR} "${mosquitto_SOURCE_DIR}") @@ -34,7 +31,10 @@ 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 + SQLite::SQLite3 + ) if(WIN32) target_link_libraries(mosquitto_persist_sqlite PRIVATE mosquitto) endif() From 0e9df05d0d4ccc62bf5c6abc230762ffe4ee7db6 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Mon, 9 May 2022 18:59:02 +0200 Subject: [PATCH 7/9] 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 8/9] 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 9/9] 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; } } -