Introduce a common-options cmake target

this makes it possible to explicitly share compile options, without
using the `add_definition` function. This function declares options for
the current directory and below (in our case also for `deps`).

Adding -Wall, -Wconversion and -Wextra to at least make compiler
warnings visible for the cmake build.

Signed-off-by: Kai Buschulte <kai.buschulte@cedalo.com>
pull/2586/head
Kai Buschulte 3 years ago
parent a3d94359f9
commit 71456077ad

@ -26,6 +26,9 @@ if(APPLE)
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup") set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
endif() endif()
add_library(common-options INTERFACE)
target_compile_options(common-options INTERFACE -Wall -Wextra -Wconversion)
include(GNUInstallDirs) include(GNUInstallDirs)
include(CheckIncludeFiles) include(CheckIncludeFiles)
@ -88,7 +91,6 @@ option(WITH_CJSON "Build with cJSON support (required for dynamic security plugi
if(WITH_CJSON) if(WITH_CJSON)
FIND_PACKAGE(cJSON) FIND_PACKAGE(cJSON)
if(CJSON_FOUND) if(CJSON_FOUND)
message(STATUS ${CJSON_FOUND})
target_compile_definitions(cJSON INTERFACE WITH_CJSON) target_compile_definitions(cJSON INTERFACE WITH_CJSON)
else() else()
message(STATUS "Optional dependency cJSON not found. Some features will be disabled.") message(STATUS "Optional dependency cJSON not found. Some features will be disabled.")

@ -56,6 +56,7 @@ if(WITH_TLS AND CJSON_FOUND)
target_link_libraries(mosquitto_ctrl target_link_libraries(mosquitto_ctrl
PRIVATE PRIVATE
common-options
OpenSSL::SSL OpenSSL::SSL
cJSON cJSON
) )

@ -714,7 +714,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
/* Convert %25 -> %, %3a, %3A -> :, %40 -> @ */ /* Convert %25 -> %, %3a, %3A -> :, %40 -> @ */
static int mosquitto__urldecode(char *str) static int mosquitto__urldecode(char *str)
{ {
int i, j; size_t i, j;
size_t len; size_t len;
if(!str) return 0; if(!str) return 0;

@ -21,6 +21,7 @@ if(WITH_TLS)
target_link_libraries(mosquitto_passwd target_link_libraries(mosquitto_passwd
PRIVATE PRIVATE
common-options
OpenSSL::SSL OpenSSL::SSL
) )

@ -1,9 +1,5 @@
set(shared_src client_shared.c client_shared.h client_props.c) set(shared_src client_shared.c client_shared.h client_props.c)
if(WITH_SRV)
add_definitions("-DWITH_SRV")
endif()
set(CLIENT_INC set(CLIENT_INC
"${OPENSSL_INCLUDE_DIR}" "${OPENSSL_INCLUDE_DIR}"
"${STDBOOL_H_PATH}" "${STDBOOL_H_PATH}"
@ -12,25 +8,29 @@ set(CLIENT_INC
"${mosquitto_SOURCE_DIR}/include" "${mosquitto_SOURCE_DIR}/include"
) )
add_library(client-common INTERFACE)
target_link_libraries(client-common INTERFACE common-options)
target_include_directories(client-common INTERFACE ${CLIENT_INC})
target_sources(client-common INTERFACE ${shared_src})
if(WITH_SRV)
target_compile_definitions(client-common INTERFACE "-DWITH_SRV")
endif()
if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN) if(WITH_WEBSOCKETS AND WITH_WEBSOCKETS_BUILTIN)
add_definitions("-DWITH_WEBSOCKETS=WS_IS_BUILTIN") target_compile_definitions(client-common INTERFACE "-DWITH_WEBSOCKETS=WS_IS_BUILTIN")
endif() endif()
add_executable(mosquitto_pub pub_client.c pub_shared.c ${shared_src}) add_executable(mosquitto_pub pub_client.c pub_shared.c)
add_executable(mosquitto_sub sub_client.c sub_client_output.c ${shared_src}) add_executable(mosquitto_sub sub_client.c sub_client_output.c)
add_executable(mosquitto_rr rr_client.c pub_shared.c sub_client_output.c ${shared_src}) add_executable(mosquitto_rr rr_client.c pub_shared.c sub_client_output.c)
target_include_directories(mosquitto_pub PRIVATE ${CLIENT_INC})
target_include_directories(mosquitto_sub PRIVATE ${CLIENT_INC})
target_include_directories(mosquitto_rr PRIVATE ${CLIENT_INC})
if (WITH_THREADING AND NOT WIN32) if (WITH_THREADING AND NOT WIN32)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
target_link_libraries(mosquitto_pub PRIVATE Threads::Threads) target_link_libraries(client-common INTERFACE Threads::Threads)
target_link_libraries(mosquitto_sub PRIVATE Threads::Threads)
target_link_libraries(mosquitto_rr PRIVATE Threads::Threads)
endif() endif()
if(WITH_BUNDLED_DEPS) if(WITH_BUNDLED_DEPS)
@ -39,27 +39,23 @@ if(WITH_BUNDLED_DEPS)
endif() endif()
if(CJSON_FOUND) if(CJSON_FOUND)
target_link_libraries(mosquitto_pub PRIVATE cJSON) target_link_libraries(client-common INTERFACE cJSON)
target_link_libraries(mosquitto_sub PRIVATE cJSON)
target_link_libraries(mosquitto_rr PRIVATE cJSON)
endif() endif()
if(WITH_STATIC_LIBRARIES) if(WITH_STATIC_LIBRARIES)
target_link_libraries(mosquitto_pub PRIVATE libmosquitto_static) target_link_libraries(client-common INTERFACE libmosquitto_static)
target_link_libraries(mosquitto_sub PRIVATE libmosquitto_static)
target_link_libraries(mosquitto_rr PRIVATE libmosquitto_static)
else() else()
target_link_libraries(mosquitto_pub PRIVATE libmosquitto) target_link_libraries(client-common INTERFACE libmosquitto)
target_link_libraries(mosquitto_sub PRIVATE libmosquitto)
target_link_libraries(mosquitto_rr PRIVATE libmosquitto)
endif() endif()
if(QNX) if(QNX)
target_link_libraries(mosquitto_pub PRIVATE socket) target_link_libraries(client-common INTERFACE socket)
target_link_libraries(mosquitto_sub PRIVATE socket)
target_link_libraries(mosquitto_rr PRIVATE socket)
endif() endif()
target_link_libraries(mosquitto_pub PRIVATE client-common)
target_link_libraries(mosquitto_sub PRIVATE client-common)
target_link_libraries(mosquitto_rr PRIVATE client-common)
install(TARGETS mosquitto_pub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(TARGETS mosquitto_pub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS mosquitto_sub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(TARGETS mosquitto_sub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS mosquitto_rr RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(TARGETS mosquitto_rr RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

@ -58,8 +58,10 @@ if (WITH_THREADING AND WIN32)
list(APPEND C_SRC "../common/winthread_mosq.c" "../common/winthread_mosq.h") list(APPEND C_SRC "../common/winthread_mosq.c" "../common/winthread_mosq.h")
endif() endif()
set(LIBRARIES common-options)
if(WITH_TLS) if(WITH_TLS)
set (LIBRARIES OpenSSL::SSL) set (LIBRARIES ${LIBRARIES} OpenSSL::SSL)
endif() endif()
if(UNIX AND NOT APPLE AND NOT ANDROID) if(UNIX AND NOT APPLE AND NOT ANDROID)

@ -18,7 +18,7 @@ target_include_directories(mosquittopp
"${mosquitto_SOURCE_DIR}/lib/cpp" "${mosquitto_SOURCE_DIR}/lib/cpp"
) )
target_link_libraries(mosquittopp PRIVATE libmosquitto) target_link_libraries(mosquittopp PRIVATE libmosquitto common-options)
if (WITH_THREADING AND NOT WIN32) if (WITH_THREADING AND NOT WIN32)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)

@ -55,6 +55,7 @@ if(CJSON_FOUND AND WITH_TLS)
target_link_libraries(mosquitto_dynamic_security target_link_libraries(mosquitto_dynamic_security
PRIVATE PRIVATE
common-options
cJSON cJSON
OpenSSL::SSL OpenSSL::SSL
) )

@ -30,6 +30,7 @@ if(SQLITE3_FOUND AND CJSON_FOUND)
target_link_libraries(mosquitto_persist_sqlite target_link_libraries(mosquitto_persist_sqlite
PRIVATE PRIVATE
common-options
SQLite::SQLite3 SQLite::SQLite3
cJSON cJSON
) )

@ -244,6 +244,7 @@ target_link_libraries(mosquitto
PUBLIC PUBLIC
config-header config-header
PRIVATE PRIVATE
common-options
${MOSQ_LIBS} ${MOSQ_LIBS}
) )

@ -107,6 +107,8 @@ int mux__handle(struct mosquitto__listener_sock *listensock, int listensock_coun
UNUSED(listensock_count); UNUSED(listensock_count);
return mux_epoll__handle(); return mux_epoll__handle();
#elif defined(WITH_KQUEUE) #elif defined(WITH_KQUEUE)
UNUSED(listensock);
UNUSED(listensock_count);
return mux_kqueue__handle(); return mux_kqueue__handle();
#else #else
return mux_poll__handle(listensock, listensock_count); return mux_poll__handle(listensock, listensock_count);

@ -43,5 +43,5 @@ foreach(BINARY ${BINARIES})
set_property(TARGET ${BINARY} set_property(TARGET ${BINARY}
PROPERTY SUFFIX .test PROPERTY SUFFIX .test
) )
target_link_libraries(${BINARY} PRIVATE libmosquitto) target_link_libraries(${BINARY} PRIVATE common-options libmosquitto)
endforeach() endforeach()

@ -61,5 +61,5 @@ foreach(BINARY ${BINARIES})
target_compile_definitions(${BINARY} PRIVATE TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") target_compile_definitions(${BINARY} PRIVATE TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(${BINARY} PRIVATE ${CMAKE_SOURCE_DIR}/test) target_include_directories(${BINARY} PRIVATE ${CMAKE_SOURCE_DIR}/test)
set_property(TARGET ${BINARY} PROPERTY SUFFIX .test) set_property(TARGET ${BINARY} PROPERTY SUFFIX .test)
target_link_libraries(${BINARY} PRIVATE libmosquitto) target_link_libraries(${BINARY} PRIVATE common-options libmosquitto)
endforeach() endforeach()

@ -10,7 +10,12 @@ target_include_directories(common-unit-test-header
"${mosquitto_SOURCE_DIR}/src" "${mosquitto_SOURCE_DIR}/src"
"${mosquitto_SOURCE_DIR}/test" "${mosquitto_SOURCE_DIR}/test"
) )
target_link_libraries(common-unit-test-header INTERFACE config-header CUnit::CUnit) target_link_libraries(common-unit-test-header
INTERFACE
common-options
config-header
CUnit::CUnit
)
# unit-broker # unit-broker
add_executable(broker-test add_executable(broker-test

Loading…
Cancel
Save