Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 62 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,95 @@
# CMakeList.txt : CMake project for MQTTStreamingModule, include source and define
# project specific logic here.
#
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
cmake_minimum_required(VERSION 3.25)

set(SDK_TARGET_NAMESPACE daq)
set(REPO_NAME mqtt_module)
set(REPO_OPTION_PREFIX MQTT_MODULE)
set(REPO_NAME MqttModule)
set(REPO_OPTION_PREFIX DAQMODULES_MQTT)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/${REPO_NAME}")

project (${REPO_NAME} CXX)
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
add_subdirectory(cmake)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/module_version" module_version)
opendaq_get_version_major_minor_patch("${module_version}" ${REPO_OPTION_PREFIX}_VERSION)

if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
# the following section is required if module-project being built standalone with 32bit arch, it is "temporary" workaround, though - the correct one would be using `-DCMAKE_TOOLCHAIN_FILE`
# 32-bit Linux cross-compilation setup (must be before any project())
if (NOT DEFINED PROJECT_SOURCE_DIR AND OPENDAQ_FORCE_COMPILE_32BIT AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
opendaq_32bit_build_linux_early_setup()
endif()

if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
project(${REPO_NAME} VERSION ${${REPO_OPTION_PREFIX}_VERSION} LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context")
opendaq_common_early_setup()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if (PROJECT_IS_TOP_LEVEL)
message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} standalone")
else()
message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} as submodule")
endif()

option(OPENDAQ_MQTT_MODULE_ENABLE_SSL "Enable building with openSSL" OFF)
option(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS "Enable building example applications" OFF)
# options
opendaq_setup_common_build_options()
opendaq_setup_project_specific_build_options(${REPO_OPTION_PREFIX})
option(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP "Enable ${REPO_NAME} example applications" ${PROJECT_IS_TOP_LEVEL})
option(${REPO_OPTION_PREFIX}_ENABLE_TESTS "Enable ${REPO_NAME} testing" ${PROJECT_IS_TOP_LEVEL})
option(${REPO_OPTION_PREFIX}_ENABLE_SSL "Enable building with openSSL" OFF)

if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND NOT MSVC)
if (NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
add_compile_options(-Wno-deprecated-declarations)
endif()
opendaq_common_compile_targets_settings()
opendaq_setup_compiler_flags(${REPO_OPTION_PREFIX})

include(CommonUtils)
setup_repo(${REPO_OPTION_PREFIX})
if (${REPO_OPTION_PREFIX}_ENABLE_TESTS)
message(STATUS "Unit tests in ${REPO_NAME} are ENABLED")
enable_testing()
else()
message(STATUS "Unit tests in ${REPO_NAME} are DISABLED")
endif()

if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS)
if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP)
set(DAQMODULES_REF_DEVICE_MODULE ON CACHE BOOL "" FORCE)
endif()

option(OPENDAQ_MQTT_ENABLE_TESTS "Enable module testing" OFF)
option(OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS "Enable example applications building" OFF)

if(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
if(${REPO_OPTION_PREFIX}_ENABLE_SSL)
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
else()
message(FATAL_ERROR "OpenSSL Not Found")
endif()
add_compile_definitions(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
add_compile_definitions(${REPO_OPTION_PREFIX}_ENABLE_SSL)
endif()

set(MQTT_MODULE_VERSION "0.1.0" CACHE STRING "MQTT module version" FORCE)

if(OPENDAQ_MQTT_ENABLE_TESTS)
enable_testing()
if (NOT TARGET "${OPENDAQ_SDK_TARGET_NAMESPACE}::${OPENDAQ_SDK_TARGET_NAME}")
if (PROJECT_IS_TOP_LEVEL)
find_package(${OPENDAQ_SDK_NAME} GLOBAL)
endif()
if (NOT ${OPENDAQ_SDK_NAME}_FOUND)
include(FetchContent)
set(OPENDAQ_ENABLE_TESTS OFF CACHE BOOL "")

opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/opendaq_ref" OPENDAQ_REF)
opendaq_get_custom_fetch_content_params(${OPENDAQ_SDK_NAME} FC_PARAMS)

FetchContent_Declare(
${OPENDAQ_SDK_NAME}
GIT_REPOSITORY https://github.com/openDAQ/openDAQ.git
GIT_TAG ${OPENDAQ_REF}
GIT_PROGRESS ON
${FC_PARAMS}
)
FetchContent_MakeAvailable(${OPENDAQ_SDK_NAME})
else()
message(STATUS "Found installed ${OPENDAQ_SDK_NAME} version: ${${OPENDAQ_SDK_NAME}_VERSION}")
set(OPENDAQ_PACKAGE_VERSION "${${OPENDAQ_SDK_NAME}_VERSION}" CACHE INTERNAL "${OPENDAQ_SDK_NAME} SDK version")
endif()
endif()

add_subdirectory(external)
add_subdirectory(shared)
add_subdirectory(modules)

if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS)
message(STATUS "Example applications have been enabled")
if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP)
message(STATUS "Example applications in ${REPO_NAME} are ENABLED")
add_subdirectory(examples)
else()
message(STATUS "Example applications in ${REPO_NAME} are DISABLED")
endif()
5 changes: 2 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@
"name": "full",
"hidden": true,
"cacheVariables": {
"OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS": "true",
"OPENDAQ_MQTT_ENABLE_TESTS": "true",
"OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS": "true"
"DAQMODULES_MQTT_ENABLE_EXAMPLE_APP": "true",
"DAQMODULES_MQTT_ENABLE_TESTS": "true"
}
},
{
Expand Down
14 changes: 14 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(CMAKE_FOLDER "cmake")

list(APPEND CMAKE_MESSAGE_CONTEXT cmake)
set(CURR_MESSAGE_CONTEXT ${CMAKE_MESSAGE_CONTEXT})

message(STATUS "Import functions and macro from opendaq-cmake-utils repo")
include(FetchContent)
FetchContent_Declare(
opendaq-cmake-utils
GIT_REPOSITORY https://github.com/openDAQ/opendaq-cmake-utils.git
GIT_TAG v1.0.0
GIT_PROGRESS ON
)
FetchContent_MakeAvailable(opendaq-cmake-utils)
151 changes: 0 additions & 151 deletions cmake/CommonUtils.cmake

This file was deleted.

5 changes: 2 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.16)
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

set(CMAKE_FOLDER "${CMAKE_FOLDER}/examples")

if (OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS)
if (${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP)
add_subdirectory(raw-mqtt-sub)
add_subdirectory(custom-mqtt-sub)
add_subdirectory(ref-dev-mqtt-pub)
Expand Down
1 change: 1 addition & 0 deletions examples/custom-mqtt-sub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

set(EXAMPLE_PROJECT_NAME "custom-mqtt-sub")

Expand Down
1 change: 1 addition & 0 deletions examples/raw-mqtt-sub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

set(EXAMPLE_PROJECT_NAME "raw-mqtt-sub")

Expand Down
1 change: 1 addition & 0 deletions examples/ref-dev-mqtt-pub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

set(EXAMPLE_PROJECT_NAME "ref-dev-mqtt-pub")

Expand Down
20 changes: 14 additions & 6 deletions examples/ref-dev-mqtt-pub/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
cmake_minimum_required(VERSION 3.16)

add_compile_definitions(MODULE_PATH="${OPENDAQ_MODULES_DIR}")
add_compile_definitions(APP_NAME="${EXAMPLE_PROJECT_NAME}")
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

if (TARGET daq::ref_device_module)
add_compile_definitions(MODULE_PATH="${OPENDAQ_MODULES_DIR}")
add_compile_definitions(APP_NAME="${EXAMPLE_PROJECT_NAME}")

add_executable(${EXAMPLE_PROJECT_NAME} ref-dev-mqtt-pub.cpp)
add_dependencies(${EXAMPLE_PROJECT_NAME} daq::ref_device_module)
target_link_libraries(${EXAMPLE_PROJECT_NAME} PRIVATE daq::opendaq)
target_include_directories(${EXAMPLE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../)
else()
message(WARNING "Building ${EXAMPLE_PROJECT_NAME} is canceled because of missing dependencies")
endif()


add_executable(${EXAMPLE_PROJECT_NAME} ref-dev-mqtt-pub.cpp)
add_dependencies(${EXAMPLE_PROJECT_NAME} daq::ref_device_module)
target_link_libraries(${EXAMPLE_PROJECT_NAME} PRIVATE daq::opendaq)
target_include_directories(${EXAMPLE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../)
13 changes: 7 additions & 6 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
set(CMAKE_FOLDER "${CMAKE_FOLDER}/external")
list(APPEND CMAKE_MESSAGE_CONTEXT external)
opendaq_set_cmake_folder_context(TARGET_FOLDER_NAME)

if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source build is not supported!")
endif()

include(FetchContent)
if (${REPO_OPTION_PREFIX}_ENABLE_TESTS AND (NOT TARGET gtest))
add_subdirectory(gtest)
endif()

add_subdirectory(opendaq)
add_subdirectory(mqtt)
add_subdirectory(rapidjson)
add_subdirectory(boost)
add_subdirectory(paho_mqtt_c)
add_subdirectory(rapidjson)
5 changes: 5 additions & 0 deletions external/boost/Boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opendaq_append_required_boost_components(
algorithm
date_time
)

Loading