[Documentation] [TitleIndex] [WordIndex

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 catkin_create_qt_pkg. The following is for an example project

In package.xml, at a minimum:

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>qt_build</build_depend>
  <build_depend>roscpp</build_depend>
  <run_depend>roscpp</run_depend>

In CMakeLists.txt:

Check if qt is on your system and set up the qt variables to play with

find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
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 catkin dependency includes and moc'd headers!

include_directories(${catkin_INCLUDE_DIRS})
add_executable(qdude ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(qdude ${QT_LIBRARIES} ${catkin_LIBRARIES})

Finally an install rule:

install(TARGETS qdude RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

Note the above works automatically so long as you keep

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.


2024-11-16 14:53