How to understand the difference between the two command line parameters for cmake?

Describe the difference between these two commands:

C:\xxxxx> cmake -help

Usage

  $ cmake [options] <path-to-source>
  $ cmake [options] <path-to-existing-build>

      

Specify a source directory to (re) create a build system for it in the current working directory. Specify an existing build directory to generate your build system.

The last description does not give me how to use the first or the second.

Could you explain this to me?

+3


source to share


2 answers


When you use the built-in tree ( cmake .

) construct , there is no difference.

When you build outside of the tree, there is a difference.



Suppose your project is in ~/foo

and your current directory is~/foo/build

You need to run cmake ..

for the first build. But for subsequent reconfigurations, you can use cmake .

because there is already an assembly in there.

0


source


This command:

cmake [options] <path>

      

works like this:



  • if <path> is not a valid (that is, already configured) CMake build directory, it is assumed to contain CMakeList.txt

    . CMake will configure the current working directory as the build directory using the <path>/CMakeLists.txt

    source directory.
  • if <path> is a valid CMake build directory, the command reconfigures that directory using the original directory assigned when the build directory was first configured

So the general usage patterns are:

  • initial configuration:

    mkdir my-build-dir
    cd my-build-dir
    cmake [options] my-source-dir
    
          

  • subsequent (repeated) configurations:

    cmake [options] my-build-dir # current-work-dir is not important
    
          

  • alternative (initial) configuration using undocumented options:

    cmake -Hmy-source-dir -Bmy-build-dir [options] # cwd is not important
    
          

0


source







All Articles