2024-08-10 12:58:21 -05:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
|
|
|
|
|
|
|
project( qmqtt VERSION 1.0.3 )
|
|
|
|
|
|
|
|
include( GNUInstallDirs ) # needed to define vars used in install() directives.
|
|
|
|
|
|
|
|
|
|
|
|
# ===================================================================
|
|
|
|
# Configurable options
|
|
|
|
|
|
|
|
option( ${PROJECT_NAME}_SHARED "Build a shared library. Turn off for static." OFF )
|
|
|
|
option( ${PROJECT_NAME}_WEBSOCKETS "Enable WebSockets for MQTT" OFF )
|
|
|
|
option( ${PROJECT_NAME}_SSL "Enable SSL support for MQTT" ON )
|
|
|
|
|
|
|
|
if ( ${PROJECT_NAME}_SHARED )
|
2024-08-29 13:51:17 -05:00
|
|
|
set(library_build_type SHARED )
|
|
|
|
set(library_install_component Library )
|
2024-08-10 12:58:21 -05:00
|
|
|
else()
|
2024-08-29 13:51:17 -05:00
|
|
|
set(library_build_type STATIC )
|
|
|
|
set(library_install_component Devel )
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2024-08-29 13:51:17 -05:00
|
|
|
set(ws_component )
|
|
|
|
set(ws_libname )
|
|
|
|
set(qt5_min_version "5.3.0" )
|
|
|
|
set(qt6_min_version "6.2.4" )
|
2024-08-10 12:58:21 -05:00
|
|
|
|
|
|
|
if ( ${PROJECT_NAME}_WEBSOCKETS )
|
2024-08-29 13:51:17 -05:00
|
|
|
set(ws_component WebSockets )
|
|
|
|
set(qt5_min_version "5.7.0" )
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if ( NOT ${PROJECT_NAME}_SSL)
|
2024-08-29 13:51:17 -05:00
|
|
|
set(ssl_defs QT_NO_SSL )
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(Qt6 ${qt6_min_version} COMPONENTS Core Network ${ws_component} CONFIG)
|
|
|
|
if(NOT Qt6_FOUND)
|
2024-08-29 13:51:17 -05:00
|
|
|
find_package(Qt5 ${qt5_min_version} COMPONENTS Core Network ${ws_component} REQUIRED)
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${PROJECT_NAME}_WEBSOCKETS)
|
2024-08-29 13:51:17 -05:00
|
|
|
set(ws_libname "Qt${QT_VERSION_MAJOR}::WebSockets" )
|
|
|
|
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebSockets REQUIRED)
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
2024-08-29 13:51:17 -05:00
|
|
|
set(CMAKE_AUTOMOC ON )
|
2024-08-10 12:58:21 -05:00
|
|
|
cmake_policy( SET CMP0020 NEW ) # Automatically link Qt executables to qtmain target on Windows.
|
|
|
|
|
|
|
|
|
|
|
|
# ===================================================================
|
|
|
|
# Project files
|
|
|
|
|
2024-08-29 13:51:17 -05:00
|
|
|
set(PUBLIC_HEADERS
|
|
|
|
src/mqtt/qmqtt_global.h
|
|
|
|
src/mqtt/qmqtt.h
|
|
|
|
src/mqtt/qmqtt_client.h
|
|
|
|
src/mqtt/qmqtt_frame.h
|
|
|
|
src/mqtt/qmqtt_message.h
|
|
|
|
src/mqtt/qmqtt_routesubscription.h
|
|
|
|
src/mqtt/qmqtt_routedmessage.h
|
|
|
|
src/mqtt/qmqtt_router.h
|
|
|
|
src/mqtt/qmqtt_networkinterface.h
|
|
|
|
src/mqtt/qmqtt_socketinterface.h
|
|
|
|
src/mqtt/qmqtt_timerinterface.h
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
2024-08-29 13:51:17 -05:00
|
|
|
set(PRIVATE_HEADERS
|
|
|
|
src/mqtt/qmqtt_client_p.h
|
|
|
|
src/mqtt/qmqtt_message_p.h
|
|
|
|
src/mqtt/qmqtt_network_p.h
|
|
|
|
src/mqtt/qmqtt_socket_p.h
|
|
|
|
src/mqtt/qmqtt_timer_p.h
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
2024-08-29 13:51:17 -05:00
|
|
|
set(SOURCES
|
|
|
|
src/mqtt/qmqtt_client_p.cpp
|
|
|
|
src/mqtt/qmqtt_client.cpp
|
|
|
|
src/mqtt/qmqtt_frame.cpp
|
|
|
|
src/mqtt/qmqtt_message.cpp
|
|
|
|
src/mqtt/qmqtt_network.cpp
|
|
|
|
src/mqtt/qmqtt_routesubscription.cpp
|
|
|
|
src/mqtt/qmqtt_router.cpp
|
|
|
|
src/mqtt/qmqtt_socket.cpp
|
|
|
|
src/mqtt/qmqtt_timer.cpp
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
if ( ${PROJECT_NAME}_WEBSOCKETS )
|
2024-08-29 13:51:17 -05:00
|
|
|
list( APPEND PRIVATE_HEADERS
|
|
|
|
src/mqtt/qmqtt_websocket_p.h
|
|
|
|
src/mqtt/qmqtt_websocketiodevice_p.h
|
|
|
|
)
|
|
|
|
list( APPEND SOURCES
|
|
|
|
src/mqtt/qmqtt_websocket.cpp
|
|
|
|
src/mqtt/qmqtt_websocketiodevice.cpp
|
|
|
|
)
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if ( ${PROJECT_NAME}_SSL)
|
2024-08-29 13:51:17 -05:00
|
|
|
list( APPEND PRIVATE_HEADERS
|
|
|
|
src/mqtt/qmqtt_ssl_socket_p.h
|
|
|
|
)
|
|
|
|
list( APPEND SOURCES
|
|
|
|
src/mqtt/qmqtt_ssl_socket.cpp
|
|
|
|
)
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# Mark public headers as such
|
|
|
|
set_source_files_properties( ${PUBLIC_HEADERS} PROPERTIES PUBLIC_HEADER 1 )
|
|
|
|
|
|
|
|
|
|
|
|
# ===================================================================
|
|
|
|
# Library target
|
|
|
|
|
|
|
|
# Library has the same name as the project
|
|
|
|
add_library( ${PROJECT_NAME} ${library_build_type} ${SOURCES} ${PUBLIC_HEADERS} ${PRIVATE_HEADERS} )
|
|
|
|
target_link_libraries( ${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${ws_libname} )
|
|
|
|
target_compile_definitions( ${PROJECT_NAME}
|
2024-08-29 13:51:17 -05:00
|
|
|
PRIVATE
|
|
|
|
QT_NO_CAST_FROM_ASCII
|
|
|
|
QT_NO_CAST_TO_ASCII
|
|
|
|
QT_STATIC
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# Where to look for headers while compiling the target or when compiling against
|
|
|
|
# the target.
|
|
|
|
target_include_directories( ${PROJECT_NAME}
|
2024-08-29 13:51:17 -05:00
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/mqtt>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
set_target_properties( ${PROJECT_NAME}
|
2024-08-29 13:51:17 -05:00
|
|
|
PROPERTIES
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED OFF # Whether CXX_STANDARD is enforced
|
2024-08-10 12:58:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
if ( ${CMAKE_HOST_WIN32} )
|
2024-08-29 13:51:17 -05:00
|
|
|
# On Windows, libraries are not generally prefixed with "lib".
|
|
|
|
# If left unchanged, cmake will still add this prefix.
|
|
|
|
set_target_properties( ${PROJECT_NAME}
|
|
|
|
PROPERTIES
|
|
|
|
PREFIX ""
|
|
|
|
IMPORT_PREFIX ""
|
|
|
|
)
|
2024-08-10 12:58:21 -05:00
|
|
|
endif()
|