# cmake build disregards CMAKE\_BUILD\_TYPE for the Visual Studio generator

**URL:** https://discourse.cmake.org/t/cmake-build-disregards-cmake-build-type-for-the-visual-studio-generator/4051
**Category:** Usage
**Tags:** comp:msvc, gen:vs
**Created:** [September 8, 2021, 8:01am UTC](https://discourse.cmake.org/t/cmake-build-disregards-cmake-build-type-for-the-visual-studio-generator/4051 "2021-09-08T08:01:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)
#### Post date: [September 8, 2021, 8:01am UTC](https://discourse.cmake.org/t/cmake-build-disregards-cmake-build-type-for-the-visual-studio-generator/4051/1 "2021-09-08T08:01:38Z")

</div>

I tried building via the command line interface:

```auto
cmake ../path_to_source -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release 
cmake --build .

```

But when I ran the built target I got some strange dll errors. II discovered that the built executable was the debug version of my application, even though I specified `-DCMAKE_BUILD_TYPE=Release`.

To actually build the release version of the executable I had to specify the config when triggering the build:

```auto
cmake --build . --config Release

```

The documentation for the build command do not mention this. Maybe it should be amended with this information:  
[https://cmake.org/cmake/help/latest/command/build\_command.html](https://cmake.org/cmake/help/latest/command/build_command.html)

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [September 8, 2021, 9:21am UTC](https://discourse.cmake.org/t/cmake-build-disregards-cmake-build-type-for-the-visual-studio-generator/4051/2 "2021-09-08T09:21:21Z")

</div>

I think the [documentation of `CMAKE_BUILD_TYPE`](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) already explains that behavior:

> Specifies the build type on single-configuration generators.

> This variable is only meaningful to single-configuration generators (such as [Makefile Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators) and [`Ninja`](https://cmake.org/cmake/help/latest/generator/Ninja.html#generator:Ninja)) i.e. those which choose a single configuration when CMake runs to generate a build tree as opposed to multi-configuration generators which offer selection of the build configuration within the generated build environment.

---

<div class="post-metadata">

### Author: ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)
#### Post date: [September 8, 2021, 11:26am UTC](https://discourse.cmake.org/t/cmake-build-disregards-cmake-build-type-for-the-visual-studio-generator/4051/3 "2021-09-08T11:26:43Z")

</div>

Maybe the documentation for the CMake build command should be amended with similar information as well. Maybe something along the lines of:

_“Note that multi-configuration generators will not use the `CMAKE_BUILD_TYPE` variable and hence default to a debug configuration unless another configuration is specified with the `--config` option.”_
