-
Notifications
You must be signed in to change notification settings - Fork 15
工具链 CMake 进阶配置
本文介绍了如何使用 CMake Profile 编译针对不同开发板的程序。
前置阅读资料:工具链 概念介绍
CLion 说明是这样描述 CMake Profile 的:
In CLion, all the settings required for building a project are incorporated in a CMake profile. It accumulates toolchains, build types, CMake options, and environment variables (in other words, the compiler, linker, and CMake settings). You can create multiple profiles with different build types and toolchains:
在本工程中,由于 CMakeLists.txt 现已包含工具链配置,故不需要通过 CLion 配置 Toolchain(CLion 中的配置会被 CMakeLists.txt 中的配置覆盖),相关内容在本文配置末尾,作为参考。
而在 CLion 的 CMake 选项卡中,除了工具链,还有以下内容可以配置:
- Build Type。这个可以决定工程编译时的优化选项。
- Option。通过指定这一内容,可以向 CMake 传递额外的参数,我们通过改变 Option 控制编译的目标开发板。
File - Preferences(Setting) - Build, Execute, Deployment - CMake
此处可以新建多个 Profile。每个 Profile 可以组合以下选项:
- Debug:此 Build Type 会使用 -O0 -g 作为编译参数,用于开发过程中。
- Release:此 Build Type 会使用 -Os 作为编译参数,用于发布。
此处可以从外部向 CMake 传入参数。
-
-DBOARD_NAME="rm_board_2017"
: 使用 RM 2017 开发版。 -
-DBOARD_NAME="rm_board_2018_a"
: 使用 RM 2018 A型 开发版。
以上选项组合可以得到不同的 Profile。
例如,保存用于两个开发板的 Debug 配置:
File - Setting - Build, Execute, Deployment - Toolchains
- 添加一个 Toolchain 配置,命名为 arm-none-eabi
- 将 C Compiler, C++ Compiler 和 Debugger 更换为 arm-none-eabi
可执行文件一般在
/usr/local/bin
目录下,在文件选择窗口,可以按 Cmd+Shift+G 跳转)。
- 2019.02.13 初次发布。 liuzikai
- 2021.07.07 更新工具链系列文档顺序。liuzikai
- 基础知识
- 基础配置
- 进阶与参考