如何在CMake中为每个目标的构建输出生成单独的输出文件?

huangapple go评论60阅读模式
英文:

How can I generate separate output files for the build output of each target in CMake?

问题

CMake在处理大型项目时,会智能地并行构建各个目标。然而,所有目标的构建日志会混在stdout中打印到屏幕上,这可能会让理解构建失败变得困难。

是否有一种方法可以为项目中的每个目标生成构建日志文件?

build_target_name_0.logbuild_target_name_1.log 等。

英文:

When working with big CMake projects with many targets, CMake will intelligently build the targets in parallel. However, the build logs for all targets will just intermix in stdout getting printed to the screen. This can make understanding failures difficult.

Is there a way to generate a build log file for each target in the project?

i.e. build_target_name_0.log, build_target_name_1.log.

答案1

得分: 1

CMake仅根据您的CMake项目配置生成构建系统。编译源文件的顺序由构建系统根据CMake生成的构建系统配置文件确定。我不知道CMake是否有一个配置点,用于配置构建系统以满足您的需求。在运行构建时,您可以向构建工具命令传递与构建系统相关的参数。请参阅您的构建工具的文档。

一个“CMake支持的”解决方法是按目标顺序逐个构建,从依赖图/树中的“最低”目标(最依赖的)到最高目标(不依赖于其他目标,但依赖于其他目标)。任何合格的构建系统都会知道何时不需要重新构建目标,因此这种方式可以仅获取您构建的目标的输出。请参阅cmake --build--target参数。然后只需使用您的shell机制将输出重定向到文件。

英文:

CMake just generates the buildsystem based on your CMake project configuration. The order of compiling source files is determined by the buildsystem based on the buildsystem configuration files generated by CMake. I'm not aware of CMake having a configuration point that it uses to configure buildsystems to do what you are looking for. When you run the build, you can pass buildsystem-specific arguments to the build tool command. Consult your build tool's documentation.

One "CMake-supported" workaround would be to just build target-by-target, from the order of targets "lowest" in the dependency graph/tree (most depended upon), to those highest (not depended upon, but depends on other targets). Any decent buildsystem will know when a target doesn't need to be rebuilt, so this way, you can get output for just the target you build. See the --target argument of cmake --build. Then just use your shell's mechanism for piping output to a file.

huangapple
  • 本文由 发表于 2023年4月17日 23:15:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036676.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定