diff --git a/tinyxml2/BUILD.gn b/tinyxml2/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..841c59ec2181b8428ca3f3be192d2735631d40eb --- /dev/null +++ b/tinyxml2/BUILD.gn @@ -0,0 +1,62 @@ +# Copyright (c) 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. + +import("//build/ohos.gni") + +declare_args() { + enable_tinyxml2_test = false +} + +config("tinyxml2_config") { + include_dirs = [ "//third_party/tinyxml2/tinyxml2" ] + + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-funwind-tables", + "-fstack-protector-strong", + "-no-canonical-prefixes", + "-fno-addrsig", + "-Wa,--noexecstack", + "-Wformat", + "-Werror=format-security", + "-D__MUSL__", + "-fPIC", + "-fvisibility=hidden", + "-fvisibility-inlines-hidden", + ] +} + +ohos_shared_library("tinyxml2_shared") { + sources = [ "//third_party/tinyxml2/tinyxml2/tinyxml2.cpp" ] + + configs = [ ":tinyxml2_config" ] + + deps = [] + + part_name = "tinyxml2" +} + +ohos_executable("xmltest") { + sources = [ "//third_party/tinyxml2/tinyxml2/xmltest.cpp" ] + deps = [ ":tinyxml2_shared" ] + configs = [ ":tinyxml2_config" ] + part_name = "tinyxml2" +} + +group("tinyxml2") { + deps = [ ":tinyxml2_shared" ] + if (enable_tinyxml2_test) { + deps += [ ":xmltest" ] + } +} diff --git a/tinyxml2/CMakeLists.txt b/tinyxml2/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..02a4659b850228fbcfe2bc250078c2bde99ab681 --- /dev/null +++ b/tinyxml2/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 3.4.1) + +project(tinyxml2) + +set(TARGET_NAME tinyxml2) + +add_subdirectory(${TARGET_NAME}) + + + diff --git a/tinyxml2/README.OpenSource b/tinyxml2/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..cfe181c624517743ae94a3392e0a95db1979993a --- /dev/null +++ b/tinyxml2/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "tinyxml2", + "License": "zlib license", + "License File": "LICENSE", + "Version Number": "v9.0.0", + "Owner": "longfeng20@huawei.com", + "Upstream URL": "https://github.com/leethomason/tinyxml2.git", + "Description": "TinyXML-2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs." + } +] diff --git a/tinyxml2/README_zh.md b/tinyxml2/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..b6823f9c3e7c67208d9a1a51e3bc1a48270f9932 --- /dev/null +++ b/tinyxml2/README_zh.md @@ -0,0 +1,15 @@ +# tinyxml2三方库说明 +## 功能简介 +TinyXML2 是 simple、small、efficient 的开源 C++ XML 文件解析库,可以很方便地应用到现有的项目中。 +## 使用约束 +- ROM版本:OpenHarmony-v3.2-Beta1 +- IDE版本:DevEco Studio 3.1 Beta1(3.1.0.200) +- SDK:API9 Release(3.2.10.6) +- 三方库版本:v9.0.0 + +- 当前适配的功能:xml解析 + +- [zlib License](https://github.com/leethomason/tinyxml2/blob/9.0.0/LICENSE.txt) +## 集成方式 ++ [系统Rom包集成](docs/rom_integrate.md) ++ [应用Hap包集成](docs/hap_integrate.md) diff --git a/tinyxml2/bundle.json b/tinyxml2/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..988d993ca1ac707a8d886ccf4a00ec8228664e19 --- /dev/null +++ b/tinyxml2/bundle.json @@ -0,0 +1,33 @@ +{ + "name": "@ohos/tinyxml2", + "description": "A fast JSON parser/generator for C++ with both SAX/DOM style API", + "version": "v9.0.0", + "license": "GNU LGPLv2+", + "publishAs": "", + "segment": { + "destPath": "third_party/tinyxml2" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "tinyxml2", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": ["//third_party/tinyxml2:tinyxml2"], + "inner_kits": [], + "test": [] + } + } +} diff --git a/tinyxml2/docs/hap_integrate.md b/tinyxml2/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..68e834ccede08fa8113229834057e28f81d3fab5 --- /dev/null +++ b/tinyxml2/docs/hap_integrate.md @@ -0,0 +1,57 @@ +# tinyxml2如何集成到应用hap +## 准备应用工程 +本库是基于DevEco Studio 3.1 Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +### 准备应用开发环境 +- IDE版本:DevEco Studio 3.1 Beta1 +- SDK版本:OpenHarmony SDK +- API版本:API Version 9 + +应用环境准备具体可参照文档[通过IDE开发一个Napi工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) + +### 增加构建脚本及配置文件 + +- 下载本仓库代码
+ 通过[C/C++三方库TCP仓](https://gitee.com/openharmony-sig/tpc_c_cplusplus)下载本三方库代码并将其解压。 +- 仓库代码库目录结构说明 + ``` + tpc_c_cplusplus/tinyxml2 #三方库tinyxml2 的目录结构如下 + ├── docs #存放三方库相关文档的文件夹 + ├── BUILD.gn # 构建脚本,支持rom包集成 + ├── CmakeLists.txt #构建脚本,支持hap包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将tinyxml2 拷贝至工程xxxx/entry/src/main/cpp/thirdparty目录下 +### 准备三方库源码 +- 三方库下载地址:[tinyxml2](https://github.com/leethomason/tinyxml2), 版本:v9.0.0 + 解压后修改库文件名为tinyxml2,拷贝至工程xxxx/entry/src/main/cpp/thirdparty/tinyxml2目录下 +## 应用中使用三方库 +- 将三方库加入工程中,目录结构如下: + ``` + demo/entry/src/main/cpp + ├── thirdparty #三方库存放目录 + │ ├──tinyxml2 #三方库tinyxml2 + ├── CMakeLists.txt #工程目录的构建脚本 + ├── ..... #工程目录的其他文件 + ``` +- 在工程顶级CMakeLists.txt中引入三方库,增加如下代码 + ``` + target_include_directories(工程库名 PRIVATE thirdparty/tinyxml2/tinyxml2) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/tinyxml2) #引入子目录下的CMakeLists.txt + target_link_libraries(工程库名 PUBLIC tinyxml2) #工程依赖三方库tinyxml2 + ``` +## 编译工程 + +- 连接上设备后,DevEco Studio就会显示被发现设备。然后,点击“运行”,即可依次完成该应用“编译”和“安装”的过程,如图: +  ![install](pic/install.png) + +## 运行效果 +- 在 [tinyxml2](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/tree/master/tinyxml2)中,运行效果如下图 +  ![演示](pic/hap.jpeg) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87deveco-studio%E5%BC%80%E5%8F%91%E4%B8%80%E4%B8%AAnapi%E5%B7%A5%E7%A8%8B) + diff --git a/tinyxml2/docs/pic/hap.jpeg b/tinyxml2/docs/pic/hap.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..677b7e9d1ca32b7b8f466d7247da8f5314ccc7f4 Binary files /dev/null and b/tinyxml2/docs/pic/hap.jpeg differ diff --git a/tinyxml2/docs/pic/install.png b/tinyxml2/docs/pic/install.png new file mode 100644 index 0000000000000000000000000000000000000000..58ac7e732a58239c3c256f918f4cbe5dafe1601a Binary files /dev/null and b/tinyxml2/docs/pic/install.png differ diff --git a/tinyxml2/docs/pic/result.png b/tinyxml2/docs/pic/result.png new file mode 100644 index 0000000000000000000000000000000000000000..f10c60c20b19be6045cfb3cd0eb8305d45b0a2e9 Binary files /dev/null and b/tinyxml2/docs/pic/result.png differ diff --git a/tinyxml2/docs/rom_integrate.md b/tinyxml2/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..28c307923c36c2616311275e5f050a8d00d48e5b --- /dev/null +++ b/tinyxml2/docs/rom_integrate.md @@ -0,0 +1,111 @@ +# tinyxml2如何集成到系统Rom +## 准备源码工程 +本库是基于OpenHarmony-v3.2-Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +### 准备系统Rom源码 +系统源码获取请参考:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta2/zh-cn/release-notes/OpenHarmony-v3.2-beta1.md) +### 增加构建脚本及配置文件 +- 下载本仓库代码 + ``` + cd ~ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/tinyxml2 #三方库tinyxml2的目录结构如下 + ├── adapted #存放三方库适配需要的代码文件 + ├── docs #存放三方库相关文档的文件夹 + ├── BUILD.gn #构建脚本,支持rom包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将三方库拷贝到OpenHarmony源码的third_party目录下 + ``` + cp ~/tpc_c_cplusplus/tinyxml2 ~/openharmony/third_party -rf + ``` +### 准备三方库源码 +``` +cd ~/openharmony/third_party/tinyxml2 #进入三方库目录 +git clone https://github.com/leethomason/tinyxml2.git #下载三方库源码 +``` +## 系统Rom中引入三方库 +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) +我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +新增需要编译的组件,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件中,新增需要编译的组件,如下代码段所示,在thirdparty子系统下面新增tinyxml2组件。 + +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "tinyxml2", + "features": [] + } + ] + } + +``` +## 系统Rom中引入三方库测试程序 +如果需要编译测试用例,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项,如下 +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "tinyxml2", + "features": ["enable_tinyxml2_test=true"] + } + ] + } +``` +## 编译工程 +在OpenHarmony源码根目录下 +``` +cd ~/openharmony +``` +- 选择平台 + ``` + hb set #hb set 命令会列出所有可选平台,这里我们选择rk3568 + ``` +- 执行编译 + ``` + hb build --target-cpu arm #编译32位系统 + hb build --target-cpu arm64 #编译64位系统 + ``` +- 生成文件的路径,可执行文件和库文件都在out/rk3568/thirdparty/tinyxml 目录下,同时也打包到了镜像中 +## 运行效果 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 + 工具编译出来所在路径out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + + ``` + hb set #源码根目录下使用hb set 选择产品ohos-sdk + hb build #然后编译 + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 将原生库测试需要的所有文件打包成tinyxml2.tar,并拷贝到windows下 +- 将文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -oremount,rw / #修改系统权限为可读写 + hdc_std file send tinyxml2.tar / #将文件包推入开发板 + hdc_std shell #进入开发板 + tar xvf tinyxml2.tar #解压 + #注意需要将库拷贝到/system/lib 或者/system/lib64目录下 + ``` +- 运行测试程序 + 运行测试用例,结果如下图 + ![result](pic/result.png) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) \ No newline at end of file