zephyr笔记 1.3 开发环境的拓展了解

本文介绍Zephyr开发中Cmake与Ninja的使用方法,包括Cmake生成Ninja编译文件的过程及Ninja的基础命令,适合初学者入门。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 前言

前一节1.2 软件开发环境准备学习了软件开发环境的搭建,但部分细节还讳莫如深,择日不如撞日,我们赶紧认识一下。本节对编译过程中的 Cmake 和 Ninja 做个拓展了解,这也是官方教程没体现的部分。

我正在学习 Zephyr,一个很可能会用到很多物联网设备上的操作系统,如果你也感兴趣,可点此查看帖子zephyr学习笔记汇总

2 Cmake

Build 过程中有用到 Cmake 命令来配置生成 Ninja 编译所需的文件。

# Use cmake to configure a Ninja-based build system:
cmake -GNinja -DBOARD=nrf52_pca10040 ..

使用 Ninja 时需要生成 build.ninja 文件,对于大型项目来说一条一条地写配置文件是不可能的,可以使用Cmake来生成这个配置文件。

Cmake支持参数Camke -G Ninja,Cmake会根据用户给定的CMakeLists.txt来生成build.ninja文件,接着才能进行ninja编译。

CmakeLists文件的语法这里写不深究,结合build日志感受下。

D:\zephyr_path\zephyr\samples\basic\blinky\build>cmake -GNinja -DBOARD=nucleo_l073rz ..
CMake Deprecation Warning at D:/winter/resources/zephyr/zephyr/cmake/app/boilerplate.cmake:38 (cmake_policy):
  The OLD behavior for policy CMP0000 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:1 (include)


-- Selected BOARD nucleo_l073rz
Zephyr version: 1.11.99
Parsing Kconfig tree in D:/winter/resources/zephyr/zephyr//Kconfig
Using D:/zephyr_path/zephyr/samples/basic/blinky/build/zephyr/.config as base
-- Generating zephyr/include/generated/generated_dts_board.h
nucleo_l073rz.dts_compiled: Warning (unit_address_vs_reg): Node /soc/pin-controller has a reg or ranges property, but no unit name
nucleo_l073rz.dts_compiled: Warning (unit_address_vs_reg): Node /soc/pin-controller/usart1@0 has a unit name, but no reg property
nucleo_l073rz.dts_compiled: Warning (unit_address_vs_reg): Node /soc/pin-controller/usart2@0 has a unit name, but no reg property
-- Configuring done
-- Generating done
-- Build files have been written to: D:/zephyr_path/zephyr/samples/basic/blinky/build

在 /zephyr/samples/basic/blinky/build 目录下,就看到了一堆 build 所需的文件。

3 ninja的基础用法

Ninja 官网点击这里。

不过我们使用 ninja -help 命令,也能看到 Ninja 常见命令,如下:

Cleaning targets:
  clean     - Remove most generated files but keep configuration and backup files
  pristine  - Remove all files in the build directory

Configuration targets:

  run <ninja kconfig-usage>

Other generic targets:
  all          - Build a zephyr application
  run          - Build a zephyr application and run it if the board supports emulation
  flash        - Build and flash an application
  debug        - Build and debug an application using GDB
  debugserver  - Build and start a GDB server (port 1234 for Qemu targets)
  ram_report   - Build and create RAM usage report
  rom_report   - Build and create ROM usage report
  usage        - Display this text

特别是 pristine 命令,如果工程要切换 board,那么就需要这么做。

4 总结

这篇笔记对工程编译用到的 Cmake 和 Ninja 做了个简单了解。

End


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值