From 2c63053259a1a3527169e54788810edf9b0a16aa Mon Sep 17 00:00:00 2001 From: huangminzhong Date: Mon, 29 Aug 2022 23:12:14 -0700 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4gn=E6=9E=84=E5=BB=BA=E6=8C=87?= =?UTF-8?q?=E5=AF=BC=E5=92=8C=E8=A1=A5=E5=85=85=E9=A6=96=E9=A1=B5Opensourc?= =?UTF-8?q?e=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangminzhong --- README_zh.md | 4 +- common/gn_build.md | 60 +++++++++++++++++++++ common/gn_compile.md | 125 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 2 deletions(-) create mode 100755 common/gn_build.md create mode 100755 common/gn_compile.md diff --git a/README_zh.md b/README_zh.md index 19029ab5..e13dfd00 100755 --- a/README_zh.md +++ b/README_zh.md @@ -14,12 +14,12 @@ tpc_c_cplusplus ├── 三方库1 │ ├──gn #gn构建脚本、适配指导的文件夹 │ ├──cmake #cmake构建脚本、适配指导的文件夹 -│ ├──README_zh.md +│ ├──README_zh.md #目录下文件使用的介绍 │ ├──README.OpenSource #文件中包含了三方库源码的下载地址,版本,license等信息 ├── 三方库2 │ ├──gn #gn构建脚本、适配指导的文件夹 │ ├──cmake #cmake构建脚本、适配指导的文件夹 -│ ├──README_zh.md +│ ├──README_zh.md #目录下文件使用的介绍 │ ├──README.OpenSource #文件中包含了三方库源码的下载地址,版本,license等信息 ...... ``` diff --git a/common/gn_build.md b/common/gn_build.md new file mode 100755 index 00000000..4778ad1b --- /dev/null +++ b/common/gn_build.md @@ -0,0 +1,60 @@ +# 三方库引入GN工程 + +## 概述 + +本文介绍如何将三方库引入自己的GN工程 + + + +## 开发流程 + +这里以三方库thirdpartyA、动态库名libA的三方库引入到helloworld工程为例: + +### 目录结构 + +三方库thirdpartyA目录结构如下: + +``` +third_party/thirdpartyA +├── src +├── include +├── BUILD.gn +..... +``` + +helloworld工程目录结构如下: + +``` +third_party/helloworld +├── src +├── include +├── BUILD.gn +..... +``` + +### 引入三方库 + +在helloworld工程构建脚本中引入三方库thirdpartyA: + +``` +import("//build/ohos.gni") # 导入编译模板 +ohos_executable("helloworld") { # 可执行模块 + sources = [ # 模块源码 + "src/helloworld.c" + ] + include_dirs = [ # 模块依赖头文件目录 + "include" , + “//third_party/thirdpartyA/include”, #依赖三方库头文件的目录 + ] + cflags = [] + cflags_c = [] + cflags_cc = [] + ldflags = [] + configs = [] + deps =[] # 部件内部依赖 + deps += [ “//third_party/thirdpartyA:libA” ] #依赖三方库库文件 + part_name = "hello" # 所属部件名称,必选 + install_enable = true # 是否默认安装(缺省默认不安装),可选 +} +``` + diff --git a/common/gn_compile.md b/common/gn_compile.md new file mode 100755 index 00000000..228ea60d --- /dev/null +++ b/common/gn_compile.md @@ -0,0 +1,125 @@ +# 工程加入OpenHarmony构建体系 + +## 概述 + +本文介绍如何将自己的工程加入OpenHarmony进行编译 + + + +## 开发流程 + +以helloworld工程为例,有如下步骤 + +### 新增工程目录 + +``` +#在源码根目录下创建工程目录 +mkdir ~/openharmony/helloworld + +#在helloworld工程目录下新建源码文件 +touch hello.c + +#编写源文件内容如下 +#include + +void HelloPrint() +{ + printf("\n************************************************\n"); + printf("\n\t\tHello World!\n"); + printf("\n************************************************\n"); +} + +int main(int argc, char **argv) +{ + HelloPrint(); + return 0; +} + + +``` + + + +### 新增工程构建脚本 + +``` +#在helloworld工程目录下新增BUILD.gn脚本,内容如下 + +import("//build/ohos.gni") +ohos_executable("hello") { + sources = [ + "helloworld.c" + ] + include_dirs = [] + deps = [] + part_name = "hello" + install_enable = true +} +``` + + + +### 新增组件定义脚本 + +``` +#在helloworld工程目录下新增ohos.build脚本,内容如下 +{ + "subsystem": "helloworld", + "parts": { + "hello": { + "module_list": [ + "//helloworld:hello" + ] + } + } +} +``` + + + +### 新增产品定义 + +``` +#在vendor目录下新增产品的定义,这里以rk3568为例 +#在openharmony源码根目录下的vendor/hihope/rk3568/config.json,新增如下内容 + { + "subsystem": "helloworld", + "components": [ + { + "component": "hello", + "features": [] + } + ] + } + +``` + + + +### 新增子系统定义 + +``` +#在openharmony源码根目录下的build/subsystem_config.json中新增子系统定义 + + "helloworld": { + "path": "helloworld", + "name": "helloworld" + } +``` + + + +### 编译Openharmony镜像 + +``` +#在OpenHarmony源码根目录 +#选择需要编译的产品 +hb set + +#编译32位镜像 +hb build --target-cpu arm + +#编译64位镜像 +hb build --target-cpu arm64 +``` + -- Gitee