[Cmake] WinMain

Nick Arini nick.arini at amersham.com
Tue Jun 8 10:37:00 EDT 2004


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)

INCLUDE_DIRECTORIES(
${QT_INCLUDE_DIR}
${QT_INCLUDE_PATH}
)

LINK_LIBRARIES (
${QT_QT_LIBRARY}
)

# 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)


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 --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20040608/07707c56/attachment.htm


More information about the Cmake mailing list