# repeat variable

**URL:** https://discourse.cmake.org/t/repeat-variable/5437
**Category:** Usage
**Tags:** os:windows
**Created:** [April 11, 2022, 11:09am UTC](https://discourse.cmake.org/t/repeat-variable/5437 "2022-04-11T11:09:38Z")
**Posts on this page:** 5
**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: [April 11, 2022, 11:09am UTC](https://discourse.cmake.org/t/repeat-variable/5437/1 "2022-04-11T11:09:38Z")

</div>

Is it a good method for declare twice set build\_type?

```auto
set build_type=release
cmake -Dbuild-type=%build_type%

set build_type=debug
cmake -Dbuild-type=%build_type%

```

Because c++ only declare 1 times.

```auto
int a=0;
dosomething;

a=2;
dosomething;

```

---

<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: [April 12, 2022, 12:02pm UTC](https://discourse.cmake.org/t/repeat-variable/5437/2 "2022-04-12T12:02:02Z")

</div>

This will configure two CMake build trees in the same place. Basically, the `build_type=release` gets overwritten with `build_type=debug` in the code you’ve shown.

---

<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: [April 13, 2022, 6:04am UTC](https://discourse.cmake.org/t/repeat-variable/5437/3 "2022-04-13T06:04:16Z")

</div>

I want to build release and debug version.  
I rewrite the camke

```auto
set build_type=release
cmake -B build-release -Dbuild-type=%build_type% -Dprefix_path=../%build_type%

set build_type=debug
cmake -B build-debug -Dbuild-type=%build_type% -Dprefix_path=../%build_type%

```

---

<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: [April 13, 2022, 8:52pm UTC](https://discourse.cmake.org/t/repeat-variable/5437/4 "2022-04-13T20:52:02Z")

</div>

That would work because there are two different build directories.

---

<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: [April 14, 2022, 6:31am UTC](https://discourse.cmake.org/t/repeat-variable/5437/5 "2022-04-14T06:31:07Z")

</div>

Thanks
