CMAKE添加子目录,它不是真实目录上的子目录 [英] CMAKE add sub-directory which is not sub-directory on real directory

查看:2236
本文介绍了CMAKE添加子目录,它不是真实目录上的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在cmake中包含同级目录作为子目录?

Is It possible to include sibling directory as Sub-Directory inside cmake ?

A 
  CMakeLists.txt

B
  CMakeLists.txt

且B包含A作为子目录?

and B includes A as sub-directory ?

推荐答案

也许不推荐...

您可以使用add_subdirectory命令的双参数形式添加任何您想要作为sub目录的目录:

You can use the two-argument form of the add_subdirectory command to add any directory you want as a "sub" directory:

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../A ${CMAKE_CURRENT_BINARY_DIR}/A)

双参数形式的第二个参数指定将添加子目录的二进制目录放在哪里。

The second argument of the two-argument form specifies where to put the binary directory for the added subdirectory.

你只需要小心,没有另一个真正的子目录B也被命名为A,也是add_subdirectory的...因为如果你这样做,这将是一个错误,因为CMake不能有两个不同的源目录映射到同一个构建目录。

You just have to be careful that there's not also another real sub-directory of B that is also named "A" and that is also add_subdirectory'd... Because if you do, then that would be an error, as CMake cannot have two different source directories mapping into the same build directory.

这篇关于CMAKE添加子目录,它不是真实目录上的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆