# cmake -B parameter

**URL:** https://discourse.cmake.org/t/cmake-b-parameter/5012
**Category:** Usage
**Tags:** os:windows
**Created:** [February 15, 2022, 11:06am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012 "2022-02-15T11:06:13Z")
**Posts on this page:** 13
**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, 11:06am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/1 "2022-02-15T11:06:13Z")

</div>

If I have a project sample

```auto
../sample/
├── build
├── CMakeLists.txt
├── main.cpp
└── release

```

Is the two command the same thing?

```auto
cd sample\build
cmake -S ..\ 

```

```auto
cd sample
cmake -S .\ -B build

```

ref:  
[cmake --install](https://cmake.org/cmake/help/v3.23/manual/cmake.1.html#generate-a-project-buildsystem)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 15, 2022, 2:17pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/2 "2022-02-15T14:17:21Z")

</div>

They look equivalent to me.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 15, 2022, 2:52pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/3 "2022-02-15T14:52:46Z")

</div>

-S stands for [CMAKE\_SOURCE\_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_SOURCE_DIR.html?highlight=cmake_source_dir)

-B stands for [CMAKE\_BINARY\_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html#variable:CMAKE_BINARY_DIR)

If you don’t specify -S / -B they are implied to be your current working directory.

So yes the 2 commands shown are equivalent

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 15, 2022, 8:57pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/4 "2022-02-15T20:57:01Z")

</div>

The only thing that comes to mind for me is that `-B` will create the build directory for you if it doesn’t exist.

---

<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:50am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/5 "2022-02-16T02:50:01Z")

</div>

In fact, the two commands will generate different size file or additional file.  
Is it reasonable?

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 16, 2022, 2:38pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/6 "2022-02-16T14:38:09Z")

</div>

> [@alice](#):
>
> In fact, the two commands will generate different size file or additional file.  
> Is it reasonable?

I’m not sure what you are referring to.

---

<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:09am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/7 "2022-02-17T08:09:20Z")

</div>

Here is the sample [https://github.com/fmtlib/fmt](https://github.com/fmtlib/fmt)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 17, 2022, 12:44pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/8 "2022-02-17T12:44:21Z")

</div>

Sure, but what, exactly, are you referring to by:

> [@alice](#):
>
> the two commands will generate different size file or additional file.

---

<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 18, 2022, 3:30am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/9 "2022-02-18T03:30:39Z")

</div>

method1

```auto
cd sample\build
cmake -S ..\ 
cmake --build xxx
cmake --install xxx

```

method1 result  
 ![image](https://discourse.cmake.org/uploads/default/original/2X/9/9415df2cc8158ba9acfd0d203f2192bc62e040e9.png)

method2

```auto
cd sample
cmake -S .\ -B build
cmake --build xxx
cmake --install xxx

```

method2 result  
 ![image](https://discourse.cmake.org/uploads/default/original/2X/0/0caa155a9055e03c104fdcfe714d18e622c0bcf8.png)

Are the two methods same for install it?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 18, 2022, 12:55pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/10 "2022-02-18T12:55:11Z")

</div>

OK, so the vcxproj files look to be different sizes (though at this resolution, there could be small diffs in many of these files). But are they different in any material way?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 18, 2022, 9:49pm UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/11 "2022-02-18T21:49:32Z")

</div>

It looks like testing wasn’t enabled for method 1. It is missing some of the files that we see with method 2 (e.g. `RUN_TESTS.vcxproj*` and `CTestTestfile.cmake`). I have no explanation, just making an observation.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 19, 2022, 12:35am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/12 "2022-02-19T00:35:14Z")

</div>

That feels like one had `ENABLE_TESTING=ON` (or `OFF`. That could certainly increase the file sizes as well.

---

<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 21, 2022, 6:48am UTC](https://discourse.cmake.org/t/cmake-b-parameter/5012/13 "2022-02-21T06:48:53Z")

</div>

ENABLE\_TESTING=ON no use with command.

Thanks for your help.
