# How to add different target types for different configuration\_types for Visual Studio generator?

**URL:** <https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860>\
**Category:** Code\
**Created:** [June 14, 2022, 5:53am UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860 "2022-06-14T05:53:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Revbrte](https://discourse.cmake.org/user_avatar/discourse.cmake.org/revbrte/32/2498_2.png) [@Revbrte](https://discourse.cmake.org/u/Revbrte)\
**Post date:** [June 14, 2022, 5:53am UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860/1 "2022-06-14T05:53:18Z")

</div>

How to add different target\_types for configuration\_types,  
eq:Release - Executable  
AA\_Release(custom\_config) - Static\_library  
How to configure so that when we open the solution file in visual studio, in properties we should be able to see the correct target types for the different configuration\_types?

---

<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:** [June 14, 2022, 11:47am UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860/2 "2022-06-14T11:47:52Z")

</div>

Configurations are mostly about flag selection. Target types should not change between configurations.

---

<div class="post-metadata">

**Author:** ![Revbrte](https://discourse.cmake.org/user_avatar/discourse.cmake.org/revbrte/32/2498_2.png) [@Revbrte](https://discourse.cmake.org/u/Revbrte)\
**Post date:** [June 15, 2022, 5:26am UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860/3 "2022-06-15T05:26:20Z")

</div>

Thanks Ben, but if I have such a requirement is there any workaround to fix it?  
Right now I am following the steps as below:

1. Configure using command : cmake -H. -B\_builds “-DCMAKE\_BUILD\_TYPE=Debug” -G “Visual Studio 14 2015” -A Win32
2. Conditions like this:if("${CMAKE\_BUILD\_TYPE}" STREQUAL “Debug” )  
and add the required target\_type  
This works but the problem is when i open the solution file in Visual Studio The target type(exe or dll) of that project for the Debug will be correct. But when i choose Release/ any other custom config from the Visual Studio drop down it wont be correct.

---

<div class="post-metadata">

**Author:** ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)\
**Post date:** [June 15, 2022, 5:40am UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860/4 "2022-06-15T05:40:38Z")

</div>

There is no way to do this. Some generators are “multi-config”, meaning that the build configuration is specified at _build time_, not at CMake configure time. This is what generator expressions are for. But as far as I know, it is not possible to conditionalize target types using generator expressions.

---

<div class="post-metadata">

**Author:** ![Revbrte](https://discourse.cmake.org/user_avatar/discourse.cmake.org/revbrte/32/2498_2.png) [@Revbrte](https://discourse.cmake.org/u/Revbrte)\
**Post date:** [June 16, 2022, 3:22pm UTC](https://discourse.cmake.org/t/how-to-add-different-target-types-for-different-configuration-types-for-visual-studio-generator/5860/5 "2022-06-16T15:22:33Z")

</div>

Thanks Ben
