-H。选项对CMake意味着什么?

What does the `-H.` option means for CMake?

CMake上一个先前问题的答案显示了以下命令行:

1
cmake -H. -Bbuild -G"MSYS Makefiles"

-H.选项在这里执行什么任务? cmake --help表示-H打印帮助...

我正在使用CMake 3.2.3。


如链接的答案中所述,这是一个未记录的选项,但是查看源代码可以发现其效果:

cmake::SetArgs()中:

1
2
3
4
5
6
7
if(arg.find("-H",0) == 0)
  {    
  directoriesSet = true;
  std::string path = arg.substr(2);
  path = cmSystemTools::CollapseFullPath(path);
  cmSystemTools::ConvertToUnixSlashes(path);
  this->SetHomeDirectory(path);

最后一个调用SetHomeDirectory实际上设置了项目的源目录。 -B选项(也未记录)依次设置二进制目录。

如果未设置这些选项,则二进制目录将是执行cmake的当前文件夹,并且源目录可以作为位置参数给出(如果未找到,则源文件夹也将是当前工作目录)。


《漫游者CMake指南》解释了CMake 3.13选项中的旧版和新版:

  • -H

    This internal option is not documented but widely used by community.

    Has been replaced in 3.13 with the official source directory flag of -S.

  • -B

    Starting with CMake 3.13, -B is an officially supported flag,
    can handle spaces correctly and can be used independently of the -S or -H options.