forked from apache/nuttx-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
151 lines (134 loc) · 4.47 KB
/
CMakeLists.txt
File metadata and controls
151 lines (134 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# ##############################################################################
# apps/netutils/mqttc/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
if(CONFIG_NETUTILS_MQTTC)
# ############################################################################
# Config and Fetch MQTTC lib
# ############################################################################
set(MQTTC_DIR ${CMAKE_CURRENT_LIST_DIR}/MQTT-C)
if(NOT EXISTS ${MQTTC_DIR})
set(MQTTC_URL "https://github.com/LiamBindle/MQTT-C/archive")
FetchContent_Declare(
mqttc_fetch
URL ${MQTTC_URL}/${CONFIG_NETUTILS_MQTTC_VERSION}.tar.gz SOURCE_DIR
${MQTTC_DIR} BINARY_DIR ${NUTTX_APPS_BINDIR}/netutils/mqttc/MQTT-C
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)
FetchContent_GetProperties(mqttc_fetch)
if(NOT mqttc_fetch_POPULATED)
FetchContent_Populate(mqttc_fetch)
endif()
execute_process(
COMMAND patch -s -N -d ${MQTTC_DIR} -p1 -i
${CMAKE_CURRENT_LIST_DIR}/0001_add_connection_status.patch
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif()
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${MQTTC_DIR}/include)
set(CFLAGS -Wno-return-type)
if(CONFIG_NETUTILS_MQTTC_WITH_MBEDTLS)
list(APPEND CFLAGS -DMQTT_USE_MBEDTLS)
endif()
file(GLOB CSRCS ${MQTTC_DIR}/src/*.c)
nuttx_add_library(mqttc STATIC)
target_sources(mqttc PRIVATE ${CSRCS})
target_compile_options(mqttc PRIVATE ${CFLAGS})
if(CONFIG_NETUTILS_MQTTC_WITH_MBEDTLS AND CONFIG_CRYPTO_MBEDTLS)
nuttx_add_dependencies(TARGET mqttc DEPENDS mbedtls)
endif()
if(CONFIG_NETUTILS_MQTTC_EXAMPLE)
if(CONFIG_NETUTILS_MQTTC_WITH_MBEDTLS)
nuttx_add_application(
NAME
mqttc_mbedtls_pub
STACKSIZE
${CONFIG_NETUTILS_MQTTC_EXAMPLE_STACKSIZE}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
SRCS
${MQTTC_DIR}/examples/mbedtls_publisher.c
COMPILE_FLAGS
${CFLAGS}
DEPENDS
mqttc
mbedtls)
else()
set(MQTT_PUB_CFLAGS
${CFLAGS}
-Dopen_nb_socket=pub_open_nb_socket
-Dexit_example=pub_exit_example
-Dpublish_callback=pub_publish_callback
-Dclient_refresher=pub_client_refresher)
set(MQTT_SUB_CFLAGS
${CFLAGS}
-Dopen_nb_socket=sub_open_nb_socket
-Dexit_example=sub_exit_example
-Dpublish_callback=sub_publish_callback
-Dclient_refresher=sub_client_refresher)
nuttx_add_application(
NAME
mqttc_posix_pub
STACKSIZE
${CONFIG_NETUTILS_MQTTC_EXAMPLE_STACKSIZE}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
SRCS
${MQTTC_DIR}/examples/simple_publisher.c
COMPILE_FLAGS
${MQTT_PUB_CFLAGS}
DEPENDS
mqttc)
nuttx_add_application(
NAME
mqttc_posix_sub
STACKSIZE
${CONFIG_NETUTILS_MQTTC_EXAMPLE_STACKSIZE}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
SRCS
${MQTTC_DIR}/examples/simple_subscriber.c
COMPILE_FLAGS
${MQTT_SUB_CFLAGS}
DEPENDS
mqttc)
endif()
endif()
if(CONFIG_NETUTILS_MQTTC_TEST)
set(MQTT_TEST_CFLAGS ${CFLAGS} -Dopen_nb_socket=test_open_nb_socket
-Dpublish_callback=test_publish_callback)
nuttx_add_application(
NAME
cmocka_mqttc_test
STACKSIZE
${CONFIG_NETUTILS_MQTTC_TEST_STACKSIZE}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
SRCS
${MQTTC_DIR}/tests.c
COMPILE_FLAGS
${MQTT_TEST_CFLAGS}
DEPENDS
cmocka
mqttc)
endif()
endif()