gpt4 book ai didi

cmake:如何将目标从子目录导入到更高级别?

转载 作者:行者123 更新时间:2023-12-03 18:03:15 25 4
gpt4 key购买 nike

给定一个递归构建结构。如何将目标从较低级别导入到较高级别?
这是一个简化的示例:

顶级 CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
add_subdirectory(sub1)

sub1/CMakeLists.txt:
add_subdirectory(subdir)
add_executable(foo EXCLUDE_FROM_ALL
foo.cpp)

add_custom_target(both)
add_dependencies(both DEPENDS foo bar)

sub1/subdir/CMakeLists.txt:
add_executable(bar EXCLUDE_FROM_ALL
bar.cpp)

在顶层,所有目标都是可见的:
  • make foo - 构建 foo
  • 制作酒吧 - 制作酒吧
  • make both - 构建 foo 和 bar

  • 在底层(sub1/subdir)只有栏是可见的:
  • 制作酒吧 - 制作酒吧

  • 在中间层,只有 foo 作为目标可见:
  • make foo - 构建 foo
  • make both - 构建 foo 和 bar

  • 制作帮助显示:

    以下是此 Makefile 的一些有效目标:
    ...全部(如果未提供目标,则为默认值)
    ... 干净的
    ... 依靠
    ... edit_cache
    ...重建缓存
    ... 两个都
    ... foo
    ... foo.o
    ... foo.i
    ... foo.s

    如何在不将构建指令上移的情况下将 bar 添加到此列表中?

    最佳答案

    如果我改变

    add_dependencies(both DEPENDS foo bar)


    add_dependencies(both foo bar)

    我收到以下回复以在顶级文件夹中提供帮助:
    The following are some of the valid targets for this Makefile:
    ... all (the default if no target is provided)
    ... clean
    ... depend
    ... edit_cache
    ... rebuild_cache
    ... both
    ... foo
    ... bar

    看看文档:
    https://cmake.org/cmake/help/v3.3/command/add_dependencies.html

    关于cmake:如何将目标从子目录导入到更高级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35488501/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com