用qt5.3.2打开ros(机器人操作系统)的界面(CmakeList.txt)
机器人操作系统的GUI用QT來实现,可以用qmake编译,也可以用cmake编译
一般來说,在QT调试中用qmake來调试,然而对于ros来说,用cmake更为熟练.
在qt中以打开CmakeList.txt的方法來打开GUI的方法:
1) 首先确保项目处于catkin的工作空间(避免错误
CMake Error at CMakeLists.txt:65 (message):
find_package(catkin) failed. catkin was neither found in the workspace nor
in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was
sourced before.
)
这句话是为了环境变量而设置的,因为我的是linux系统, .bashrc里面
source ~/backup/ISW-build/devel/setup.bash ()
是运行ros指令查找的可执行文件目录,如果不是当前工程的目录有些东西比如消息,是查找不到的
env
可以看到打印的环境变量中 CMAKE_PREFIX_PATH 包含/opt/ros/kinetic,表明ros环境变量配置完成
(如果打开文件提示CMAKE_PREFIX_PATH没有设置ROS,是因为没有setup.sh 注意:是因为qtcretor配置被覆盖,依次点击工具->选项->构建和运行(kit),,选择自己的套件,修改CMake Configuration,删除CMAKE_PREFIX_PATH,以防被覆盖)
2) File-open file or project 找到要打开的項目的CmakeList.txt(最好把包与cakkin_init生成的cmake放在同一级别,打开这个cmake
最后为CMakeLists.txt,是catkin生成的)
3) 设置BUILD Location中的build directory为catkin的工作空间的build 目录(只是需要设置一个生成目录,也可自定义一个qt_build目录)
此处build 目录对应.bashrc的目录, 如
source ~/backup/ISW-build/devel/setup.bash
那就 ~/backup/ISW-build
4) 在Run Cmake中设置Arguments为:-DCMKE-BUILD-TYPE=Debug(可为空,也就是说不用设置即可进行下一步)
5) Run Cmake
6) 若一切正常的話点击Finished.出现错误时请查看Cmake是否正确
欢迎大家批评,指正,交流!
联系方式:
emai: [email protected]
# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake
cmake_minimum_required(VERSION 3.0.2)
project(Project)
set(CATKIN_TOPLEVEL TRUE)
# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
RESULT_VARIABLE _res
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
# searching fot catkin resulted in an error
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
# include catkin from workspace or via find_package()
if(_res EQUAL 0)
set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
# include all.cmake without add_subdirectory to let it operate in same scope
include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
add_subdirectory("${_out}")
else()
# use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
# or CMAKE_PREFIX_PATH from the environment
if(NOT DEFINED CMAKE_PREFIX_PATH)
if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
if(NOT WIN32)
string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
else()
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
endif()
endif()
endif()
# list of catkin workspaces
set(catkin_search_path "")
foreach(path ${CMAKE_PREFIX_PATH})
if(EXISTS "${path}/.catkin")
list(FIND catkin_search_path ${path} _index)
if(_index EQUAL -1)
list(APPEND catkin_search_path ${path})
endif()
endif()
endforeach()
# search for catkin in all workspaces
set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
find_package(catkin QUIET
NO_POLICY_SCOPE
PATHS ${catkin_search_path}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
unset(CATKIN_TOPLEVEL_FIND_PACKAGE)
if(NOT catkin_FOUND)
message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
endif()
endif()
catkin_workspace()