# Controlling Visual Studio options from CMake

**URL:** <https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581>\
**Category:** Code\
**Created:** [September 29, 2022, 5:10pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581 "2022-09-29T17:10:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naum\_Derzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Naum\_Derzhi](https://discourse.cmake.org/u/Naum_Derzhi)\
**Post date:** [September 29, 2022, 5:10pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581/1 "2022-09-29T17:10:23Z")

</div>

When CMake generates VisualStudio solution and project for an application, the default setting for Project-\>Linker-\>System-\>Subsystem project parameter is Windows, but I need Console. Every time the solution is updated, I have to open the VS GUI and edit the project settings. Is there a way to write CMake code in such a way, that CMake will generate the solution with this option set to Console.

I tried the following lines:

add\_compile\_options(“/SUBSYSTEM:Console”)

add\_link\_options(“/SUBSYSTEM:Console”)

It made no difference.

Or, in general, how to use CMake for setting desired Visual Studio options?

Thank you

![image001.jpg](https://discourse.cmake.org/uploads/default/original/2X/d/dbddf1f80fec592c650b6234312c4ea48652de1e.jpeg)

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [September 29, 2022, 6:45pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581/2 "2022-09-29T18:45:25Z")

</div>

See [https://cmake.org/cmake/help/latest/prop\_tgt/WIN32\_EXECUTABLE.html#prop\_tgt:WIN32\_EXECUTABLE](https://cmake.org/cmake/help/latest/prop_tgt/WIN32_EXECUTABLE.html#prop_tgt:WIN32_EXECUTABLE)

This is also controlled by the WIN32 keyword of add\_executable()

---

<div class="post-metadata">

**Author:** ![Naum\_Derzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Naum\_Derzhi](https://discourse.cmake.org/u/Naum_Derzhi)\
**Post date:** [September 29, 2022, 6:51pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581/3 "2022-09-29T18:51:21Z")

</div>

Thank you, but this was not my question. I do not want to build a WinMain app – this is happening by default. I need a console application. It’s easy to achieve by editing the project properties using VS GUI. But I want it to be done by CMake when configuring and generating the solution.

Thanks again

![image001.jpg](https://discourse.cmake.org/uploads/default/original/2X/d/dbddf1f80fec592c650b6234312c4ea48652de1e.jpeg)

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [September 29, 2022, 7:00pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581/4 "2022-09-29T19:00:13Z")

</div>

CMake makes console applications by default rather than GUI applications. My guess is that your executable is having the `WIN32_EXECUTABLE` property set somewhere, either directly with `set_property()` or `set_target_properties()`, at `add_executable()` time with the `WIN32` keyword, or indirectly by the `CMAKE_WIN32_EXECUTABLE` variable. In all cases, `set_property(tgt PROPERTY WIN32_EXECUTABLE FALSE)` should fix it, though if it were me I’d find the place where it’s being initialized and fix that.

---

<div class="post-metadata">

**Author:** ![Naum\_Derzhi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/a587f6/32.png) [@Naum\_Derzhi](https://discourse.cmake.org/u/Naum_Derzhi)\
**Post date:** [September 29, 2022, 7:05pm UTC](https://discourse.cmake.org/t/controlling-visual-studio-options-from-cmake/6581/5 "2022-09-29T19:05:52Z")

</div>

Yes, this is it!!! Thank you very much

![~WRD0001.jpg](https://discourse.cmake.org/uploads/default/original/2X/5/52d5f1c08649212fe6768d2cacdcf8df711810d9.jpeg)

![image001.jpg](https://discourse.cmake.org/uploads/default/original/2X/d/dbddf1f80fec592c650b6234312c4ea48652de1e.jpeg)
