|
1 | | -# CMakeList.txt : CMake project for MQTTStreamingModule, include source and define |
2 | | -# project specific logic here. |
3 | | -# |
4 | | -set(CMAKE_POLICY_VERSION_MINIMUM 3.5) |
| 1 | +set(CMAKE_POLICY_VERSION_MINIMUM 3.5) |
5 | 2 | cmake_minimum_required(VERSION 3.25) |
6 | 3 |
|
7 | | -set(SDK_TARGET_NAMESPACE daq) |
8 | | -set(REPO_NAME mqtt_module) |
9 | | -set(REPO_OPTION_PREFIX MQTT_MODULE) |
| 4 | +set(REPO_NAME MqttModule) |
| 5 | +set(REPO_OPTION_PREFIX DAQMODULES_MQTT) |
10 | 6 | set(CMAKE_FOLDER "${CMAKE_FOLDER}/${REPO_NAME}") |
11 | 7 |
|
12 | | -project (${REPO_NAME} CXX) |
| 8 | +list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME}) |
| 9 | +add_subdirectory(cmake) |
13 | 10 |
|
14 | | -# Enable Hot Reload for MSVC compilers if supported. |
15 | | -if (POLICY CMP0141) |
16 | | - cmake_policy(SET CMP0141 NEW) |
17 | | - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>") |
18 | | -endif() |
| 11 | +opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/module_version" module_version) |
| 12 | +opendaq_get_version_major_minor_patch("${module_version}" ${REPO_OPTION_PREFIX}_VERSION) |
19 | 13 |
|
20 | | -if (POLICY CMP0135) |
21 | | - cmake_policy(SET CMP0135 NEW) |
| 14 | +# 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` |
| 15 | +# 32-bit Linux cross-compilation setup (must be before any project()) |
| 16 | +if (NOT DEFINED PROJECT_SOURCE_DIR AND OPENDAQ_FORCE_COMPILE_32BIT AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") |
| 17 | + opendaq_32bit_build_linux_early_setup() |
22 | 18 | endif() |
23 | 19 |
|
24 | | -if (POLICY CMP0077) |
25 | | - cmake_policy(SET CMP0077 NEW) |
26 | | -endif() |
| 20 | +project(${REPO_NAME} VERSION ${${REPO_OPTION_PREFIX}_VERSION} LANGUAGES CXX) |
27 | 21 |
|
28 | | -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
29 | | -list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME}) |
30 | | -set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context") |
| 22 | +opendaq_common_early_setup() |
31 | 23 |
|
32 | | -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 24 | +if (PROJECT_IS_TOP_LEVEL) |
| 25 | + message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} standalone") |
| 26 | +else() |
| 27 | + message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} as submodule") |
| 28 | +endif() |
33 | 29 |
|
34 | | -option(OPENDAQ_MQTT_MODULE_ENABLE_SSL "Enable building with openSSL" OFF) |
35 | | -option(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS "Enable building example applications" OFF) |
| 30 | +# options |
| 31 | +opendaq_setup_common_build_options() |
| 32 | +opendaq_setup_project_specific_build_options(${REPO_OPTION_PREFIX}) |
| 33 | +option(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP "Enable ${REPO_NAME} example applications" ${PROJECT_IS_TOP_LEVEL}) |
| 34 | +option(${REPO_OPTION_PREFIX}_ENABLE_TESTS "Enable ${REPO_NAME} testing" ${PROJECT_IS_TOP_LEVEL}) |
| 35 | +option(${REPO_OPTION_PREFIX}_ENABLE_SSL "Enable building with openSSL" OFF) |
36 | 36 |
|
37 | | -if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND NOT MSVC) |
38 | | - if (NOT WIN32) |
39 | | - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") |
40 | | - endif() |
41 | | - add_compile_options(-Wno-deprecated-declarations) |
42 | | -endif() |
| 37 | +opendaq_common_compile_targets_settings() |
| 38 | +opendaq_setup_compiler_flags(${REPO_OPTION_PREFIX}) |
43 | 39 |
|
44 | | -include(CommonUtils) |
45 | | -setup_repo(${REPO_OPTION_PREFIX}) |
| 40 | +if (${REPO_OPTION_PREFIX}_ENABLE_TESTS) |
| 41 | + message(STATUS "Unit tests in ${REPO_NAME} are ENABLED") |
| 42 | + enable_testing() |
| 43 | +else() |
| 44 | + message(STATUS "Unit tests in ${REPO_NAME} are DISABLED") |
| 45 | +endif() |
46 | 46 |
|
47 | | -if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS) |
| 47 | +if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP) |
48 | 48 | set(DAQMODULES_REF_DEVICE_MODULE ON CACHE BOOL "" FORCE) |
49 | 49 | endif() |
50 | 50 |
|
51 | | -option(OPENDAQ_MQTT_ENABLE_TESTS "Enable module testing" OFF) |
52 | | -option(OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS "Enable example applications building" OFF) |
53 | | - |
54 | | -if(OPENDAQ_MQTT_MODULE_ENABLE_SSL) |
| 51 | +if(${REPO_OPTION_PREFIX}_ENABLE_SSL) |
55 | 52 | find_package(OpenSSL REQUIRED) |
56 | 53 | if (OPENSSL_FOUND) |
57 | 54 | message(STATUS "Found OpenSSL ${OPENSSL_VERSION}") |
58 | 55 | else() |
59 | 56 | message(FATAL_ERROR "OpenSSL Not Found") |
60 | 57 | endif() |
61 | | - add_compile_definitions(OPENDAQ_MQTT_MODULE_ENABLE_SSL) |
| 58 | + add_compile_definitions(${REPO_OPTION_PREFIX}_ENABLE_SSL) |
62 | 59 | endif() |
63 | 60 |
|
64 | | -set(MQTT_MODULE_VERSION "0.1.0" CACHE STRING "MQTT module version" FORCE) |
65 | | - |
66 | | -if(OPENDAQ_MQTT_ENABLE_TESTS) |
67 | | - enable_testing() |
| 61 | +if (NOT TARGET "${OPENDAQ_SDK_TARGET_NAMESPACE}::${OPENDAQ_SDK_TARGET_NAME}") |
| 62 | + if (PROJECT_IS_TOP_LEVEL) |
| 63 | + find_package(${OPENDAQ_SDK_NAME} GLOBAL) |
| 64 | + endif() |
| 65 | + if (NOT ${OPENDAQ_SDK_NAME}_FOUND) |
| 66 | + include(FetchContent) |
| 67 | + set(OPENDAQ_ENABLE_TESTS OFF CACHE BOOL "") |
| 68 | + |
| 69 | + opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/opendaq_ref" OPENDAQ_REF) |
| 70 | + opendaq_get_custom_fetch_content_params(${OPENDAQ_SDK_NAME} FC_PARAMS) |
| 71 | + |
| 72 | + FetchContent_Declare( |
| 73 | + ${OPENDAQ_SDK_NAME} |
| 74 | + GIT_REPOSITORY https://github.com/openDAQ/openDAQ.git |
| 75 | + GIT_TAG ${OPENDAQ_REF} |
| 76 | + GIT_PROGRESS ON |
| 77 | + ${FC_PARAMS} |
| 78 | + ) |
| 79 | + FetchContent_MakeAvailable(${OPENDAQ_SDK_NAME}) |
| 80 | + else() |
| 81 | + message(STATUS "Found installed ${OPENDAQ_SDK_NAME} version: ${${OPENDAQ_SDK_NAME}_VERSION}") |
| 82 | + set(OPENDAQ_PACKAGE_VERSION "${${OPENDAQ_SDK_NAME}_VERSION}" CACHE INTERNAL "${OPENDAQ_SDK_NAME} SDK version") |
| 83 | + endif() |
68 | 84 | endif() |
69 | 85 |
|
70 | 86 | add_subdirectory(external) |
71 | 87 | add_subdirectory(shared) |
72 | 88 | add_subdirectory(modules) |
73 | 89 |
|
74 | | -if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS) |
75 | | - message(STATUS "Example applications have been enabled") |
| 90 | +if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP) |
| 91 | + message(STATUS "Example applications in ${REPO_NAME} are ENABLED") |
76 | 92 | add_subdirectory(examples) |
| 93 | +else() |
| 94 | + message(STATUS "Example applications in ${REPO_NAME} are DISABLED") |
77 | 95 | endif() |
0 commit comments