有没有办法从 Keil 构建配置中导出预定义的宏?

Is there a way to export the predefined macros from a Keil build configuration?

上下文:

我正在尝试使用 Keil 自动执行嵌入式开发中一些比较普通的任务。我想要的最终结果是在 Keil 项目中单击构建将 运行 一个预构建步骤,即 运行 通过 Uncrustify(源代码美化器)确保所有代码符合公司风格指南,以及 post-构建步骤,然后 运行 通过 pc-lint(静态代码分析器)对代码进行分析,以突出显示它可能发现的任何可能不安全的代码。我编写了一个 PC 实用程序,它在 .uvproj 文件中搜索 #define 宏、包含路径和文件路径,所有这些都是两个工具都需要的,然后修改 pre 和 post-build 用户命令来调用我的批处理文件,它将管理这两个步骤。 uncrustify 部分工作正常,lint 部分产生一些合理的消息,但信噪比不是很好。

我的问题:

Lint 不断生成似乎与 Keil 编译器知道但 Lint 不知道的宏相关的消息。我正试图找到一种方法来填补这一空白。我在 Keil 网站上找到了一个 table of predefined macros 文档,这似乎是一个好的开始,但我不想手动将它们复制到静态 .lnt 文件中,而是想找到一种获取最新信息的方法项目建成时的价值。这样,例如,“__ARMCC_VERSION”宏将在开发人员更新 his/her Keil 编译器时更新,而不是在我手动复制它时卡在某个时间点。

如果有人能直接回答我的问题,我会很高兴,但如果有人对我可以尝试的更直接的替代方法提出可行的建议,我同样会很高兴。非常感谢!

我假设您使用的是 Keil ARM 编译器。

来自Compiler User Guide

To list macros that are defined on the command line, predefined by the compiler, and found in header and source files, use --list_macros with a non-empty source file.

To list only macros predefined by the compiler and specified on the command line, use --list_macros with an empty source file.

编辑:

看来你的SDK也加了几个宏。

来自µVision User's Guide

The following control strings are added, depending on the use of MDK:

__UVISION_VERSION:

Major and minor version of µVision. For example: -D__UVISION_VERSION="520".

RTE:

Set when RTE is in use. For example: -D_RTE_.

__RTX:

Set when RTX Kernel has been selected in Options for Target - Target - Operation System. Not set when using RTE. For example: -D__RTX.

__MICORLIB:

Set when Use MicroLIB has been enabled in Options for Target - Target. For example: -D__MICROLIB.

__EVAL:

µVision runs in evaluation mode. License MDK-Lite. For example: -D__EVAL.

device header name:

Device header name.