I'd like to build my application such that debug mode is a console application and release mode is a Win32 application. According to the documentation I need to add WIN32
to add_executable
depending on whether I want a console application or not.
Because I'm using Visual Studio, I can't use CMAKE_BUILD_TYPE
(the generated project contains multiple configurations). How can I tell CMAKE to use WIN32
for release builds and omit it for debug builds?
Quoting http://www.cmake.org/Wiki/VSConfigSpecificSettings
if(WIN32)
set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(WindowApplicationExample PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
set_target_properties(WindowApplicationExample PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows")
set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:windows")
endif(WIN32)
UPDATE: This feature is broken in recent versions due to a bug. One workaround I've found is to specify "/SUBSYSTEM:windows" instead of "/SUBSYSTEM:WINDOWS". That seems to work for some reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With