[Cmake] WinMain

Filipe Sousa filipe.gr.sousa at alunos.ipb.pt
Tue Jun 8 13:32:34 EDT 2004


Hi Nick!

On Tuesday 08 June 2004 15:37, Nick Arini wrote:
> Filipe, Julien, William and Andy,
>
> Thanks for all your suggestions. I finally got a combination that works
> for me. I am posting it here (and not to Qt-interest) because all the
> additions are to the CMakeLists.txt file and did not require any changes
> to the source code.
>
> Filipe was right that I didnt need to write a WinMain and use nasty
> #ifdefs. My main program is still calling main() and is unchanged.
>
> When using Qt on Windows it seems you need to link to the qtmain.lib
> library. To be safe I also included the lines that Julien suggested. The
> important bits of my CMakeLists.txt file now look like below.
>
> This still works just fine for Linux and GCC ;->.
>
> Best regards,
>
> Nick
>
>
> <begin code>
>
>
> #
> # Find QT (Obviously)
> #
> INCLUDE (${CMAKE_ROOT}/Modules/FindQt.cmake)

It's easier to do FIND_PACKAGE(Qt) instead of INCLUDE

>
> INCLUDE_DIRECTORIES(
> ${QT_INCLUDE_DIR}
> ${QT_INCLUDE_PATH}
> )
>
> LINK_LIBRARIES (
> ${QT_QT_LIBRARY}
> )

Here is the problem, you shouldn't use QT_QT_LIBRARY, you have to use 
QT_LIBRARIES both on windows and linux that has qt.lib and qtmain.lib.

> # Only include the qtmain lib if we are on the windows platform
> IF(WIN32)
> LINK_LIBRARIES(
> ${QT_QTMAIN_LIBRARY}
> )
> ENDIF(WIN32)
>
> IF(WIN32)
> ADD_DEFINITIONS(-DQT_DLL)
> ENDIF(WIN32)
>
>
> SET(VIEWER_SRCS
> MainWindow.cpp
> MainWindow.h
> main.cpp
> )
>
>
> SET(VIEWER_MOC_SRCS
> MainWindow.h
> )
>
> IF(QT_WRAP_CPP)
>   QT_WRAP_CPP(viewer VIEWER_SRCS VIEWER_MOC_SRCS)
> ENDIF(QT_WRAP_CPP)
>
>
> # Julien's suggested lines
> IF(WIN32)
> SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows")
>
> ENDIF(WIN32)
I never had to use "/subsystem:windows" I thinks this is added with WIN32 on 
ADD_EXECUTABLE
>
> ADD_EXECUTABLE(viewer WIN32 VIEWER_SRCS)
>
>
> <end code>
>
>
>
>
>
>
> Filipe Sousa <filipe.gr.sousa at alunos.ipb.pt>
> Sent by: cmake-bounces at www.cmake.org
> 07/06/2004 19:16
>
>
>         To:     cmake at www.cmake.org
>         cc:
>         Subject:        Re: [Cmake] WinMain
>
>
> There is no need to write WinMain. The library qtmain.lib has the WinMain
> that
> calls the user's main() function.
>
> On Monday 07 June 2004 16:07, William A. Hoffman wrote:
> > This is really a QT question.   You should look at some QT examples and
> > figure out how QT deals with WinMain.   If it has a WinMain, then use
> > the WIN32 option in ADD_EXECUTABLE:
> > ADD_EXECUTABLE(viewer WIN32 VIEWER_SRCS)
> > If it uses main, then leave out the WIN32 option.
> >
> > -Bill
>
> -- Filipe Sousa
>
> _______________________________________________
> Cmake mailing list
> Cmake at www.cmake.org
> http://www.cmake.org/mailman/listinfo/cmake


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://public.kitware.com/pipermail/cmake/attachments/20040608/cafe1668/attachment.pgp


More information about the Cmake mailing list