可以不在cmake中生成ALL_BUILD项目吗?

Is it possible not to generate ALL_BUILD project in cmake?

我不需要ALL_BUILD子项目,我可以避免生成它吗?谢谢

它对应于all make 目标,所以,不,你无法避免生成它。不过,您可以手动将其从解决方案中删除。

CMake Issue #16979: "ALL_BUILD target being generated":

The ALL_BUILD target corresponds to CMake's notion of the "all" target, equivalent to make all with makefile generators. This is different from "Build Solution" behavior due to idiosyncrasies in how the VS IDE deals with inter-vcxproj dependencies.

There is no way to suppress the ALL_BUILD target. It must exist for commands like cmake --build. to be able to build the "all" target by default.

所以你无法避免它——就像@arrowd 的回答一样——但是 CMake 中有一些东西会影响 usage/appearance(在 IDE 生成器上,比如 Visual Studio)其中:

  1. 当你激活全局USE_FOLDERS属性

     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
    

    通用目标 ALL_BUILDZERO_CHECKINSTALLPACKAGERUN_TESTS 将分组到 CMakePredefinedTargets 文件夹(或以全局 PREDEFINED_TARGETS_FOLDER 属性).

    中给出的名称为准

  2. 全局变量 CMAKE_SKIP_INSTALL_ALL_DEPENDENCYCMAKE_SKIP_PACKAGE_ALL_DEPENDENCY 会抑制 INSTALLPACKAGEALL_BUILD 目标自动生成的依赖关系.

  3. 全局 VS_STARTUP_PROJECT 属性 可用于将默认启动项目名称更改为 ALL_BUILD 或“第一个项目不在 sub-folder" 目标。

参考资料

  • What are ALL_BUILD and ZERO_CHECK and do I need them?
  • How to skip dependency on all for package target?