Overview
Some cmake magic to assist in the build logic for qt-ros packages. Currently this is mostly to assist for the mingw cross compiled qt-ros packages which need to fix some faulty logic in cmake versions < 2.8.1. For 2.8.1+, it has been fixed upstream.
Usage
Most of this is automatically generated if you create your project with roscreate-qt-pkg. The following is for an example project
In manifest.xml, at a minimum:
<!-- rosbuild1 --> <depend package="qt_build"/> <depend package="roscpp"/> <rosbuild2> <depend package="qt_build"/> <depend package="roscpp"/> </rosbuild2>
In CMakeLists.txt:
Check if qt is on your system and set up the qt variables to play with
rosbuild_include(qt_build qt-ros) rosbuild_prepare_qt4(QtCore QtGui) # Add qt components to the list here
Set up a directory structure to auto-find and define the relevant resources:
file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui) file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc) file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/qdude/*.hpp) QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES}) QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS}) QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC}) file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)
Add cpp resources for your executable, don't forget the moc'd files!
rosbuild_add_executable(qdude ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP}) target_link_libraries(qdude ${QT_LIBRARIES})
Note the above works automatically so long as you keep
header files in include/qdude/*.hpp
sources in src
user interface files in ui
resources in resources
It is also possible to use it to generate multiple qt apps in a single package or qt libraries. See the code used by qt_tutorials for an example.