win10 下 ros + Qt 工程CMakeLists.txt
系统:win10
ros: melodic
Qt: 5.12.12
源码目录: D:\workspace\catkin_qt
示例代码 https://github.com/ncnynl/ros-qt.git
由于示例代码是Qt4 ,目前我是用QT5,所以CMakeLists.txt 修改如下
CMakeLists.txt
##############################################################################
# CMake
##############################################################################cmake_minimum_required(VERSION 2.8.0)
project(msg)set (TARGET msg)set(CMAKE_CXX_STANDARD 11)
add_compile_options(-std=c++11)##############################################################################
# Catkin
##############################################################################find_package(catkin REQUIRED COMPONENTSroscppstd_msgs
)include_directories(${catkin_INCLUDE_DIRS}# include ui generate .h file${CMAKE_BINARY_DIR}/code02-msg
)
# 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
################################################################################ This setting causes Qt's "MOC" generation to happen automatically.
# set(CMAKE_AUTOMOC ON)
# set(CMAKE_AUTOUIC ON)
# set(CMAKE_AUTORCC ON)find_package(Qt5 COMPONENTS Gui Widgets Core REQUIRED)
set(QT_LIBRARIES Qt5::Gui Qt5::Widgets)##############################################################################
# Sections
############################################################################################################################################################
# Sources
##############################################################################file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)
file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/msg/*.hpp)
file(GLOB_RECURSE RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS resources/*.qrc)
file(GLOB_RECURSE UI RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS ui/*.ui)qt5_wrap_cpp(SOURCES ${HEADERS})
qt5_wrap_ui(SOURCES ${UI})
qt5_add_resources(SOURCES ${RESOURCES})##############################################################################
# Binaries
##############################################################################add_executable(${TARGET} ${SOURCES} )
target_link_libraries(${TARGET} ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS ${TARGET} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})message("CATKIN_PACKAGE_BIN_DESTINATION : " ${CATKIN_PACKAGE_BIN_DESTINATION})
message("CATKIN_PACKAGE_ETC_DESTINATION : " ${CATKIN_PACKAGE_ETC_DESTINATION})
message("CATKIN_PACKAGE_INCLUDE_DESTINATION : " ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
message("CATKIN_PACKAGE_LIB_DESTINATION : " ${CATKIN_PACKAGE_LIB_DESTINATION})
message("CATKIN_PACKAGE_PYTHON_DESTINATION : " ${CATKIN_PACKAGE_PYTHON_DESTINATION})
message("CATKIN_PACKAGE_SHARE_DESTINATION : " ${CATKIN_PACKAGE_SHARE_DESTINATION})
message("CMAKE_BINARY_DIR":${CMAKE_BINARY_DIR})
编译
win10下 打开 ros-melodic 命令行快捷方式:
切换到工作目录 :
C:\Windows\System32> cd /d D:\workspace\catkin_qt
添加工作目录环境变量:
D:\workspace\catkin_qt> cmd /k D:\workspace\catkin_qt\devel\setup.bat
catkin_make
运行
roscore
rosrun msg msg