Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
example cmake with ROS and Qt
##############################################################################
# CMake
##############################################################################
cmake_minimum_required(VERSION 2.8.0)
project(show_laser)
##############################################################################
# Catkin
##############################################################################
# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(catkin REQUIRED COMPONENTS qt_build roscpp sensor_msgs)
include_directories(include ${catkin_INCLUDE_DIRS})
# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything.
catkin_package()
##############################################################################
# Qt Environment
##############################################################################
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
#SET(CMAKE_AUTOUIC ON)
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport)
##############################################################################
# Sections
##############################################################################
file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5PrintSupport_INCLUDE_DIRS}
)
add_definitions( -std=c++11 -fPIC)
##############################################################################
# Sources
##############################################################################
set( QT_SOURCES
src/main.cpp
src/main_window.cpp
src/qcustomplot.cpp
src/qnode.cpp
src/parameters_dialog.cpp
src/trunk_detector.cpp
src/qcustomplot.h
include/show_laser/parameters_dialog.h
include/show_laser/main_window.hpp
include/show_laser/qnode.hpp
include/show_laser/trunk_detector.hpp
)
##############################################################################
# Binaries
##############################################################################
add_executable(show_laser ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(show_laser
${catkin_LIBRARIES}
Qt5::Core
Qt5::Widgets
Qt5::PrintSupport
)
install(TARGETS show_laser RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
@h3ct0r

This comment has been minimized.

Copy link

h3ct0r commented Feb 11, 2019

Thanks for this example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.