Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cmake

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

like image 871
Eleno Avatar asked Jun 27 '15 16:06

Eleno


People also ask

What are Cmake options?

When CMake is first run in an empty build tree, it creates a CMakeCache. txt file and populates it with customizable settings for the project. This option may be used to specify a setting that takes priority over the project's default value. The option may be repeated for as many CACHE entries as desired.

What does Cmake B do?

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

How do I set Cmake options?

There are two different ways to configure with cmake ; one is to run cmake in a fresh directory passing some options on the command line, and the other is to run ccmake and use its editor to change options. For both, assume you are in a directory called debug and the IMP source is in a directory at ../imp .

What is in Cmake command?

The cmake command creates many files at your current working directory (CWD, the directory you ran the command from), and among them is a file called Makefile , which has rules about which files to compile/build/copy/write/whatever and how to do it.


2 Answers

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

like image 87
Akos Bannerth Avatar answered Sep 26 '22 02:09

Akos Bannerth


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.

like image 26
mloskot Avatar answered Sep 26 '22 02:09

mloskot