# binary tree

**URL:** https://discourse.cmake.org/t/binary-tree/5009
**Category:** Usage
**Tags:** os:windows, gen:ninja
**Created:** [February 15, 2022, 7:16am UTC](https://discourse.cmake.org/t/binary-tree/5009 "2022-02-15T07:16:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [February 15, 2022, 7:16am UTC](https://discourse.cmake.org/t/binary-tree/5009/1 "2022-02-15T07:16:37Z")

</div>

[https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#build-a-project](https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#build-a-project)  
What is the already-generated project binary tree?

Here is the introduction for source tree and build tree  
[https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#introduction-to-cmake-buildsystems](https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#introduction-to-cmake-buildsystems)

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [February 15, 2022, 7:53am UTC](https://discourse.cmake.org/t/binary-tree/5009/2 "2022-02-15T07:53:32Z")

</div>

If you just use the `cmake` command, the configuration and generation are all in one step and you don’t have to think about it.  
cmake-gui allows to separate those two and configure project without generating the build system files (makefiles, ninja.build, etc). You cannot build until the generate step is done.

---

<div class="post-metadata">

### Author: ![hex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hex/32/363_2.png) [@hex](https://discourse.cmake.org/u/hex)
#### Post date: [February 15, 2022, 5:15pm UTC](https://discourse.cmake.org/t/binary-tree/5009/3 "2022-02-15T17:15:13Z")

</div>

CMake is typically used in project mode hence the emphasis on _project_. This command will fail if you haven’t generated a CMake project first, so already-generated is a pre-condition. To use CMake you need 2 commands:

```auto
# the project binary directory
cd build
# Generate a Project Buildsystem
cmake ..
# Build a Project
cmake --build .

```

The binary directory is any directory that you chose for CMake to use when generating the project. The binary directory is also known as build tree. Personally, i would avoid calling it a binary tree since that is more commonly known as a data structure.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [February 16, 2022, 2:40am UTC](https://discourse.cmake.org/t/binary-tree/5009/4 "2022-02-16T02:40:28Z")

</div>

How can I know the build tool for these commands on windows?  
I expect `Visual Studio 16 2019` Generators

```auto
# the project binary directory
cd build
# Generate a Project Buildsystem
cmake ..
# Build a Project
cmake --build .

```

REF  
[https://cmake.org/cmake/help/v3.23/manual/cmake-generators.7.html#ide-build-tool-generators](https://cmake.org/cmake/help/v3.23/manual/cmake-generators.7.html#ide-build-tool-generators)

---

<div class="post-metadata">

### Author: ![hex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hex/32/363_2.png) [@hex](https://discourse.cmake.org/u/hex)
#### Post date: [February 16, 2022, 11:08am UTC](https://discourse.cmake.org/t/binary-tree/5009/5 "2022-02-16T11:08:27Z")

</div>

The generators available for CMake depend on your machine. For example, Visual Studio must be installed in order to use it with CMake. You can see a list of available generators with

```sh
cmake --help

```

> [@alice](#):
>
> I expect `Visual Studio 16 2019` Generators

You would expect the one marked default in the command above. You can choose a different one when you generate the project buildsystem (see [available options](https://cmake.org/cmake/help/v3.23/manual/cmake.1.html)).

> [@alice](#):
>
> How can I know the build tool for these commands on windows?

I assume you are asking how to check which one is used. Perhaps the easiest way to do that is launching `cmake-gui`:

```sh
cd build
cmake ..
cmake-gui .

```

The GUI application shows `Current Generator: <your selected generator>`

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [February 16, 2022, 11:36am UTC](https://discourse.cmake.org/t/binary-tree/5009/6 "2022-02-16T11:36:33Z")

</div>

Q1

```auto
cmake -G "Visual Studio 16 2019"

```

Because I assign the `-G` to “Visual Studio 16 2019”, the build tool will be the “Visual Studio 16 2019” ?

Q2  
Which step assigns build tool ( Generate a Project or Build a Project)?

```auto
# the project binary directory
cd build
# Generate a Project Buildsystem
cmake .. -G "Visual Studio 16 2019"
# Build a Project
cmake --build . [-- <build-tool-options>]

```

Q3  
How to use the parameter `[-- <build-tool-options>]`?  
[https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#build-a-project](https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#build-a-project)

---

<div class="post-metadata">

### Author: ![hex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hex/32/363_2.png) [@hex](https://discourse.cmake.org/u/hex)
#### Post date: [February 16, 2022, 12:19pm UTC](https://discourse.cmake.org/t/binary-tree/5009/7 "2022-02-16T12:19:12Z")

</div>

Q1: Some generators are for build systems but yes, in a more general way we are generating build tools. I would say that “Visual Studio” is the build tool here. The suffix are version details. Don’t throw stones at me if i’m wrong.

Q2:

> [@hex](#):
>
> You can choose a different one when you generate the project buildsystem

Q3: This is out of scope for CMake. Everything following `--` CMake doesn’t understand, and passes it along to said tool. Any build tool generated by CMake may have options that you want to use.

Here is a real world example for `cmake --build <dir> -- <build-tool-options>`:

```sh
cmake \
    -G "Unix Makefiles" \
    --build "${BINARY_DIR}" \
    -- --no-print-directory

```

`--no-print-directory` is not a CMake option. It is passed on to Make by CMake. You have to consult the documentation of your build tool for available options.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [February 17, 2022, 8:15am UTC](https://discourse.cmake.org/t/binary-tree/5009/9 "2022-02-17T08:15:46Z")

</div>

Do you have the sample command for Q3?

---

<div class="post-metadata">

### Author: ![hex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hex/32/363_2.png) [@hex](https://discourse.cmake.org/u/hex)
#### Post date: [February 17, 2022, 11:02am UTC](https://discourse.cmake.org/t/binary-tree/5009/10 "2022-02-17T11:02:22Z")

</div>

yes, i edited my previous post.
