给出了一种可重复的构建结构。如何将目标从较低级别导入较高级别? 这是一个简化的例子:
toplevel 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 /子目录/的CMakeLists.txt :
add_executable(bar EXCLUDE_FROM_ALL
bar.cpp)
在顶层,所有目标都可见:
在底层(sub1 / subdir),只有 bar 可见:
在中间级别,只有 foo 可见为目标:
提供帮助显示:
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 ... foo.o ... foo.i ... foo.s
如何在不将构建说明移到某个级别的情况下将 bar 添加到此列表中?
答案 0 :(得分:-1)
如果我改变
add_dependencies(both DEPENDS foo bar)
到
add_dependencies(both foo bar)
我在顶层文件夹中得到以下对 make help 的回复:
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