diff --git a/thirdparty/json/HPKBUILD b/thirdparty/json/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..e1ae7067a96633b80a45f3cbae5471a2f3bad1a1 --- /dev/null +++ b/thirdparty/json/HPKBUILD @@ -0,0 +1,49 @@ +# Contributor: wupingyuan +# Maintainer: wupingyuan +pkgname=json +pkgver=v3.11.2 +pkgrel=0 +pkgdesc="JSON for Modern C++" +url="https://github.com/nlohmann/json" +archs=("armeabi-v7a" "arm64-v8a") +license=("MIT") +depends=() +makedepends=() +install= +source="https://github.com/nlohmann/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=true +downloadpackage=true +builddir=$pkgname-${pkgver:1} +packagename=$builddir.tar.gz + +prepare() { + mkdir -p $builddir/$ARCH-build +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -DOHOS_ARCH=$ARCH -B$ARCH-build -S./ -L > `pwd`/$ARCH-build/build.log 2>&1 + make -j4 -C $ARCH-build >> `pwd`/$ARCH-build/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + make -C $ARCH-build install >> `pwd`/$ARCH-build/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +check() { + echo "The test must be on an OpenHarmony device!" + # 在OpenHarmony开发板中执行用例 + # ctest +} + +cleanbuild(){ + rm -rf ${PWD}/$builddir #${PWD}/$packagename +} diff --git a/thirdparty/json/README.OpenSource b/thirdparty/json/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..f648e88a1947b281d2f47e9cca709173e6adee61 --- /dev/null +++ b/thirdparty/json/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "json", + "License": "MIT", + "License File": "LICENSE.MIT", + "Version Number": "v3.11.2", + "Owner": "wupingyuan@huawei.com", + "Upstream URL": "https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.tar.gz", + "Description": "JSON for Modern C++" + } +] diff --git a/thirdparty/json/README_zh.md b/thirdparty/json/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..19e81568e587a1fb317aac2db6ab4df5d70b296f --- /dev/null +++ b/thirdparty/json/README_zh.md @@ -0,0 +1,12 @@ +# json三方库说明 +## 功能简介 +json是一个C++的处理json数据解析的库。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Beta2 +- SDK版本:ohos_sdk_public 3.2.11.9 (API Version 9 Release) +- 三方库版本:v3.11.2 +- 当前适配的功能:json数据解析 +- [MIT](https://github.com/nlohmann/json) + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/json/SHA512SUM b/thirdparty/json/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..caa71fc9dbbea2658f082149471c8478315c6f96 --- /dev/null +++ b/thirdparty/json/SHA512SUM @@ -0,0 +1 @@ +70097c9bcd7a91254acbd41b8b68a6aaa371fc2dd7011f472917f69f1e2d2986155a0339dad791699d542e4a3be44dc49ae72ff73d0ee0ea4b34183296ce19a0 json-3.11.2.tar.gz \ No newline at end of file diff --git a/thirdparty/json/docs/hap_integrate.md b/thirdparty/json/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..54f0d7daf89264e4546eaa2ecead0a23019cfc20 --- /dev/null +++ b/thirdparty/json/docs/hap_integrate.md @@ -0,0 +1,140 @@ +# json集成到应用hap +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 开发环境 +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 3.2.11.9 (API Version 9 Release)](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fohos-sdk-windows_linux-public.tar.gz) +- [DevEco Studio 3.1 Beta2](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2Ff3%2Fv3%2FuJyuq3syQ2ak4hE1QZmAug%2Fdevecostudio-windows-3.1.0.400.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230408T013335Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D96262721EDC9B34E6F62E66884AB7AE2A94C2A7B8C28D6F7FC891F46EB211A70) +- [准备三方库构建环境](../../../tools/README.md#编译环境准备) +- [准备三方库测试环境](../../../tools/README.md#ci环境准备) +## 编译三方库 +- 下载本仓库 + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/thirdparty/json #三方库json的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 将json拷贝至tools/main目录下 + ``` + cd tpc_c_cplusplus + cp thirdparty/json tools/main -rf + ``` +- 在tools目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../tools/README.md#编译环境准备) + ``` + cd tools + ./build.sh json + ``` +- 三方库头文件及生成的库 + 在tools目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + ``` + json/arm64-v8a json/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + ![thirdparty_install_dir](pic/json_install_dir.jpg) +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ``` + #将三方库的头文件加入工程中(由于改库没有静态库或动态库,直接引入源文件使用) + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json/${OHOS_ARCH}/include) + ``` + ![json_usage](pic/json_usage.jpg) +## 测试三方库 +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../tools/README.md#ci环境准备) +先在linux系统进入构建目录执行ctest执行测试用例:download_test_data + ![json_test](pic/json_test1.jpg) +然后进入板子到构建目录执行以下可执行文件运行测试用例(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + ``` + ./tests/test-algorithms_cpp11 + ./tests/test-allocator_cpp11 + ./tests/test-alt-string_cpp11 + ./tests/test-assert_macro_cpp11 + ./tests/test-binary_formats_cpp11 + ./tests/test-bjdata_cpp11 + ./tests/test-bson_cpp11 + ./tests/test-byte_container_with_subtype_cpp11 + ./tests/test-capacity_cpp11 + ./tests/test-cbor_cpp11 + ./tests/test-class_const_iterator_cpp11 + ./tests/test-class_iterator_cpp11 + ./tests/test-class_lexer_cpp11 + ./tests/test-class_parser_cpp11 + ./tests/test-comparison_cpp11 + ./tests/test-comparison_cpp20 + ./tests/test-comparison_legacy_cpp11 + ./tests/test-comparison_legacy_cpp20 + ./tests/test-concepts_cpp11 + ./tests/test-constructor1_cpp11 + ./tests/test-constructor2_cpp11 + ./tests/test-convenience_cpp11 + ./tests/test-conversions_cpp11 + ./tests/test-conversions_cpp17 + ./tests/test-deserialization_cpp11 + ./tests/test-diagnostics_cpp11 + ./tests/test-disabled_exceptions_cpp11 + ./tests/test-element_access1_cpp11 + ./tests/test-element_access2_cpp11 + ./tests/test-element_access2_cpp14 + ./tests/test-element_access2_cpp17 + ./tests/test-hash_cpp11 + ./tests/test-inspection_cpp11 + ./tests/test-items_cpp11 + ./tests/test-items_cpp17 + ./tests/test-iterators1_cpp11 + ./tests/test-iterators2_cpp11 + ./tests/test-iterators2_cpp20 + ./tests/test-json_patch_cpp11 + ./tests/test-json_pointer_cpp11 + ./tests/test-json_pointer_cpp20 + ./tests/test-large_json_cpp11 + ./tests/test-merge_patch_cpp11 + ./tests/test-meta_cpp11 + ./tests/test-modifiers_cpp11 + ./tests/test-msgpack_cpp11 + ./tests/test-noexcept_cpp11 + ./tests/test-ordered_json_cpp11 + ./tests/test-ordered_map_cpp11 + ./tests/test-pointer_access_cpp11 + ./tests/test-readme_cpp11 + ./tests/test-reference_access_cpp11 + ./tests/test-regression1_cpp11 + ./tests/test-regression1_cpp17 + ./tests/test-regression2_cpp11 + ./tests/test-regression2_cpp17 + ./tests/test-regression2_cpp20 + ./tests/test-serialization_cpp11 + ./tests/test-testsuites_cpp11 + ./tests/test-to_chars_cpp11 + ./tests/test-type_traits_cpp11 + ./tests/test-ubjson_cpp11 + ./tests/test-udl_cpp11 + ./tests/test-udt_cpp11 + ./tests/test-udt_macro_cpp11 + ./tests/test-unicode1_cpp11 + ./tests/test-unicode2_cpp11 + ./tests/test-unicode3_cpp11 + ./tests/test-unicode4_cpp11 + ./tests/test-unicode5_cpp11 + ./tests/test-user_defined_input_cpp11 + ./tests/test-windows_h_cpp11 + ./tests/test-wstring_cpp11 + ``` + ![json_test](pic/json_test2.jpg) + +## 参考资料 +- [润和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) diff --git a/thirdparty/json/docs/pic/json_install_dir.jpg b/thirdparty/json/docs/pic/json_install_dir.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a722776aa72ed13ce4ca23bec5af67d902467e06 Binary files /dev/null and b/thirdparty/json/docs/pic/json_install_dir.jpg differ diff --git a/thirdparty/json/docs/pic/json_test1.jpg b/thirdparty/json/docs/pic/json_test1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3ed40570df0a770636288c2740bf0d1b7f617c7f Binary files /dev/null and b/thirdparty/json/docs/pic/json_test1.jpg differ diff --git a/thirdparty/json/docs/pic/json_test2.jpg b/thirdparty/json/docs/pic/json_test2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e3e2da0a6bf90c47c8494ee4b3368a565648e0ad Binary files /dev/null and b/thirdparty/json/docs/pic/json_test2.jpg differ diff --git a/thirdparty/json/docs/pic/json_usage.jpg b/thirdparty/json/docs/pic/json_usage.jpg new file mode 100644 index 0000000000000000000000000000000000000000..54852e609cf679b67228ef8b6078ea13e6151132 Binary files /dev/null and b/thirdparty/json/docs/pic/json_usage.jpg differ