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

Cmake

Cmake Problem Overview


[This answer][1] to a former question on CMake shows this command line:

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

What task does the -H. option perform here? cmake --help says that -H prints the help...

I am using CMake 3.2.3.

[1]: https://stackoverflow.com/a/11144109/370132 "This answer"

Cmake Solutions


Solution 1 - Cmake

As mentioned in the linked answer, it is an undocumented option, but looking at the source code reveals its effect:

In cmake::SetArgs():

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

The last call, SetHomeDirectory actually sets the source directory for the project. The -B option (also undocumented) in turn sets the binary directory.

If these options are not set, the binary directory will be the current folder where cmake is executed, and the source directory can be given as a positional argument (if not found, the source folder will also be the current working directory).

Solution 2 - Cmake

The Hitchhiker’s Guide to the CMake explains both, the legacy and new in CMake 3.13 options:

  • -H

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

    and

    > 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElenoView Question on Stackoverflow
Solution 1 - CmakeAkos BannerthView Answer on Stackoverflow
Solution 2 - CmakemloskotView Answer on Stackoverflow