Sunday, April 3, 2022

[SOLVED] How to enable console window in Debug mode and disable in Release mode with QT & CMake?

Issue

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)


Solution

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.



Answered By - Developer Paul
Answer Checked By - Robin (WPSolving Admin)