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
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.
Dunno if this bug has been fixed in CMake yet. I'm using VC++ 2010 express and CMake v2.8.10.1 (which is currently the latest release) and I'm still having the exact same problem.
A working solution was provided here: modify your source code (e.g. main.cpp/main.c) by adding:
Alternatively, you could add the linker flag "/SUBSYSTEM:WINDOWS" to the release-mode build. I'm using this definition which seems to work:
Use the entry-point setting in order to avoid linker errors in case you've defined: