diff --git a/CMakeLists.txt b/CMakeLists.txt index efda590b..01ee0bbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,35 +4,35 @@ # 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.0) -cmake_policy(SET CMP0042 NEW) +cmake_minimum_required(VERSION 3.10) -project(mosquitto) set (VERSION 2.0.10) +project(mosquitto + VERSION ${VERSION} + DESCRIPTION "Eclipse Mosquitto" + LANGUAGES C CXX +) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") add_definitions (-DCMAKE -DVERSION=\"${VERSION}\") -if (WIN32) +if(WIN32) add_definitions("-D_CRT_SECURE_NO_WARNINGS") add_definitions("-D_CRT_NONSTDC_NO_DEPRECATE") -endif (WIN32) +endif() if(APPLE) set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup") -endif(APPLE) +endif() include(GNUInstallDirs) include(CheckIncludeFiles) option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON) -option(WITH_TLS - "Include SSL/TLS support?" ON) -option(WITH_TLS_PSK - "Include TLS-PSK support (requires WITH_TLS)?" ON) -option(WITH_EC - "Include Elliptic Curve support (requires WITH_TLS)?" ON) +option(WITH_TLS "Include SSL/TLS support?" ON) +option(WITH_TLS_PSK "Include TLS-PSK support (requires WITH_TLS)?" ON) +option(WITH_EC "Include Elliptic Curve support (requires WITH_TLS)?" ON) if (WITH_TLS) find_package(OpenSSL REQUIRED) add_definitions("-DWITH_TLS") @@ -44,70 +44,69 @@ if (WITH_TLS) if (WITH_EC) add_definitions("-DWITH_EC") endif (WITH_EC) -else (WITH_TLS) +else() set (OPENSSL_INCLUDE_DIR "") -endif (WITH_TLS) +endif() option(WITH_UNIX_SOCKETS "Include Unix Domain Socket support?" ON) -if (WITH_UNIX_SOCKETS AND NOT WIN32) +if(WITH_UNIX_SOCKETS AND NOT WIN32) add_definitions("-DWITH_UNIX_SOCKETS") -endif (WITH_UNIX_SOCKETS AND NOT WIN32) +endif() option(WITH_SOCKS "Include SOCKS5 support?" ON) -if (WITH_SOCKS) +if(WITH_SOCKS) add_definitions("-DWITH_SOCKS") -endif (WITH_SOCKS) +endif() 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) +if(WITH_THREADING) add_definitions("-DWITH_THREADING") - if (WIN32) - if (CMAKE_CL_64) + if(WIN32) + if(CMAKE_CL_64) set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x64\\pthreadVC2.lib) - else (CMAKE_CL_64) + else() set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib) - endif (CMAKE_CL_64) + endif() set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include) - elseif (ANDROID) + elseif(ANDROID) set (PTHREAD_LIBRARIES "") set (PTHREAD_INCLUDE_DIR "") - else (WIN32) + else() find_library(LIBPTHREAD pthread) - if (LIBPTHREAD) + if(LIBPTHREAD) set (PTHREAD_LIBRARIES pthread) - else (LIBPTHREAD) + else() set (PTHREAD_LIBRARIES "") endif() - set (PTHREAD_INCLUDE_DIR "") - endif (WIN32) -else (WITH_THREADING) + set(PTHREAD_INCLUDE_DIR "") + endif() +else() set (PTHREAD_LIBRARIES "") set (PTHREAD_INCLUDE_DIR "") -endif (WITH_THREADING) +endif() option(WITH_DLT "Include DLT support?" OFF) message(STATUS "WITH_DLT = ${WITH_DLT}") -if (WITH_DLT) +if(WITH_DLT) #find_package(DLT REQUIRED) find_package(PkgConfig) pkg_check_modules(DLT "automotive-dlt >= 2.11") add_definitions("-DWITH_DLT") -endif (WITH_DLT) +endif() option(WITH_CJSON "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)?" ON) -if (WITH_CJSON) +if(WITH_CJSON) FIND_PACKAGE(cJSON) - if (CJSON_FOUND) + if(CJSON_FOUND) message(STATUS ${CJSON_FOUND}) - else (CJSON_FOUND) + else() message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") - endif(CJSON_FOUND) + endif() endif() # ======================================== @@ -121,33 +120,33 @@ option(WITH_PLUGINS "Build plugins?" ON) option(DOCUMENTATION "Build documentation?" ON) add_subdirectory(lib) -if (WITH_CLIENTS) +if(WITH_CLIENTS) add_subdirectory(client) -endif (WITH_CLIENTS) +endif() -if (WITH_BROKER) +if(WITH_BROKER) add_subdirectory(src) -endif (WITH_BROKER) +endif() -if (WITH_APPS) +if(WITH_APPS) add_subdirectory(apps) -endif (WITH_APPS) +endif() -if (WITH_PLUGINS) +if(WITH_PLUGINS) add_subdirectory(plugins) -endif (WITH_PLUGINS) +endif() -if (DOCUMENTATION) +if(DOCUMENTATION) add_subdirectory(man) -endif (DOCUMENTATION) +endif() # ======================================== # Install config file # ======================================== -if (WITH_BROKER) +if(WITH_BROKER) install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/mosquitto") -endif (WITH_BROKER) +endif() # ======================================== # Install pkg-config files diff --git a/apps/mosquitto_ctrl/CMakeLists.txt b/apps/mosquitto_ctrl/CMakeLists.txt index d4466fe5..97dbcf15 100644 --- a/apps/mosquitto_ctrl/CMakeLists.txt +++ b/apps/mosquitto_ctrl/CMakeLists.txt @@ -1,11 +1,6 @@ -if (WITH_TLS AND CJSON_FOUND) +if(WITH_TLS AND CJSON_FOUND) add_definitions("-DWITH_CJSON") - include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/src - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH} - ${CJSON_INCLUDE_DIRS} ${mosquitto_SOURCE_DIR}/apps/mosquitto_passwd) - link_directories(${CJSON_DIR}) add_executable(mosquitto_ctrl @@ -20,29 +15,46 @@ if (WITH_TLS AND CJSON_FOUND) ../../src/memory_public.c options.c ../../src/password_mosq.c ../../src/password_mosq.h - ) + ) + + target_include_directories(mosquitto_ctrl PRIVATE + "${CJSON_INCLUDE_DIRS}" + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/apps/mosquitto_passwd" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/src" + ) - if (WITH_STATIC_LIBRARIES) + if(WITH_STATIC_LIBRARIES) target_link_libraries(mosquitto_ctrl libmosquitto_static) else() target_link_libraries(mosquitto_ctrl libmosquitto) endif() - if (UNIX) - if (APPLE) + if(UNIX) + if(APPLE) target_link_libraries(mosquitto_ctrl dl) - elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") # - elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") # elseif(QNX) # - else(APPLE) + else() target_link_libraries(mosquitto_ctrl dl) - endif (APPLE) - endif (UNIX) + endif() + endif() - target_link_libraries(mosquitto_ctrl ${OPENSSL_LIBRARIES} ${CJSON_LIBRARIES}) + target_link_libraries(mosquitto_ctrl + ${OPENSSL_LIBRARIES} + ${CJSON_LIBRARIES} + ) - install(TARGETS mosquitto_ctrl RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") -endif (WITH_TLS AND CJSON_FOUND) + install(TARGETS mosquitto_ctrl + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endif() diff --git a/apps/mosquitto_passwd/CMakeLists.txt b/apps/mosquitto_passwd/CMakeLists.txt index 13a7d826..a8e83c0e 100644 --- a/apps/mosquitto_passwd/CMakeLists.txt +++ b/apps/mosquitto_passwd/CMakeLists.txt @@ -1,8 +1,4 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/src - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH}) - -if (WITH_TLS) +if(WITH_TLS) add_executable(mosquitto_passwd mosquitto_passwd.c get_password.c get_password.h @@ -10,9 +6,23 @@ if (WITH_TLS) ../../src/memory_public.c ../../lib/misc_mosq.c ../../src/password_mosq.c ../../src/password_mosq.h - ) + ) + + target_include_directories(mosquitto_passwd PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/src" + ) + target_link_libraries(mosquitto_passwd + ${OPENSSL_LIBRARIES} + ) - target_link_libraries(mosquitto_passwd ${OPENSSL_LIBRARIES}) - install(TARGETS mosquitto_passwd RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") -endif (WITH_TLS) + install(TARGETS mosquitto_passwd + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endif() diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index e81d59cb..d7be8963 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,35 +1,44 @@ set(shared_src client_shared.c client_shared.h client_props.c) -if (WITH_SRV) +if(WITH_SRV) add_definitions("-DWITH_SRV") -endif (WITH_SRV) +endif() -set( CLIENT_INC ${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH} ${PTHREAD_INCLUDE_DIR} - ${OPENSSL_INCLUDE_DIR}) +set(CLIENT_INC + "${OPENSSL_INCLUDE_DIR}" + "${PTHREAD_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) -set( CLIENT_DIR ${mosquitto_BINARY_DIR}/lib) +set(CLIENT_DIR ${mosquitto_BINARY_DIR}/lib) -if (CJSON_FOUND) +if(CJSON_FOUND) add_definitions("-DWITH_CJSON") - set( CLIENT_DIR "${CLIENT_DIR};${CJSON_DIR}" ) - set( CLIENT_INC "${CLIENT_INC};${CJSON_INCLUDE_DIRS}" ) + set(CLIENT_DIR "${CLIENT_DIR};${CJSON_DIR}") + set(CLIENT_INC "${CLIENT_INC};${CJSON_INCLUDE_DIRS}") endif() -include_directories(${CLIENT_INC}) -link_directories(${CLIENT_DIR}) - 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}) -if (CJSON_FOUND) +target_include_directories(mosquitto_pub PRIVATE ${CLIENT_INC}) +target_include_directories(mosquitto_sub PRIVATE ${CLIENT_INC}) +target_include_directories(mosquitto_rr PRIVATE ${CLIENT_INC}) + +link_directories(${CLIENT_DIR}) + + +if(CJSON_FOUND) target_link_libraries(mosquitto_pub ${CJSON_LIBRARIES}) target_link_libraries(mosquitto_sub ${CJSON_LIBRARIES}) target_link_libraries(mosquitto_rr ${CJSON_LIBRARIES}) endif() -if (WITH_STATIC_LIBRARIES) +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) @@ -39,7 +48,7 @@ else() target_link_libraries(mosquitto_rr libmosquitto) endif() -if (QNX) +if(QNX) target_link_libraries(mosquitto_pub socket) target_link_libraries(mosquitto_sub socket) target_link_libraries(mosquitto_rr socket) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 3fcf817e..aba55726 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,17 +1,7 @@ option(WITH_LIB_CPP "Build C++ library?" ON) -if (WITH_LIB_CPP) +if(WITH_LIB_CPP) add_subdirectory(cpp) -endif (WITH_LIB_CPP) - -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/lib - ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH} - ${OPENSSL_INCLUDE_DIR} ${PTHREAD_INCLUDE_DIR}) -link_directories(${mosquitto_SOURCE_DIR}/lib) - -if (WITH_BUNDLED_DEPS) - include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/deps) -endif (WITH_BUNDLED_DEPS) +endif() set(C_SRC actions.c @@ -62,50 +52,74 @@ set(C_SRC set (LIBRARIES ${OPENSSL_LIBRARIES} ${PTHREAD_LIBRARIES}) -if (UNIX AND NOT APPLE AND NOT ANDROID) +if(UNIX AND NOT APPLE AND NOT ANDROID) find_library(LIBRT rt) - if (LIBRT) + if(LIBRT) set (LIBRARIES ${LIBRARIES} rt) - endif (LIBRT) -endif (UNIX AND NOT APPLE AND NOT ANDROID) + endif() +endif() -if (WIN32) +if(WIN32) set (LIBRARIES ${LIBRARIES} ws2_32) -endif (WIN32) +endif() -if (WITH_SRV) +if(WITH_SRV) # Simple detect c-ares find_path(ARES_HEADER ares.h) - if (ARES_HEADER) + if(ARES_HEADER) add_definitions("-DWITH_SRV") set (LIBRARIES ${LIBRARIES} cares) - else (ARES_HEADER) + else() message(WARNING "c-ares library not found.") - endif (ARES_HEADER) -endif (WITH_SRV) + endif() +endif() -add_library(libmosquitto SHARED ${C_SRC}) -set_target_properties(libmosquitto PROPERTIES - POSITION_INDEPENDENT_CODE 1 +add_library(libmosquitto SHARED + ${C_SRC} ) +target_include_directories(libmosquitto PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${PTHREAD_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/lib" +) + +link_directories("${mosquitto_SOURCE_DIR}/lib") + +if(WITH_BUNDLED_DEPS) + target_include_directories(libmosquitto PRIVATE + "${mosquitto_SOURCE_DIR}/deps" + ) +endif() + + target_link_libraries(libmosquitto ${LIBRARIES}) set_target_properties(libmosquitto PROPERTIES OUTPUT_NAME mosquitto VERSION ${VERSION} SOVERSION 1 + POSITION_INDEPENDENT_CODE 1 ) -install(TARGETS libmosquitto RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") +install(TARGETS libmosquitto + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) -if (WITH_STATIC_LIBRARIES) - add_library(libmosquitto_static STATIC ${C_SRC}) - if (WITH_PIC) +if(WITH_STATIC_LIBRARIES) + add_library(libmosquitto_static STATIC + ${C_SRC} + ) + if(WITH_PIC) set_target_properties(libmosquitto_static PROPERTIES POSITION_INDEPENDENT_CODE 1 ) - endif (WITH_PIC) + endif() target_link_libraries(libmosquitto_static ${LIBRARIES}) @@ -115,8 +129,10 @@ if (WITH_STATIC_LIBRARIES) ) target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC") - install(TARGETS libmosquitto_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif (WITH_STATIC_LIBRARIES) + install(TARGETS libmosquitto_static + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ) +endif() install(FILES ../include/mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(FILES ../include/mqtt_protocol.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 1748b14c..e9382423 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -1,31 +1,43 @@ -include_directories(${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/lib/cpp - ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) -link_directories(${mosquitto_BINARY_DIR}/lib) - set(CPP_SRC mosquittopp.cpp mosquittopp.h) -add_library(mosquittopp SHARED ${CPP_SRC}) +add_library(mosquittopp SHARED + ${CPP_SRC} +) + 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" +) + +link_directories(${mosquitto_BINARY_DIR}/lib) + target_link_libraries(mosquittopp libmosquitto) set_target_properties(mosquittopp PROPERTIES VERSION ${VERSION} SOVERSION 1 ) -install(TARGETS mosquittopp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") +install(TARGETS mosquittopp + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) -if (WITH_STATIC_LIBRARIES) +if(WITH_STATIC_LIBRARIES) add_library(mosquittopp_static STATIC ${C_SRC} ${CPP_SRC} ) - if (WITH_PIC) + if(WITH_PIC) set_target_properties(mosquittopp_static PROPERTIES POSITION_INDEPENDENT_CODE 1 ) - endif (WITH_PIC) + endif() target_link_libraries(mosquittopp_static ${LIBRARIES}) @@ -35,7 +47,9 @@ if (WITH_STATIC_LIBRARIES) ) target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC") - install(TARGETS mosquittopp_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif (WITH_STATIC_LIBRARIES) + install(TARGETS mosquittopp_static + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ) +endif() install(FILES mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt index 2c8b0955..e6d6545f 100644 --- a/man/CMakeLists.txt +++ b/man/CMakeLists.txt @@ -8,23 +8,23 @@ if(NOT WIN32) find_program(XSLTPROC xsltproc OPTIONAL) if(XSLTPROC) function(compile_manpage page) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/man/${page} - COMMAND xsltproc ${CMAKE_SOURCE_DIR}/man/${page}.xml -o ${CMAKE_SOURCE_DIR}/man/ - MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/man/${page}.xml) - add_custom_target(${page} ALL DEPENDS ${CMAKE_SOURCE_DIR}/man/${page}) + add_custom_command(OUTPUT "${CMAKE_SOURCE_DIR}/man/${page}" + COMMAND xsltproc "${CMAKE_SOURCE_DIR}/man/${page}.xml" -o "${CMAKE_SOURCE_DIR}/man/" + MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/man/${page}.xml") + add_custom_target(${page} ALL DEPENDS "${CMAKE_SOURCE_DIR}/man/${page}") endfunction() + compile_manpage("libmosquitto.3") + compile_manpage("mosquitto-tls.7") + compile_manpage("mosquitto.8") + compile_manpage("mosquitto.conf.5") compile_manpage("mosquitto_ctrl.1") compile_manpage("mosquitto_ctrl_dynsec.1") compile_manpage("mosquitto_passwd.1") compile_manpage("mosquitto_pub.1") - compile_manpage("mosquitto_sub.1") compile_manpage("mosquitto_rr.1") - compile_manpage("libmosquitto.3") - compile_manpage("mosquitto.conf.5") - compile_manpage("mosquitto-tls.7") + compile_manpage("mosquitto_sub.1") compile_manpage("mqtt.7") - compile_manpage("mosquitto.8") else() message(FATAL_ERROR "xsltproc not found: manpages cannot be built") endif() @@ -36,12 +36,12 @@ install(FILES mosquitto_ctrl_dynsec.1 mosquitto_passwd.1 mosquitto_pub.1 - mosquitto_sub.1 mosquitto_rr.1 - DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 + mosquitto_sub.1 + DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" OPTIONAL) -install(FILES libmosquitto.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 OPTIONAL) -install(FILES mosquitto.conf.5 DESTINATION ${CMAKE_INSTALL_MANDIR}/man5 OPTIONAL) -install(FILES mosquitto-tls.7 mqtt.7 DESTINATION ${CMAKE_INSTALL_MANDIR}/man7 OPTIONAL) -install(FILES mosquitto.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8 OPTIONAL) +install(FILES libmosquitto.3 DESTINATION "${CMAKE_INSTALL_MANDIR}/man3" OPTIONAL) +install(FILES mosquitto.conf.5 DESTINATION "${CMAKE_INSTALL_MANDIR}/man5" OPTIONAL) +install(FILES mosquitto-tls.7 mqtt.7 DESTINATION "${CMAKE_INSTALL_MANDIR}/man7" OPTIONAL) +install(FILES mosquitto.8 DESTINATION "${CMAKE_INSTALL_MANDIR}/man8" OPTIONAL) diff --git a/plugins/dynamic-security/CMakeLists.txt b/plugins/dynamic-security/CMakeLists.txt index 213ea03d..135c0e9b 100644 --- a/plugins/dynamic-security/CMakeLists.txt +++ b/plugins/dynamic-security/CMakeLists.txt @@ -1,16 +1,19 @@ -if (CJSON_FOUND AND WITH_TLS) +if(CJSON_FOUND AND WITH_TLS) add_definitions("-DWITH_CJSON") - set( CLIENT_INC ${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH} ${PTHREAD_INCLUDE_DIR} - ${OPENSSL_INCLUDE_DIR} ${mosquitto_SOURCE_DIR}/deps - ${mosquitto_SOURCE_DIR}/src - ${CJSON_INCLUDE_DIRS} ) - - set( CLIENT_DIR ${mosquitto_BINARY_DIR}/lib ${CJSON_DIR}) + set(CLIENT_INC + "${CJSON_INCLUDE_DIRS}" + "${OPENSSL_INCLUDE_DIR}" + "${PTHREAD_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/deps" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/src" + ) - include_directories(${CLIENT_INC}) - link_directories(${CLIENT_DIR} ${mosquitto_SOURCE_DIR}) + set(CLIENT_DIR "${mosquitto_BINARY_DIR}/lib" "${CJSON_DIR}") add_library(mosquitto_dynamic_security SHARED acl.c @@ -25,17 +28,26 @@ if (CJSON_FOUND AND WITH_TLS) plugin.c roles.c rolelist.c - sub_matches_sub.c) + sub_matches_sub.c + ) + + target_include_directories(mosquitto_dynamic_security PRIVATE + ${CLIENT_INC} + ) + link_directories(${CLIENT_DIR} "${mosquitto_SOURCE_DIR}") set_target_properties(mosquitto_dynamic_security PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) - set_target_properties(mosquitto_dynamic_security PROPERTIES PREFIX "") target_link_libraries(mosquitto_dynamic_security ${CJSON_LIBRARIES}) if(WIN32) target_link_libraries(mosquitto_dynamic_security mosquitto) - endif(WIN32) + endif() - install(TARGETS mosquitto_dynamic_security RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install(TARGETS mosquitto_dynamic_security + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ) endif() diff --git a/plugins/examples/CMakeLists.txt b/plugins/examples/CMakeLists.txt index 67f41d84..ff51dfba 100644 --- a/plugins/examples/CMakeLists.txt +++ b/plugins/examples/CMakeLists.txt @@ -1,7 +1,7 @@ if(NOT WIN32) add_subdirectory(add-properties) add_subdirectory(message-timestamp) -endif(NOT WIN32) +endif() add_subdirectory(auth-by-ip) add_subdirectory(client-properties) add_subdirectory(connection-state) diff --git a/plugins/examples/add-properties/CMakeLists.txt b/plugins/examples/add-properties/CMakeLists.txt index 6e036442..a0e619f3 100644 --- a/plugins/examples/add-properties/CMakeLists.txt +++ b/plugins/examples/add-properties/CMakeLists.txt @@ -1,11 +1,18 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_add_properties SHARED + mosquitto_add_properties.c +) + +target_include_directories(mosquitto_add_properties PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) -add_library(mosquitto_add_properties SHARED mosquitto_add_properties.c) set_target_properties(mosquitto_add_properties PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_add_properties PROPERTIES PREFIX "") # Don't install, these are example plugins only. #install(TARGETS mosquitto_add_properties 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 45260bd5..06addd6b 100644 --- a/plugins/examples/auth-by-ip/CMakeLists.txt +++ b/plugins/examples/auth-by-ip/CMakeLists.txt @@ -1,11 +1,18 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_auth_by_ip SHARED + mosquitto_auth_by_ip.c +) + +target_include_directories(mosquitto_auth_by_ip PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH} ${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) -add_library(mosquitto_auth_by_ip SHARED mosquitto_auth_by_ip.c) set_target_properties(mosquitto_auth_by_ip PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_auth_by_ip PROPERTIES PREFIX "") # Don't install, these are example plugins only. #install(TARGETS mosquitto_auth_by_ip 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 3ba8a208..e2c14586 100644 --- a/plugins/examples/client-properties/CMakeLists.txt +++ b/plugins/examples/client-properties/CMakeLists.txt @@ -1,15 +1,24 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_client_properties SHARED + mosquitto_client_properties.c +) + +target_include_directories(mosquitto_client_properties PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) + link_directories(${mosquitto_SOURCE_DIR}) -add_library(mosquitto_client_properties SHARED mosquitto_client_properties.c) set_target_properties(mosquitto_client_properties PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_client_properties PROPERTIES PREFIX "") + if(WIN32) target_link_libraries(mosquitto_client_properties mosquitto) -endif(WIN32) +endif() # Don't install, these are example plugins only. #install(TARGETS mosquitto_client_properties 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 32b7fb7f..6fbf7b10 100644 --- a/plugins/examples/connection-state/CMakeLists.txt +++ b/plugins/examples/connection-state/CMakeLists.txt @@ -1,11 +1,18 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_connection_state SHARED + mosquitto_connection_state.c +) + +target_include_directories(mosquitto_connection_state PRIVATE + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) -add_library(mosquitto_connection_state SHARED mosquitto_connection_state.c) set_target_properties(mosquitto_connection_state PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_connection_state PROPERTIES PREFIX "") # Don't install, these are example plugins only. #install(TARGETS mosquitto_connection_state 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 e53a4bc0..1b9dd7c1 100644 --- a/plugins/examples/message-timestamp/CMakeLists.txt +++ b/plugins/examples/message-timestamp/CMakeLists.txt @@ -1,11 +1,19 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_message_timestamp SHARED + mosquitto_message_timestamp.c +) + +target_include_directories(mosquitto_message_timestamp PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) -add_library(mosquitto_message_timestamp SHARED mosquitto_message_timestamp.c) set_target_properties(mosquitto_message_timestamp PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_message_timestamp PROPERTIES PREFIX "") # Don't install, these are example plugins only. #install(TARGETS mosquitto_message_timestamp 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 a4492911..932f0fdb 100644 --- a/plugins/examples/payload-modification/CMakeLists.txt +++ b/plugins/examples/payload-modification/CMakeLists.txt @@ -1,15 +1,24 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH}) +add_library(mosquitto_payload_modification SHARED + mosquitto_payload_modification.c +) + +target_include_directories(mosquitto_payload_modification PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" +) + link_directories(${mosquitto_SOURCE_DIR}) -add_library(mosquitto_payload_modification SHARED mosquitto_payload_modification.c) set_target_properties(mosquitto_payload_modification PROPERTIES + PREFIX "" POSITION_INDEPENDENT_CODE 1 ) -set_target_properties(mosquitto_payload_modification PROPERTIES PREFIX "") if(WIN32) target_link_libraries(mosquitto_payload_modification mosquitto) -endif(WIN32) +endif() # Don't install, these are example plugins only. #install(TARGETS mosquitto_payload_modification RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cbb2f631..7ac3d990 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,3 @@ -include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/src - ${mosquitto_SOURCE_DIR}/include ${mosquitto_SOURCE_DIR}/lib - ${OPENSSL_INCLUDE_DIR} ${STDBOOL_H_PATH} ${STDINT_H_PATH}) - set (MOSQ_SRCS ../lib/alias_mosq.c ../lib/alias_mosq.h bridge.c bridge_topic.c @@ -71,110 +67,100 @@ set (MOSQ_SRCS ../lib/utf8_mosq.c websockets.c will_delay.c - ../lib/will_mosq.c ../lib/will_mosq.h) + ../lib/will_mosq.c ../lib/will_mosq.h +) CHECK_INCLUDE_FILES(sys/event.h HAVE_SYS_EVENT_H) -if (HAVE_SYS_EVENT_H) +if(HAVE_SYS_EVENT_H) add_definitions("-DWITH_KQUEUE") -endif (HAVE_SYS_EVENT_H) - -if (WITH_BUNDLED_DEPS) - include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/deps) -endif (WITH_BUNDLED_DEPS) +endif() find_path(HAVE_SYS_EPOLL_H sys/epoll.h) -if (HAVE_SYS_EPOLL_H) +if(HAVE_SYS_EPOLL_H) add_definitions("-DWITH_EPOLL") endif() option(INC_BRIDGE_SUPPORT "Include bridge support for connecting to other brokers?" ON) -if (INC_BRIDGE_SUPPORT) +if(INC_BRIDGE_SUPPORT) set (MOSQ_SRCS ${MOSQ_SRCS} bridge.c) add_definitions("-DWITH_BRIDGE") -endif (INC_BRIDGE_SUPPORT) +endif() -option(USE_LIBWRAP - "Include tcp-wrappers support?" OFF) +option(USE_LIBWRAP "Include tcp-wrappers support?" OFF) -if (USE_LIBWRAP) +if(USE_LIBWRAP) set (MOSQ_LIBS ${MOSQ_LIBS} wrap) add_definitions("-DWITH_WRAP") -endif (USE_LIBWRAP) +endif() -option(INC_DB_UPGRADE - "Include database upgrade support? (recommended)" ON) +option(INC_DB_UPGRADE "Include database upgrade support? (recommended)" ON) -option(INC_MEMTRACK - "Include memory tracking support?" ON) -if (INC_MEMTRACK) +option(INC_MEMTRACK "Include memory tracking support?" ON) +if(INC_MEMTRACK) add_definitions("-DWITH_MEMORY_TRACKING") -endif (INC_MEMTRACK) +endif() -option(WITH_PERSISTENCE - "Include persistence support?" ON) -if (WITH_PERSISTENCE) +option(WITH_PERSISTENCE "Include persistence support?" ON) +if(WITH_PERSISTENCE) add_definitions("-DWITH_PERSISTENCE") -endif (WITH_PERSISTENCE) +endif() -option(WITH_SYS_TREE - "Include $SYS tree support?" ON) -if (WITH_SYS_TREE) +option(WITH_SYS_TREE "Include $SYS tree support?" ON) +if(WITH_SYS_TREE) add_definitions("-DWITH_SYS_TREE") -endif (WITH_SYS_TREE) +endif() -option(WITH_ADNS - "Include ADNS support?" OFF) +option(WITH_ADNS "Include ADNS support?" OFF) -if (CMAKE_SYSTEM_NAME STREQUAL Linux) - option(WITH_SYSTEMD - "Include systemd support?" OFF) - if (WITH_SYSTEMD) +if(CMAKE_SYSTEM_NAME STREQUAL Linux) + option(WITH_SYSTEMD "Include systemd support?" OFF) + if(WITH_SYSTEMD) add_definitions("-DWITH_SYSTEMD") find_library(SYSTEMD_LIBRARY systemd) set (MOSQ_LIBS ${MOSQ_LIBS} ${SYSTEMD_LIBRARY}) - endif (WITH_SYSTEMD) -endif (CMAKE_SYSTEM_NAME STREQUAL Linux) + endif() +endif() option(WITH_WEBSOCKETS "Include websockets support?" OFF) option(STATIC_WEBSOCKETS "Use the static libwebsockets library?" OFF) -if (WITH_WEBSOCKETS) +if(WITH_WEBSOCKETS) find_package(libwebsockets) add_definitions("-DWITH_WEBSOCKETS") -endif (WITH_WEBSOCKETS) +endif() option(WITH_CONTROL "Include $CONTROL topic support?" ON) -if (WITH_CONTROL) +if(WITH_CONTROL) add_definitions("-DWITH_CONTROL") -endif (WITH_CONTROL) +endif() -if (WIN32 OR CYGWIN) +if(WIN32 OR CYGWIN) set (MOSQ_SRCS ${MOSQ_SRCS} service.c) -endif (WIN32 OR CYGWIN) +endif() add_definitions (-DWITH_BROKER) -if (WITH_DLT) +if(WITH_DLT) message(STATUS "DLT_LIBDIR = ${DLT_LIBDIR}") link_directories(${DLT_LIBDIR}) set (MOSQ_LIBS ${MOSQ_LIBS} ${DLT_LIBRARIES}) -endif (WITH_DLT) +endif() set (MOSQ_LIBS ${MOSQ_LIBS} ${OPENSSL_LIBRARIES}) # Check for getaddrinfo_a include(CheckLibraryExists) check_library_exists(anl getaddrinfo_a "" HAVE_GETADDRINFO_A) -if (HAVE_GETADDRINFO_A AND WITH_ADNS) +if(HAVE_GETADDRINFO_A AND WITH_ADNS) add_definitions("-DWITH_ADNS") add_definitions(-DHAVE_GETADDRINFO_A) set (MOSQ_LIBS ${MOSQ_LIBS} anl) -endif (HAVE_GETADDRINFO_A AND WITH_ADNS) +endif() -if (UNIX) - if (APPLE) +if(UNIX) + if(APPLE) set (MOSQ_LIBS ${MOSQ_LIBS} dl m) elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") set (MOSQ_LIBS ${MOSQ_LIBS} m) @@ -182,44 +168,71 @@ if (UNIX) set (MOSQ_LIBS ${MOSQ_LIBS} m) elseif(QNX) set(MOSQ_LIBS ${MOSQ_LIBS} m socket) - else(APPLE) + else() set (MOSQ_LIBS ${MOSQ_LIBS} dl m) find_library(LIBRT rt) - if (LIBRT) + if(LIBRT) set (MOSQ_LIBS ${MOSQ_LIBS} rt) - endif (LIBRT) - endif (APPLE) -endif (UNIX) + endif() + endif() +endif() -if (WIN32) +if(WIN32) set (MOSQ_LIBS ${MOSQ_LIBS} ws2_32) -endif (WIN32) +endif() -if (WITH_WEBSOCKETS) - if (STATIC_WEBSOCKETS) +if(WITH_WEBSOCKETS) + if(STATIC_WEBSOCKETS) set (MOSQ_LIBS ${MOSQ_LIBS} websockets_static) - if (WIN32) + if(WIN32) set (MOSQ_LIBS ${MOSQ_LIBS} iphlpapi) link_directories(${mosquitto_SOURCE_DIR}) - endif (WIN32) - else (STATIC_WEBSOCKETS) + endif(IN32) + else(STATIC_WEBSOCKETS) set (MOSQ_LIBS ${MOSQ_LIBS} websockets) - endif (STATIC_WEBSOCKETS) -endif (WITH_WEBSOCKETS) + endif() +endif() add_executable(mosquitto ${MOSQ_SRCS}) -target_link_libraries(mosquitto ${MOSQ_LIBS}) -if (WIN32) - set_target_properties(mosquitto PROPERTIES ENABLE_EXPORTS 1) -endif (WIN32) - -if (UNIX) - if (APPLE) - set_target_properties(mosquitto PROPERTIES LINK_FLAGS "-Wl,-exported_symbols_list -Wl,${mosquitto_SOURCE_DIR}/src/linker-macosx.syms") - else (APPLE) - set_target_properties(mosquitto PROPERTIES LINK_FLAGS "-Wl,-dynamic-list=${mosquitto_SOURCE_DIR}/src/linker.syms") - endif (APPLE) -endif (UNIX) - -install(TARGETS mosquitto RUNTIME DESTINATION "${CMAKE_INSTALL_SBINDIR}") + +target_include_directories(mosquitto PRIVATE + "${OPENSSL_INCLUDE_DIR}" + "${STDBOOL_H_PATH}" + "${STDINT_H_PATH}" + "${mosquitto_SOURCE_DIR}" + "${mosquitto_SOURCE_DIR}/include" + "${mosquitto_SOURCE_DIR}/lib" + "${mosquitto_SOURCE_DIR}/src" +) +if(WITH_BUNDLED_DEPS) + target_include_directories(mosquitto PRIVATE + "${mosquitto_SOURCE_DIR}/deps" + ) +endif() + +target_link_libraries(mosquitto + ${MOSQ_LIBS} +) + +if(WIN32) + set_target_properties(mosquitto PROPERTIES + ENABLE_EXPORTS 1 + ) +endif() + +if(UNIX) + if(APPLE) + set_target_properties(mosquitto PROPERTIES + LINK_FLAGS "-Wl,-exported_symbols_list -Wl,${mosquitto_SOURCE_DIR}/src/linker-macosx.syms" + ) + else() + set_target_properties(mosquitto PROPERTIES + LINK_FLAGS "-Wl,-dynamic-list=${mosquitto_SOURCE_DIR}/src/linker.syms" + ) + endif() +endif() + +install(TARGETS mosquitto + RUNTIME DESTINATION "${CMAKE_INSTALL_SBINDIR}" +) install(FILES ../include/mosquitto_broker.h ../include/mosquitto_plugin.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")