[CMake] Out-of-source build with QT_WRAP_UI

clinton at elemtech.com clinton at elemtech.com
Wed Jun 25 18:34:27 EDT 2008


I've written comments in between...

On Wednesday 25 June 2008 2:28:17 am Roy van Pelt wrote:
> Dear all,
>
> I'm trying to create the following situation, but so far I did not
> manage to do so with the examples I found on the Internet.
>
> I have:
>
> build_linux\
>   CMakeLists.txt
> src
>   ui
>     mainWindow.ui
>   main.cxx
>   main.h
> CMakeLists.cxx
>
> The root CMakeLists uses SUBDIR to run the CMakeLists for my Linux
> build. Now I want QT_WRAP_UI to generate the necessary header and source
> files. By default however it places them in the build directory?!
>
> How can I get the generated files to be generated in the ui directory?
>
> I include the current CMakeLists.txt for the linux build below.
>
> Thanks in advance.
>
> #==========================================================================
>== SET(EXECUTABLE_NAME bmrvis)
>
> SET(SRC_DIR ../src)
> SET(GUI_DIR ../src/ui)
>
> #--------------------------------------------------------------------------
>----- # Find Qt package library and include files.
> #--------------------------------------------------------------------------
>----- SET(DESIRED_QT_VERSION  ${VTK_DESIRED_QT_VERSION}  CACHE FILEPATH "")
Why set the DESIRED_QT_VERSION?  You probably want to remove that.

>
> FIND_PACKAGE(Qt4 REQUIRED)
> IF(QT_USE_FILE)
>         INCLUDE(${QT_USE_FILE})
> ELSE(QT_USE_FILE)
>         SET(QT_LIBRARIES ${QT_QT_LIBRARY})

This else case doesn't make sense when using Qt4, as it always has a use file, 
and QT_QT_LIBRARY is undefined.

> ENDIF(QT_USE_FILE)
>
> #--------------------------------------------------------------------------
>----- # Build list of class files.
> #--------------------------------------------------------------------------
>----- SET(CLASSES
>   main
> )
>
> FOREACH(class ${CLASSES})
>   SET(SOURCES ${SRC_DIR}/${class}.cxx ${SRC_DIR}/${class}.h)
> ENDFOREACH(class)
>
> #--------------------------------------------------------------------------
>----- # Build list of ui files.
> #--------------------------------------------------------------------------
>----- SET(GUI_FILES
>   QMainWindow
> )
>
> FOREACH(guifile ${GUI_FILES})
>   SET(GUI ${GUI_DIR}/${guifile}.ui)
> ENDFOREACH(guifile)
>
> IF (QT_WRAP_UI)
>   QT_WRAP_UI(bmrvis_gui_lib GUI_HEADERS GUI_SOURCES ${GUI} )
> ENDIF (QT_WRAP_UI)

When using Qt4 it should instead be
QT4_WRAP_UI(GUI_HEADERS ${GUI} )

>
> #--------------------------------------------------------------------------
>----- # Specify that given list of source files is part of final library.
> #--------------------------------------------------------------------------
>----- ADD_EXECUTABLE(${EXECUTABLE_NAME} ${SOURCES} ${GUI_SOURCES} )

You need to add ${GUI_HEADERS} and remove ${GUI_SOURCES}

Clint


More information about the CMake mailing list