openharmony 6.1 L1 适配mosquito三方库
·
参考cJSON进行编译mosquito,三方库源码位置;third_party,先查看已存在的三方库
ls third_party/
EGL brotli dav1d glslang jsoncpp libnl ltp musl openmax sane-airscan v4l2-ctl
FatFs bzip2 decimal.js gn lame libphonenumber lwip ncurses openssl selinux vixl
FreeBSD cJSON e2fsprogs googletest libabigail libpng lz4 nghttp2 optimized-routines skia vk-gl-cts
NuttX cangjie_compiler elfio gptfdisk libbpf libtiff lzma ninja parse5 sonic vulkan-headers
PyYAML cangjie_runtime elfutils grpc libcoap libunwind markupsafe node pcre2 spirv-headers vulkan-loader
abseil-cpp cangjie_tools exfatprogs harfbuzz libdrm liburing mbedtls noto-cjk popt spirv-tools weex-loader
alsa-lib cares f2fs-tools icu libedit libusb media-ctl notofonts protobuf sqlite wpa_supplicant
alsa-utils cmsis ffmpeg iptables libevdev libuv mesa3d ntfs-3g pulseaudio tex-hyphen zlib
astc-encoder css-what flatbuffers jerryscript libexif libvpx meshoptimizer openGLES python toybox
backends cups freetype jinja2 libfuse libwebsockets mindspore openSLES qrcodegen typescript
benchmark cups-filters fsverity-utils jsframework libinput libxml2 mksh opencl-headers re2 tzdata
bounds_checking_function curl glfw json libjpeg-turbo littlefs mtdev openhitls rust unity
源码下载位置:https://mosquitto.org/files/source/,当前使用版本为2.0.9
下载mosquito源码,解压至third_party,修改名为mosquito,并创建编译规则BUILD.gn与bundle.json
ls third_party/mosquitto/
BUILD.gn LICENSE.txt README-windows.txt apps config.h epl-v20 lib man plugins service
CMakeLists.txt Makefile README.md bundle.json config.mk examples libmosquitto.pc.in misc pskfile.example snap
CONTRIBUTING.md README-compiling.md about.html client deps include libmosquittopp.pc.in mosquitto.conf pwfile.example src
ChangeLog.txt README-letsencrypt.md aclfile.example cmake edl-v10 installer logo notice.html security test
third_party/mosquitto/bundle.json内容如下:
{
"name": "@ohos/mosquitto",
"description": "Third-party mosquitto MQTT library",
"version": "2.0.9",
"license": "MIT",
"publishAs": "code-segment",
"segment": {
"destPath": "third_party/mosquitto"
},
"dirs": {},
"scripts": {},
"component": {
"name": "mosquitto",
"subsystem": "thirdparty",
"syscap": [],
"features": [],
"adapted_system_type": [ "mini", "small", "standard" ],
"rom": "",
"ram": "",
"deps": {
"components": [],
"third_party": []
},
"build": {
"sub_component": [],
"inner_kits": [
{
"header": {
"header_base": "//third_party/mosquitto",
"header_files": []
},
"name": "//third_party/mosquitto:mosquitto"
},
{
"name": "//third_party/mosquitto:mosquitto_static"
}
],
"test": []
}
}
}
third_party/mosquitto/BUILD.gn
#Copyright (c) 2019-2021 Huawei Device Co., Ltd.
#Licensed 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.
{
config("mosquitto_config") {
#头文件
include_dirs = [
"//third_party/mosquitto",
"//third_party/mosquitto/deps",
"//third_party/mosquitto/src",
"//third_party/mosquitto/lib",
"//third_party/mosquitto/include" ]
ldflags = [ "-lm","-lpthread" ]
#宏
#defines = [ "CJSON_NESTING_LIMIT=(128)" ]
defines = [
#"WITH_BROKER",
"WITH_PERSISTENCE",
"VERSION=\"2.0.18\""
]
}
#源文件
mosquitto_sources = [
lib/actions.c
lib/handle_publish.c
lib/messages_mosq.c
lib/read_handle.c
lib/strings_mosq.c
lib/alias_mosq.c
lib/handle_pubrec.c
lib/misc_mosq.c
lib/send_connect.c
lib/thread_mosq.c
lib/callbacks.c
lib/handle_pubrel.c
lib/mosquitto.c
lib/send_disconnect.c
lib/time_mosq.c
lib/connect.c
lib/handle_suback.c
lib/net_mosq.c
lib/send_mosq.c
lib/tls_mosq.c
lib/handle_auth.c
lib/handle_unsuback.c
lib/net_mosq_ocsp.c
lib/send_publish.c
lib/utf8_mosq.c
lib/handle_connack.c
lib/helpers.c
lib/options.c
lib/send_subscribe.c
lib/util_mosq.c
lib/handle_disconnect.c
lib/logging_mosq.c
lib/packet_datatypes.c
lib/send_unsubscribe.c
lib/util_topic.c
lib/handle_ping.c
lib/loop.c
lib/packet_mosq.c
lib/socks_mosq.c
lib/will_mosq.c
lib/handle_pubackcomp.c
lib/memory_mosq.c
lib/property_mosq.c
lib/srv_mosq.c
]
if (defined(board_toolchain_type) && board_toolchain_type == "iccarm") {
cflags = [
"--diag_suppress",
"Pe513",
]
cflags_cc = cflags
}
static_library("mosquitto_static") {
sources = mosquitto_sources
public_configs = [ ":mosquitto_config" ]
}
shared_library("mosquitto_shared") {
sources = mosquitto_sources
public_configs = [ ":mosquitto_config" ]
}
}
在build/lite/config/component/目录下创建mosquito文件夹,并在build/lite/config/component/mosquitto/目录下创建BUILD.gn
#
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed 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.
#
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
config("mosquitto_config") {
include_dirs = [
"//third_party/mosquitto",
"//third_party/mosquitto/deps",
"//third_party/mosquitto/src",
"//third_party/mosquitto/lib",
"//third_party/mosquitto/include"
]
ldflags = [ "-lm" ]
#defines = [ "WITH_BROKER=1" ]
defines = [
#"WITH_BROKER",
"WITH_PERSISTENCE",
"VERSION=\"2.0.18\""
]
if (board_toolchain_type == "iccarm") {
cflags = [
"--diag_suppress",
"Pa084",
]
}
}
mosquitto_sources = [
"//third_party/mosquitto/lib/actions.c",
"//third_party/mosquitto/lib/handle_publish.c",
"//third_party/mosquitto/lib/messages_mosq.c",
"//third_party/mosquitto/lib/read_handle.c",
"//third_party/mosquitto/lib/strings_mosq.c",
"//third_party/mosquitto/lib/alias_mosq.c",
"//third_party/mosquitto/lib/handle_pubrec.c",
"//third_party/mosquitto/lib/misc_mosq.c",
"//third_party/mosquitto/lib/send_connect.c",
"//third_party/mosquitto/lib/thread_mosq.c",
"//third_party/mosquitto/lib/callbacks.c",
"//third_party/mosquitto/lib/handle_pubrel.c",
"//third_party/mosquitto/lib/mosquitto.c",
"//third_party/mosquitto/lib/send_disconnect.c",
"//third_party/mosquitto/lib/time_mosq.c",
"//third_party/mosquitto/lib/connect.c",
"//third_party/mosquitto/lib/handle_suback.c",
"//third_party/mosquitto/lib/net_mosq.c",
"//third_party/mosquitto/lib/send_mosq.c",
"//third_party/mosquitto/lib/tls_mosq.c",
"//third_party/mosquitto/lib/handle_auth.c",
"//third_party/mosquitto/lib/handle_unsuback.c",
"//third_party/mosquitto/lib/net_mosq_ocsp.c",
"//third_party/mosquitto/lib/send_publish.c",
"//third_party/mosquitto/lib/utf8_mosq.c",
"//third_party/mosquitto/lib/handle_connack.c",
"//third_party/mosquitto/lib/helpers.c",
"//third_party/mosquitto/lib/options.c",
"//third_party/mosquitto/lib/send_subscribe.c",
"//third_party/mosquitto/lib/util_mosq.c",
"//third_party/mosquitto/lib/handle_disconnect.c",
"//third_party/mosquitto/lib/logging_mosq.c",
"//third_party/mosquitto/lib/packet_datatypes.c",
"//third_party/mosquitto/lib/send_unsubscribe.c",
"//third_party/mosquitto/lib/util_topic.c",
"//third_party/mosquitto/lib/handle_ping.c",
"//third_party/mosquitto/lib/loop.c",
"//third_party/mosquitto/lib/packet_mosq.c",
"//third_party/mosquitto/lib/socks_mosq.c",
"//third_party/mosquitto/lib/will_mosq.c",
"//third_party/mosquitto/lib/handle_pubackcomp.c",
"//third_party/mosquitto/lib/memory_mosq.c",
"//third_party/mosquitto/lib/property_mosq.c",
"//third_party/mosquitto/lib/srv_mosq.c"
]
lite_library("mosquitto_static") {
target_type = "static_library"
sources = mosquitto_sources
public_configs = [ ":mosquitto_config" ]
}
lite_library("mosquitto_shared") {
target_type = "shared_library"
sources = mosquitto_sources
public_configs = [ ":mosquitto_config" ]
}
ndk_lib("mosquitto_ndk") {
if (board_name != "hispark_pegasus") {
lib_extension = ".so"
deps = [ ":mosquitto_shared" ]
} else {
deps = [ ":mosquitto_static" ]
}
head_files = [
"//third_party/mosquitto/include/mosquitto.h",
"//third_party/mosquitto/include/mosquitto_plugin.h",
"//third_party/mosquitto/include/mosquitto_broker.h",
"//third_party/mosquitto/include/mqtt_protocol.h"
]
}
单独编译三方库
./build.sh --product-name rk3506 --vendor rockchip --ccache --gn-args enable_notice_collection=false linux_kernel_version="linux-6.1" --build-target=mosquitto_shared
生成文件路径:out/rk3506/rk3506/
ls out/rk3506/rk3506/libmosquitto_shared.so -l
-rwxr-xr-x 1 root root 79976 May 18 15:36 out/rk3506/rk3506/libmosquitto_shared.so
如果想要编译进系统,必须让其他组件依赖,才会触发编译,可以修改foundation/arkui/ui_lite/BUILD.gn文件,找到cJSON相关,再其下方添加如下内容
在cjson_static下一行添加
"//build/lite/config/component/mosquitto:mosquitto_static",
在cjson_shared下一行添加
"//build/lite/config/component/mosquitto:mosquitto_shared",
这样修改之后重新编译系统,就会触发编译mosquito,并生成libmosquitto_shared.so了,生成位置为:out/rk3506/rk3506/usr/lib/libmosquitto_shared.so
更多推荐

所有评论(0)