Controlling Visual Studio options from CMake

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:



It made no difference.

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

Thank you



This is also controlled by the WIN32 keyword of add_executable()

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


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.

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