# Select variable depending on build variant

**URL:** https://discourse.cmake.org/t/select-variable-depending-on-build-variant/6627
**Category:** Code
**Created:** [October 7, 2022, 3:22pm UTC](https://discourse.cmake.org/t/select-variable-depending-on-build-variant/6627 "2022-10-07T15:22:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Glad](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@Glad](https://discourse.cmake.org/u/Glad)
#### Post date: [October 7, 2022, 3:22pm UTC](https://discourse.cmake.org/t/select-variable-depending-on-build-variant/6627/1 "2022-10-07T15:22:16Z")

</div>

Hi,

I have a CMake file which has the following 3 lines, among many others:

```auto
set(LIBS_TYPE "_dbg")
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
target_link_libraries(${APP_NAME} PUBLIC ${STATIC_libs}/my_lib${LIBS_TYPE}.a)

```

The idea is to have Cmake invoke the debug or release libs depending on the build variant from my IDE (VSCode);

For example, in debug mode, we should call the library `my_lib_dbg.a,` whereas the release mode will call `my_lib.a`.

It is a manual process right now, I have to modify `LIBS_TYPE` by hand.

Is there a way to make it automatically?

Thanks

---

<div class="post-metadata">

### Author: ![Fab](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/51bf81/32.png) [@Fab](https://discourse.cmake.org/u/Fab)
#### Post date: [October 7, 2022, 5:40pm UTC](https://discourse.cmake.org/t/select-variable-depending-on-build-variant/6627/2 "2022-10-07T17:40:32Z")

</div>

> [@Glad](#):
>
> `set(LIBS_TYPE "_dbg")`

Try something like this:  
` set(LIBS_TYPE “MyLibTypePrefixIfAny$<$<CONFIG:Debug>:_dbg>”)`  
Also note that you may not even need a LIB\_TYPE variable now and just name your lib with the $\<$CONFIG:Debug:\_dbg\> addition directly.  
EDIT: missed the double $\<\> wrapping in my original answer, fixed.

---

<div class="post-metadata">

### Author: ![Glad](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@Glad](https://discourse.cmake.org/u/Glad)
#### Post date: [October 8, 2022, 11:31am UTC](https://discourse.cmake.org/t/select-variable-depending-on-build-variant/6627/3 "2022-10-08T11:31:30Z")

</div>

Thanks Fab 👍
