回复
hi 3861 编译构建 原创
wx6517b1bee1374
发布于 2024-12-24 21:50
浏览
0收藏
配置文件设计
配置文件
- 自动生成:src/ohos_config.json 指定 产品的配置文件路径
{
"root_path": "D:\\DevEco-Device-Tool\\Projects\\hi3861\\src",
"board": "hispark_pegasus",
"kernel": "liteos_m",
"product": "wifiiot_hispark_pegasus",
"product_path": "D:\\DevEco-Device-Tool\\Projects\\hi3861\\src\\vendor\\hisilicon\\hispark_pegasus",
"device_path": "D:\\DevEco-Device-Tool\\Projects\\hi3861\\src\\device\\hisilicon\\hispark_pegasus\\sdk_liteos"
}
- 产品的配置文件:
"product_path"
- 配置好各个子系统和对应的部件
- 误导人的:
src\build\subsystem_config.json
根本没有被编译进去
{
"product_name": "wifiiot_hispark_pegasus",
"ohos_version": "OpenHarmony 1.0",
"device_company": "hisilicon",
"board": "hispark_pegasus",
"kernel_type": "liteos_m",
"kernel_version": "",
"subsystems": [
{
"subsystem": "applications",
"components": [
{ "component": "app_wifi-iot_sample", "features":[] },
{ "component": "mqtt", "features":[]}
]
}
...
]
}
- 各子系统的配饰文件:
src\build\lite\components
{
"components": [
{
"component": "app_wifi-iot_sample",
"description": "Wifi iot samples.",
"optional": "true",
"dirs": [
"applications/sample/wifi-iot/app" # 路径
],
"targets": [
"//applications/sample/wifi-iot/app:app"
],
"rom": "",
"ram": "",
"output": [],
"adapted_board": [ "hi3861v100" ],
"adapted_kernel": [ "liteos_m" ],
"features": [],
"deps": {
"components": [
"utils_base" # 依赖组件
]
}
},
...
]
{
"component": "utils_base",
"description": "Basic macro and type definitions",
"optional": "true",
"dirs": [
"utils/native/lite/include"
],
"targets": [],
"rom": "0KB",
"ram": "0KB",
"output": [ ],
"adapted_kernel": [
"liteos_a",
"liteos_m",
"linux"
],
"features": [],
"deps": {}
},
- 部件下的 json 文件:
- 不知道有什么用
{
"name": "@ohos/applications_sample_wifi_iot",
"version": "",
"description": "供开发者参考的代码示例。",
"homePage": "https://gitee.com/openharmony",
"license": "Apache V2",
"repository": "https://gitee.com/openharmony/applications_sample_wifi_iot/tree/OpenHarmony-v3.0-LTS",
"domain": "os",
"language": "",
"publishAs": "code-segment",
"segment": {
"destPath": "applications/sample/wifi-iot"
},
"private": false,
"scripts": {},
"tags": [
"applications"
],
"keywords": [
"applications",
"sample",
"wifi",
"iot"
],
"envs": [],
"dirs": [],
"component": {
"name": "111",
"subsystem": "111",
"syscap": [],
"features": [],
"adapted_system_type": [
"standard",
"mini",
"standard"
],
"rom": "",
"ram": "",
"deps": {
"components": [],
"third_party": []
},
"build": {
"sub_component": [],
"inner_kits": [],
"test": []
}
}
}
- 部件下的 gn 文件:
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [
"00_thread:thread_demo",
"14_pwmbeer:pwm_beer_demo",
]
}
- 编译成功的提示
[OHOS INFO] wifiiot_hispark_pegasus build success
[OHOS INFO] cost time: 0:00:13
BUILD.gn 文件
目录:src\build\lite\BUILD.gn
- Read product configuration profile.(读产品的配置文件)
- Loop subsystems configured by product.(遍历文件中的子系统)
- Read OS subsystems profile.(读子系统的配置文件)
- Loop components configured by product.(遍历系统的配置文件中的部件配置)
- Check whether the component configured by product is exist.(检查是否存在)
- Skip component which not configured by product.(跳过那些没有在产品配置文件中写的部件)
3861 中定义模板的位置 src\build\lite\config\BUILDCONFIG.gn
- executable
- static_library
- shared_library
- source_set
- action
- action_foreach
src\build\lite\config\component\lite_component.gni
- lite_component
- lite_library
- build_ext_component
- ohos_tools
- generate_notice_file
补充 gn 语法
GN 提供了 gn build
命令从根目录递归构建。
# 根目录的 BUILD.gn 文件
deps = [
"//module1", # 引用子目录
"//module2",
]
# module1/BUILD.gn 文件
static_library("module1_lib") {
sources = [ "module1.cpp" ]
}
常见的目标类型
目标类型 | 用途 |
---|---|
executable |
定义可执行文件目标。 |
static_library |
定义静态库目标(生成 .a 文件)。 |
shared_library |
定义动态库目标(生成 .so 或 .dll 文件)。 |
source_set |
定义一组源文件,但不会单独生成产物。 |
group |
定义一组依赖,但不会生成文件(仅逻辑组织)。 |
属性 | 说明 |
---|---|
sources |
定义目标的源文件列表。 |
include_dirs |
定义目标的头文件路径。 |
defines |
定义编译器的宏。 |
deps |
定义目标的依赖(引用其他目标或外部库)。 |
cflags |
定义额外的 C 编译器标志。 |
ldflags |
定义链接器标志。 |
# 定义目标(如可执行文件、静态库)
executable("my_app") {
sources = [ "main.cpp" ]
deps = [ ":utils_lib" ] # 依赖其他目标
}
# 自定义模板
template("custom_library") {
sources = defined_sources
static_library(target_name) {
sources = sources
}
}
变量
# 字符串变量
output_dir = "out/my_app"
# 列表变量
source_files = [ "main.cpp", "utils.cpp" ]
# 布尔值
enable_feature = true
内置变量
变量名 | 说明 |
---|---|
current_toolchain |
当前工具链的名称。 |
current_cpu |
当前目标架构(如 "x64" , "arm" )。 |
current_os |
当前目标操作系统(如 "linux" , "win" )。 |
foreach(product_configed_subsystem, product_cfg.subsystems)
是 GN 中的循环语法,表示对product_cfg.subsystems
中的每个元素进行遍历,并将当前元素赋值给product_configed_subsystem
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
赞
收藏
回复
相关推荐