The develop environment is QT + Windows + C++. How to switch console in different build configuration? Could config expression be used in add_executable
to solve it? For example add_executable(main $<$<CONFIG:Debug>:WIN32> $<$<CONFIG:Release>:> main.cpp)
Asked
Active
Viewed 1,044 times
1

heLomaN
- 1,634
- 2
- 22
- 33
3 Answers
3
Below is what I use to achieve what you are looking for:
add_executable(<EXE_NAME> ...// sources) # note no WIN32
set_target_properties(
<EXE_NAME>
PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE"
LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
)
This will show a console in debug but not in release.

Developer Paul
- 1,502
- 2
- 13
- 18
2
if(WIN32)
set_target_properties(${PROJECT_NAME}
PROPERTIES
LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE"
LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:windows /ENTRY:mainCRTStartup"
)
endif(WIN32)
This work perfect, thanks

Eduardo Dantas
- 54
- 3
1
Here is an example that should work on Windows & Linux and uses the more specific target_link_options
if (WIN32)
# if config is debug set the variable to "/SUBSYSTEM:CONSOLE," else "/SUBSYSTEM:WINDOWS", append "/ENTRY:mainCRTStartup>" in any case
set(SUBSYSTEM_LINKER_OPTIONS "$<IF:$<CONFIG:Debug>,/SUBSYSTEM:CONSOLE,/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup>")
else()
# if config is not debug set the variable to "-mwindows" else nothing
set(SUBSYSTEM_LINKER_OPTIONS "$<IF:$<NOT:$<CONFIG:Debug>>,-mwindows,>")
endif()
target_link_options(TargetName PRIVATE ${SUBSYSTEM_LINKER_OPTIONS})

Elad Maimoni
- 3,703
- 3
- 20
- 37