http://blog.csdn.net/zyh821351004/article/details/50388429
1. catkin_make 與cmake的關系
程序在cmake編譯的流程: cmake指令依據你的CMakeLists.txt 文件,生成makefiles文件,make再依據此makefiles文件編譯鏈接生成可執行文件.
catkin_make是將cmake與make的編譯方式做了一個封裝的指令工具, 規范了工作路徑與生成文件路徑.
1) cmake標准流程
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install # (可選)
2) catkin_make 的流程
# In a catkin workspace
$ catkin_make $ catkin_make install # (可選)
如果源碼不在默認工作空間,需要指定編譯路徑: # In a catkin workspace $ catkin_make --source my_src $ catkin_make install --source my_src # (optionally)
2. catkin_make
1) catkin_make默認的路徑信息
catkin_make運行后終端輸出文件部分解析 #基本路徑 Base path: /home/user/catkin_ws Source space: /home/user/catkin_ws/src Build space: /home/user/catkin_ws/build Devel space: /home/user/catkin_ws/devel Install space: /home/user/catkin_ws/install #catkin_make 封裝運行中cmake運行的情況 Running command: "cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build" #編譯工具查找 -- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy -- This workspace overlays: /opt/ros/groovy #編譯的包 <pre name="code" class="cpp">#catkin_make 封裝運行中make運行的情況
#### Running command: "make -j4" in "/home/user/catkin_ws/build"
2) layout :ros工作空間文件系統結構
workspace_folder/ --WORKSPACE 工作空間 src/ --SOURCE SPACE 源空間 CMakeLists.txt/ --This is symlinked to catkin/cmake/toplevel.cmake package_1/ CMakeLists.txt package.xml ... package_n/ CMakeLists.txt package.xml build/ --BUILD SPACE 編譯空間 (this is where build system is invoked, not necessarily within workspace) CATKIN_IGNORE --Marking the folder to be ignored when crawling for packages (necessary when source space is in the root of the workspace, the file is emtpy) #此選項可用於忽略某個包編譯 devel/ --DEVEL SPACE 開發空間(targets go here, parameterizable, but defaults to peer of Build Space) # 生成二值 庫 可執行文件 bin/ etc/ /include/ lib/ share/ .catkin --Marking the folder as a development space (the file contains a semicolon separated list of Source space paths) # env.bash setup.bash setup.sh ... install/ --INSTALL SPACE 安裝空間[-DCMAKE_INSTALL_PREFIX=/any/directorycmake默認是/usr/local](this is where installed targets for test installations go, not necessarily within workspace) bin/ etc/ include/ lib/ share/ .catkin --Marking the folder as an install space (the file is emtpy) env.bash setup.bash -- Environment setup file for Bash shell setup.sh -- Environment setup file for Bourne shell ... / 系統安裝空間 /opt/ros/ROSDISTRO opt/ ros/ groovy/ setup.bash -- Environment setup file for Bash shell setup.sh -- Environment setup file for Bourne shell setup.zsh -- Environment setup file for zshell ...
結果空間 source RESULT-SPACE/setup.sh 類似掃描安裝空間與開發空間,替換系統通用下的對應文件.
總結:
src/ --SOURCE SPACE 源空間
build/ --BUILD SPACE 編譯空間
devel/ --DEVEL SPACE 開發空間
install/ --INSTALL SPACE 安裝空間
ROS系統安裝空間 /opt/ros/indigo
3) Overlays
catkin支持包的逐層覆蓋, 當前最高,其它依據source的順序逐層變高, 高層可覆蓋低層.
Example 4: Overlaying workspace 3 on top of local workspace2 install space on top of workspace1 devel space on top of system install cd ~/workspace2/build cmake -DCMAKE_INSTALL_PREFIX=~/ws2_installed ../src make make install source ~/ws2_installed/setup.bash cd ~/workspace3/build cmake ../src make
ros 環境變量設置 可以參考 .bashrc文件
# slam_ws
source /opt/ros/indigo/setup.bash source /home/yhzhao/slam_ws/devel/setup.bash export ROS_PACKAGE_PATH=~/slam_ws/src:$ROS_PACKAGE_PATH export ROS_WORKSPACE=~/slam_ws/src
4) catkin_make編譯指定的包
$ catkin_make -DCATKIN_WHITELIST_PACKAGES="package1;package2"
恢復編譯所有的包
$ catkin_make -DCATKIN_WHITELIST_PACKAGES=""
3. 對這句命令進行解釋:
catkin build rovio --cmake-args -DCMAKE_BUILD_TYPE=Release -DMAKE_SCENE=ON
catkin build – Build Packages,編譯rovio包
如果工作空間未初始化,可以自動完成工作空間初始化 (source ~/catkin_ws/devel/setup.bash)
It is used to build one or more packages in a catkin workspace. If a workspace is not yet initialized(初始化), build can initialize it with the default configuration(默認配置), but only if it is called from the workspace root. Specific workspaces can also be built from arbitrary working directories with the --workspace option.
--cmake-args #cmake參數
-DCMAKE_BUILD_TYPE=Release
使用 CMake我們可以生成 debug 版和 release 版的程序。debug 版的項目生成的可執行文件需要有調試信息並且不需要進行優化,而 release 版的不需要調試信息但需要優化。這些特性在 gcc/g++ 中是通過編譯時的參數來決定的,如果將優化程度調到最高需要設置參數-O3,最低是 -O0 即不做優化;添加調試信息的參數是 -g -ggdb ,如果不添加這個參數,調試信息就不會被包含在生成的二進制文件中。
CMake 中有一個變量 CMAKE_BUILD_TYPE ,可以的取值是 Debug、 Release、 RelWithDebInfo 和 MinSizeRel。當這個變量值為 Debug 的時候,CMake 會使用變量 CMAKE_CXX_FLAGS_DEBUG 和 CMAKE_C_FLAGS_DEBUG 中的字符串作為編譯選項生成 Makefile ,當這個變量值為 Release 的時候,工程會使用變量 CMAKE_CXX_FLAGS_RELEASE 和 CMAKE_C_FLAGS_RELEASE 選項生成 Makefile。
現假設項目中只有一個文件 main.cpp ,下面是一個可以選擇生成 debug 版和 release 版的程序的 CMakeList.txt :
PROJECT(main) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(CMAKE_SOURCE_DIR .) SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
AUX_SOURCE_DIRECTORY(. DIR_SRCS) ADD_EXECUTABLE(main ${DIR_SRCS})