在cmake3中指定临时构建文件路径

3

我正在Centos上使用cmake3(版本3.6.1)。在以前的CMake版本中,我可以使用-B选项指定构建目录:

cmake -GNinja -B build

有了这样,所有的临时文件,如CMakeCache.txt都存储在构建文件夹中。现在使用cmake3,我不再看到-B选项了。是否有不同的选项?


1
(cd build && cmake -Gninja ..)?- 但我认为-B没有被删除。 - spectras
在https://cmake.org/cmake/help/v3.13/manual/cmake.1.html中浏览版本似乎表明3.13之前的版本没有该选项,但更新版本有。 - jacob
缺失于 https://cmake.org/cmake/help/v3.6/manual/cmake.1.html - ssk
1个回答

1
在CMake 3.6.X命令行选项的文档中,确实没有列出-B选项:
cmake [<options>] (<path-to-source> | <path-to-existing-build>)
然而,这个功能仍然存在。你仍然可以使用-B指定构建目录的位置(当前目录是默认值)。这个选项以及-H用于指定源目录,是许多CMake版本中两个未记录的命令行选项(参见this答案)。
由于保留了支持-B选项的功能,并且仍然广泛使用,CMake在CMake 3.13中将其添加回文档中。最新的documentation描述了一直存在的-B行为。
cmake [<options>] -S <path-to-source> -B <path-to-build>

Uses <path-to-build> as the build tree and <path-to-source> as the source tree. The specified paths may be absolute or relative to the current working directory. The source tree must contain a CMakeLists.txt file. The build tree will be created automatically if it does not already exist. For example:

     $ cmake -S src -B build

我卡在了3.6.1。如果我尝试您的建议,即-S src -B build,我会得到以下错误信息:build" 似乎不包含 CMakeLists.txt。 - ssk
1
@ssk 我扩展了我的回答。使用 -S 选项指定源目录是新的,但未记录的 -H 选项也允许您指定源目录。这个 -H 选项应该在 CMake 3.6 中可用,并且实际上仍然可以在最新版本的 CMake(3.16)中使用。 - Kevin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接