我如何使用cmake --build建立多个目标 [英] How can I build multiple targets using cmake --build
问题描述
我有一个CMake构建,其中包含许多不同的目标 A
, B
, C
等。
外部应用程序负责构建,并且当前通过调用
I have a CMake build with a bunch of different targets A
, B
, C
, etc.
An external application is tasked with building, and currently does so by calling
cmake --build .
但是,这会构建 all 个目标,有时我只想构建一个子集,例如 A
和 B
,但不是 C
。
-target
标志只能给出一次,并且只能接受一个目标。
However, this builds all targets, and sometimes I only want to build a subset, like A
and B
but not C
.
The --target
flag can only be given once, and only accepts a single target.
我想我可以让CMake生成适当的Makefile,然后显式调用 make AB
,但这带走了 cmake --build
与构建系统无关。
I guess I could let CMake generate the appropriate Makefile, and then call make A B
explicitly, but that takes away the nice thing about cmake --build
being build system agnostic.
是否有解决此问题的好方法?
Is there a nice way to solve this?
推荐答案
CMake版本3.15添加了对此功能的支持。只需在命令行上列出所有目标,如下所示:
CMake version 3.15 added support for this feature. Simply list all targets on the command line as follows:
cmake --build . --target Library1 Library2
这篇关于我如何使用cmake --build建立多个目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!