diff --git a/thirdparty/cpu_features/HPKBUILD b/thirdparty/cpu_features/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..8d01af4867bbe91e712d31151dc42c2d67bb2e70 --- /dev/null +++ b/thirdparty/cpu_features/HPKBUILD @@ -0,0 +1,72 @@ +# Copyright (c) 2023 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. + +# Contributor: wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangyihao<2471389@stu.neu.edu.cn>, wangying +# Maintainer: wangyihao<2471389@stu.neu.edu.cn>, wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangying + +pkgname=cpu_features +pkgver=v0.4.0 +pkgrel=0 +pkgdesc="cpu_features is a cross-platform C library to retrieve CPU features (such as available instructions) at runtime." +url="https://github.com/google/cpu_features/tree/v0.4.0" +archs=("armeabi-v7a" "arm64-v8a") +license=("Apache License 2.0") +depends=() +makedepends=() +source="https://github.com/google/cpu_features/archive/refs/tags/v0.4.0.zip" + +downloadpackage=true +autounpack=true +buildtools=cmake +patchflag=true + +builddir=cpu_features-0.4.0 +packagename=cpu_features-v0.4.0.zip + +# 为编译设置环境,如设置环境变量,创建编译目录等 +prepare() { + if $patchflag + then + cd $builddir + #克隆googletest源码时,由于master分支已不存在,更新为默认的main分支 + patch -p1 < `pwd`/../cpu_features-0.4.0_oh_pkg.patch + #patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + mkdir -p $builddir/$ARCH-build +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -DCMAKE_C_FLAGS="-Wno-unused-command-line-argument" \ + -DCMAKE_CXX_FLAGS="-Wno-unused-command-line-argument" -B$ARCH-build -S./ -DBUILD_TESTING=ON > $buildlog 2>&1 + $MAKE VERBOSE=1 -C $ARCH-build >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + $MAKE -C $ARCH-build install >> $buildlog 2>&1 + cd $OLDPWD +} + +check() { + echo "The test must be on an OpenHarmony device!" +} + +cleanbuild() { + rm -rf ${PWD}/$builddir +} \ No newline at end of file diff --git a/thirdparty/cpu_features/HPKCHECK b/thirdparty/cpu_features/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..45087f23bbfe1b9cac2c3352e606b765ef4a975f --- /dev/null +++ b/thirdparty/cpu_features/HPKCHECK @@ -0,0 +1,33 @@ +# Copyright (c) 2023 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. + +# Contributor: wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangyihao<2471389@stu.neu.edu.cn>, wangying +# Maintainer: wangyihao<2471389@stu.neu.edu.cn>, wangjialun<2271411@stu.neu.edu.cn>, zhangqian<2371418@stu.neu.edu.cn>, wangying + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${OHOS_SDK_VER}_test.log + + +# 在OH环境执行测试的接口 +openharmonycheck() { + res=0 + cd ${builddir}/${ARCH}-build # 进入到测试目录 + ctest > $logfile 2>&1 + res=$? + if [ $res -ne 0 ];then + mkdir ${LYCIUM_FAULT_PATH}/${pkgname} + cp Testing/Temporary/LastTest.log ${LYCIUM_FAULT_PATH}/${pkgname}/ + fi + cd $OLDPWD + return $res +} \ No newline at end of file diff --git a/thirdparty/cpu_features/README.OpenSource b/thirdparty/cpu_features/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..af133c7c944e3d712c12820026ac886f0ae2b28d --- /dev/null +++ b/thirdparty/cpu_features/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "cpu_features", + "License": "Apache License 2.0", + "License File": "https://github.com/google/cpu_features/blob/main/LICENSE", + "Version Number": "v0.4.0", + "Owner": "2942375747@qq.com", + "Upstream URL": "https://github.com/google/cpu_features", + "Description": "cpu_features is a cross-platform C library to retrieve CPU features (such as available instructions) at runtime." + } +] \ No newline at end of file diff --git a/thirdparty/cpu_features/README_zh.md b/thirdparty/cpu_features/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..e0e8007453f36ff36256aed92a10e836d61db1de --- /dev/null +++ b/thirdparty/cpu_features/README_zh.md @@ -0,0 +1,9 @@ +# cpu_features三方库说明 +## 功能简介 +cpu_features是一个跨平台的C库,用于在运行时检索CPU特性(如可用指令)。 +## 三方库版本: +- v0.4.0 +## 使用约束: +- [IDE和SDK版本](../../docs/constraint.md) +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) \ No newline at end of file diff --git a/thirdparty/cpu_features/SHA512SUM b/thirdparty/cpu_features/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..9b087e8e08ff4a9505ef12ceae452c5cb8e88627 --- /dev/null +++ b/thirdparty/cpu_features/SHA512SUM @@ -0,0 +1 @@ +791b8e29d0171ca3657e0bdaaf09cb7c41aaea13718a8565b5248ba22e88e7f5944bb182090c5a60f1169ce5607407fe7543579bff17cc78a260d5936a316536 cpu_features-v0.4.0.zip \ No newline at end of file diff --git a/thirdparty/cpu_features/cpu_features-0.4.0_oh_pkg.patch b/thirdparty/cpu_features/cpu_features-0.4.0_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..c481c2757e81e80b1819757b59d86c51c94c4b50 --- /dev/null +++ b/thirdparty/cpu_features/cpu_features-0.4.0_oh_pkg.patch @@ -0,0 +1,15 @@ +diff -urN cpu_features-0.4.0_old/cmake/googletest.CMakeLists.txt.in cpu_features-0.4.0/cmake/googletest.CMakeLists.txt.in +--- cpu_features-0.4.0_old/cmake/googletest.CMakeLists.txt.in 2019-07-05 14:47:41.000000000 +0800 ++++ cpu_features-0.4.0/cmake/googletest.CMakeLists.txt.in 2024-10-31 00:24:41.901607783 +0800 +@@ -5,11 +5,11 @@ + include(ExternalProject) + ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git +- GIT_TAG master ++ GIT_TAG main + SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND " \ No newline at end of file diff --git a/thirdparty/cpu_features/docs/hap_integrate.md b/thirdparty/cpu_features/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..89df86225e717c99d5096d25f050568e84ba048d --- /dev/null +++ b/thirdparty/cpu_features/docs/hap_integrate.md @@ -0,0 +1,80 @@ +# cpu_features集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/cpu_features #三方库cpu_features的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库简介 + ├── cpu_features_oh_pkg.patch #用于cpu_features库编译的补丁 + ``` + +- 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh cpu_features + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + cpu_features/arm64-v8a cpu_features/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的头文件和静态库文件拷贝到该目录下,如下图所示: +   + +  ![thirdparty_install_dir](pic/cpu_features_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cpu_features/${OHOS_ARCH}/lib/libcpu_features.a) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cpu_features/${OHOS_ARCH}/include) + ``` + +## 测试三方库 + +- 编译出可执行的文件,使用原库自带的测试用例来做测试 [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) +进入到构建目录运行测试用例(注意arm64-v8a为构建64位的目录,armeabi-v7a为构建32位的目录)。执行结果如图所示 + +```shell + cd /data/tpc_c_cplusplus/thirdparty/cpu_features/cpu_features-0.4.0/arm64-v8a-build/ + ctest +``` + ![cpu_features_test](pic/cpu_features_test.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) \ No newline at end of file diff --git a/thirdparty/cpu_features/docs/pic/cpu_features_install_dir.png b/thirdparty/cpu_features/docs/pic/cpu_features_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..52989c4fc57c60451cd944f249aed5a1b9d4bf92 Binary files /dev/null and b/thirdparty/cpu_features/docs/pic/cpu_features_install_dir.png differ diff --git a/thirdparty/cpu_features/docs/pic/cpu_features_test.png b/thirdparty/cpu_features/docs/pic/cpu_features_test.png new file mode 100644 index 0000000000000000000000000000000000000000..d043962973ff2ff085c0c6f8c0f55f084148ffc1 Binary files /dev/null and b/thirdparty/cpu_features/docs/pic/cpu_features_test.png differ