[CMake] Qt4
Filipe Sousa
filipe at ipb.pt
Thu Jul 21 05:34:14 EDT 2005
On Thursday 21 July 2005 08:18, John Biddiscombe wrote:
> For people searching the archives, I am happy using Qt4 now, I've taken
> Filipe's snippets and created these macros in my CMakeLists file. Two
> macro's follow, then further below, the code I use when adding the
> sources to the build. I'll probably tweak the macros to create a list
> instead of doing them one at a time (but since I only have a couple of
SET(source_ext "cxx") <-- this should be global, I dislike the ".cxx"
extension, I'm used to ".cc"
MACRO(WRAP_QT_CPP result)
FOREACH(header ${ARGN})
GET_FILENAME_COMPONENT(basename ${header} NAME_WE)
SET(moc_file ${CMAKE_CURRENT_BINARY_DIR}/${basename}.moc.${source_ext})
#SET(moc_file ${CMAKE_CURRENT_BINARY_DIR}/moc_${basename}.${source_ext})
# -D flags
GET_DIRECTORY_PROPERTY(flags DEFINITIONS)
SEPARATE_ARGUMENTS(flags)
# -I flags
GET_DIRECTORY_PROPERTY(includes INCLUDE_DIRECTORIES)
FOREACH(inc ${includes})
SET(flags ${flags} ${CMAKE_INCLUDE_FLAG_CXX}${inc})
ENDFOREACH(inc)
ADD_CUSTOM_COMMAND(
OUTPUT ${moc_file}
COMMAND ${QT_MOC_EXECUTABLE}
ARGS ${flags} ${header} -o ${moc_file}
DEPENDS ${QT_MOC_EXECUTABLE} ${header}
COMMENT "Qt Wrap Files"
)
SET(${result} ${${result}} ${moc_file})
ENDFOREACH(header)
ENDMACRO(WRAP_QT_CPP)
This should handle a list of header files
WRAP_QT_CPP(moc_sources foo.h goo.h bar.h)
now you can add ${moc_sources} to ADD_EXECUTABLE or ADD_LIBRARY
Notice that you need to pass -D and -I compiler flags to moc. Without that I
couldn't compile examples/tools/plugandpaint and
examples/tools/plugandpaintplugins
> files in the project so far...), and remove the extension param since
> it's always the same,
>
> Many thanks for help. I like these macros more than the old cmake qt
> wrap commands, because I know exactly what they're doing. I am having no
> trouble with cmake regenerating files when requred, when I modify the ui
> file etc, all is regenerated as expected.
>
> Note that a variable is returned from the macro with a value set. (This
> feature seems to be flakey, so any improvements/suggestions welcome)
QT_WRAP_CPP is a command and does the same.
> #-----------------------------------------------
> # Macros for generating Qt wrapped files
> #-----------------------------------------------
> MACRO(WRAP_QT_CPP moc_file header source_ext)
> GET_FILENAME_COMPONENT(basename ${header} NAME_WE)
> GET_FILENAME_COMPONENT(path ${header} PATH)
> SET(${moc_file} ${path}/${basename}.moc.${source_ext})
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${${moc_file}}
> COMMAND ${QT_MOC_EXECUTABLE}
> ARGS ${header} -o ${${moc_file}}
> DEPENDS ${QT_MOC_EXECUTABLE} ${header}
> COMMENT "Qt Wrap Files"
> )
> ENDMACRO(WRAP_QT_CPP)
>
> MACRO(WRAP_QT_UI ui_header ui_file header_ext)
> GET_FILENAME_COMPONENT(basename ${ui_file} NAME_WE)
> SET(${ui_header}
> ${CMAKE_CURRENT_BINARY_DIR}/ui_${basename}.${header_ext})
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${${ui_header}}
> COMMAND ${QT_UIC_EXECUTABLE}
> ARGS ${ui_file} -o ${${ui_header}}
> DEPENDS ${ui_file}
> )
> ENDMACRO(WRAP_QT_UI)
>
> #-----------------------------------------------
> # Create rules for generated Qt wrapped files
> #-----------------------------------------------
> WRAP_QT_CPP(moc_mainwindow "${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.h"
> "cxx") WRAP_QT_CPP(moc_glwidget
> "${CMAKE_CURRENT_SOURCE_DIR}/widgets/GlWidget.h" "cxx")
> WRAP_QT_CPP(moc_dockwbase
> "${CMAKE_CURRENT_SOURCE_DIR}/dialogs/DockWidgetBase.h" "cxx")
> WRAP_QT_UI( ui_mainwindow "${CMAKE_CURRENT_SOURCE_DIR}/mainwindow.ui" "h")
>
> #-----------------------------------------------
> # Include the widgets & dialogs subdirs
> # Include the binary dir for Qt generated files
> #-----------------------------------------------
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/widgets)
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/dialogs)
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
>
> #-----------------------------------------------
> # Add all sources to project
> #-----------------------------------------------
> SET( molekel_SRCS
> main.cpp
> mainwindow.cxx
> widgets/GlWidget.cpp
> dialogs/DockWidgetBase.cpp
> ${moc_mainwindow}
> ${moc_glwidget}
> ${moc_dockwbase}
> ${ui_mainwindow}
> )
--
Filipe Sousa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20050721/cf997b8e/attachment.pgp
More information about the CMake
mailing list