Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: How to use different ADD_EXECUTABLE for debug build?

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?

like image 895
Gili Avatar asked Dec 17 '22 07:12

Gili


1 Answers

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.

like image 77
Gili Avatar answered Mar 29 '23 23:03

Gili