Until yesterday I used Visual Studio 2008 and CMake (in combination with CPack) to build my project under Windows - that worked fine. But now I switched to the 2010 edition and ran into a (an old) problem: The loved background console (Because Windows thinks we have a fancy console application):
I have a CMake decision to avoid this window:
if(MSVC)
target_link_libraries(client window core ${QT_QTMAIN_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
set_target_properties(client PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
else()
target_link_libraries(client window core ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
endif()
This works for Visual Studio 2008, but not for 2010 (The /SUBSYSTEM is useless). So my question is: Does anyone have experience with this or solved it in CMake ? I don't want to change my main function to WinMain (Have the same codebase for Unix/Linux/OS X and Windows) or change the SUBSYSTEM settings in Visual Studio (That's not the idea behind CMake)
So after a cup of coffee I came to the following solution. Debug and Release build don't open a background console. Take a look at the WIN32 tag and the LINK_FLAG for Debug/Release/RelWithDebugInfo:
if(MSVC)
add_executable(client WIN32 ${SRC_CLIENT} ${HDR_UI_CLIENT} ${HDR_RSC_CLIENT})
target_link_libraries(client server ${QT_QTMAIN_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
set_target_properties(client PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
set_target_properties(client PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS")
set_target_properties(client PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
set_target_properties(client PROPERTIES RELWITHDEBINFO "/SUBSYSTEM:WINDOWS")
set_target_properties(client PROPERTIES MINSIZEREL "/SUBSYSTEM:WINDOWS")
else()
add_executable(client ${SRC_CLIENT} ${HDR_UI_CLIENT} ${HDR_RSC_CLIENT})
target_link_libraries(client server ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
endif()
If you use a modern version of CMake (2.8.11 or later), the ${QT_QTMAIN_LIBRARY} library will automatically be linked in for WIN32 executables, and not otherwise, if you use the IMPORTED targets.
http://www.cmake.org/cmake/help/git-master/module/FindQt4.html
You should not need to add the /subsystem yourself at all. That's what WIN32 does. If you can produce a minimal testcase, it's a bug.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.