cmake add_subdirectory 仅在 cmake 命令行出现错误,但在 windows 上出现 cmake-gui 错误(在驱动器盘符的根目录下检出源代码)

cmake add_subdirectory error only with cmake command line but not cmake-gui on windows (with source checked out at root of a drive letter)

我正在研究使用 CMake 构建的 3dtk。您可以在此处找到它的 CMakeLists.txt:https://sourceforge.net/p/slam6d/code/HEAD/tree/trunk/CMakeLists.txt

在几个地方它使用了 add_subdirectory 指令并且从不提供第二个参数(binary_dir)。

在 linux 上调用 ccmake out-of-tree 或在 windows 上使用 cmake-gui 时,这似乎没有问题,因为在这两种情况下,项目配置成功。

但是当我在命令提示符下 运行 plain cmake on windows 时,我会得到几个这样的错误:

CMake Error at Z:/CMakeLists.txt:471 (add_subdirectory):
  add_subdirectory not given a binary directory but the given source
  directory "Z:/src/slam6d" is not a subdirectory of "Z:/". When specifying
  an out-of-tree source a binary directory must be explicitly specified.

我怀疑我只是缺少 cmake 命令的一个选项,但是哪个选项呢?

就像 Windows 上的 cmake-gui 一样,我为 Where to build the binaries 指定了与 where is the source code 不同的路径来进行树外构建,就像在 Linux 上使用 ccmake,其中我 运行 ccmake 在我源代码的子目录中 ccmake ..,我 运行ning cmake 在 Windows 从我源的子目录中。

那么 cmake-guiccmake 做了哪些 cmake 没有做的事情以及需要手动干预的地方?

编辑:找到解决方案后发现问题是我的源目录直接是一个windows盘符而不是一个的子目录。

原来这是cmake的一个bug。 Quoting 大卫·科尔:

Put your source in a sub-directory. CMake simply does not work at the root of a drive letter on Windows. CMakeLists.txt MUST be in at least one sub-directory underneath a root drive letter path.

还有一些关于此问题的公开错误报告:

查看 josch 提供的错误报告,CMake 似乎不会在不久的将来修复此问题。我在 android NDK 项目上使用 cmake 时遇到了这个问题。

我的解决方案是使用联结(我使用 windows 10),我无法将源文件夹移动到子目录。

要使用 mklink 命令创建连接(在 cmd.exe 中):

cd z:\
mklink /J MyProjectJp z:\

在探索器中,您会看到一个文件夹 z:\MyProjectJp,其视图与 z:\ 完全相同。现在要构建您的项目,请输入 z:\MyProjectJp.