cmake 拾遗之.cmake文件

cmake 拾遗之.cmake文件

这个文件是神马,是不是从来没注意过,但是其至关重要。主要功能有两个,一是引导你的CMakeLists.txt找到对应包的地址,二是作为脚本(类似于python脚本)实现一些在make之前处理的逻辑,比如说proto文件生成xx.pb.h 和xx.pb.cc文件等。

首先我们看一下这个文件在哪儿

假设你已经源码编译路一个库,我以octomap 库为例说明。这个是机器人中一个常见点地图表达用的库

# 创建文件夹
xx:~/data/project/slam/octomap-devel$ mkdir build && cd build
#生成makefile
xx:~/data/project/slam/octomap-devel/build$ cmake ..
#编译
xx:~/data/project/slam/octomap-devel/build$ make

现在我们执行一下install

~/data/project/slam/octomap-devel/build$ sudo make install
[sudo] bamboo 的密码: 
[  4%] Built target octomath-static
[  7%] Built target octomath
.......
[100%] Built target exampleEDT3D
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/include/octomap/AbstractOcTree.h
-- Installing: /usr/local/include/octomap/AbstractOccupancyOcTree.h
-- Installing: /usr/local/include/octomap/ColorOcTree.h
....
-- Installing: /usr/local/include/octomap/math/Utils.h
-- Installing: /usr/local/include/octomap/math/Vector3.h
-- Installing: /usr/local/share/octomap/package.xml

-- Installing: /usr/local/share/octomap/octomap-config.cmake
-- Installing: /usr/local/share/octomap/octomap-config-version.cmake
-- Installing: /usr/local/lib/pkgconfig/octomap.pc

-- Installing: /usr/local/lib/liboctomath.so.1.9.5
-- Installing: /usr/local/lib/liboctomath.so.1.9

-- Set runtime path of "/usr/local/lib/liboctomath.so.1.9.5" to "/usr/local/lib"

-- Installing: /usr/local/lib/liboctomath.so
-- Installing: /usr/local/lib/liboctomath.a
-- Installing: /usr/local/lib/liboctomap.so.1.9.5
-- Installing: /usr/local/lib/liboctomap.so.1.9
-- Set runtime path of "/usr/local/lib/liboctomap.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/liboctomap.so
-- Installing: /usr/local/lib/liboctomap.a

-- Installing: /usr/local/share/octomap/octomap-targets.cmake
-- Installing: /usr/local/bin/graph2tree
-- Set runtime path of "/usr/local/bin/graph2tree" to "/usr/local/lib"
-- Installing: /usr/local/bin/log2graph
-- Set runtime path of "/usr/local/bin/log2graph" to "/usr/local/lib"
-- Installing: /usr/local/bin/binvox2bt
-- Set runtime path of "/usr/local/bin/binvox2bt" to "/usr/local/lib"
-- Installing: /usr/local/bin/bt2vrml
-- Set runtime path of "/usr/local/bin/bt2vrml" to "/usr/local/lib"
-- Installing: /usr/local/bin/edit_octree
-- Set runtime path of "/usr/local/bin/edit_octree" to "/usr/local/lib"
-- Installing: /usr/local/bin/convert_octree
-- Set runtime path of "/usr/local/bin/convert_octree" to "/usr/local/lib"
-- Installing: /usr/local/bin/eval_octree_accuracy
-- Set runtime path of "/usr/local/bin/eval_octree_accuracy" to "/usr/local/lib"
-- Installing: /usr/local/bin/compare_octrees
-- Set runtime path of "/usr/local/bin/compare_octrees" to "/usr/local/lib"
-- Installing: /usr/local/bin/octovis
-- Set runtime path of "/usr/local/bin/octovis" to "/usr/local/lib:/home/bamboo/data/software/anaconda3/lib"
-- Installing: /usr/local/lib/liboctovis.a
-- Installing: /usr/local/lib/liboctovis.so.1.9.5
-- Installing: /usr/local/lib/liboctovis.so.1.9
-- Set runtime path of "/usr/local/lib/liboctovis.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/liboctovis.so
-- Installing: /usr/local/share/octovis/octovis-targets.cmake
-- Installing: /usr/local/include/octovis/ColorOcTreeDrawer.h
-- Installing: /usr/local/include/octovis/OcTreeDrawer.h
-- Installing: /usr/local/include/octovis/OcTreeRecord.h
-- Installing: /usr/local/include/octovis/PointcloudDrawer.h
-- Installing: /usr/local/include/octovis/SceneObject.h
-- Installing: /usr/local/include/octovis/SelectionBox.h
-- Installing: /usr/local/include/octovis/TrajectoryDrawer.h
-- Installing: /usr/local/share/octovis/octovis-config.cmake
-- Installing: /usr/local/share/octovis/octovis-config-version.cmake
-- Installing: /usr/local/share/octovis/package.xml
-- Installing: /usr/local/include/dynamicEDT3D/bucketedqueue.h
-- Installing: /usr/local/include/dynamicEDT3D/bucketedqueue.hxx
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDT3D.h
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDTOctomap.h
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDTOctomap.hxx
-- Installing: /usr/local/include/dynamicEDT3D/point.h
-- Installing: /usr/local/share/dynamic_edt_3d/package.xml
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DConfig.cmake
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DConfig-version.cmake
-- Installing: /usr/local/lib/pkgconfig/dynamicEDT3D.pc
-- Installing: /usr/local/lib/libdynamicedt3d.so.1.9.5
-- Installing: /usr/local/lib/libdynamicedt3d.so.1.9
-- Set runtime path of "/usr/local/lib/libdynamicedt3d.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/libdynamicedt3d.so
-- Installing: /usr/local/lib/libdynamicedt3d.a
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DTargets.cmake

至少可以看到四点:

  • .h文件安装到了 /usr/local/octomap 文件夹下了
-- Installing: /usr/local/include/octomap/AbstractOcTree.h
  • .so文件安装到了 /usr/local/lib/ 文件夹下了
-- Installing: /usr/local/lib/liboctomath.so.1.9.5
  • 可执行文件安装到了/usr/local/bin 文件夹下了
-- Installing: /usr/local/bin/octovis
  • .cmake文件 安装到了/usr/local/share/octomap 文件夹下了
-- Installing: /usr/local/share/octomap/octomap-targets.cmake

还有一点,也特别重要:
设置 runtime path

-- Set runtime path of "/usr/local/lib/liboctomath.so.1.9.5" to "/usr/local/lib"

我们来看看这个文件长成神马样子

@[TOC]

# cmake 拾遗之.cmake文件

这个文件是神马,是不是从来没注意过,但是其至关重要。主要功能有两个,一是引导你的CMakeLists.txt找到对应包的地址,二是作为脚本(类似于python脚本)实现一些在make之前处理的逻辑,比如说proto文件生成xx.pb.h 和xx.pb.cc文件等。

## 首先我们看一下这个文件在哪儿
假设你已经源码编译路一个库,我以octomap 库为例说明。这个是机器人中一个常见点地图表达用的库
```bash
# 创建文件夹
xx:~/data/project/slam/octomap-devel$ mkdir build && cd build
#生成makefile
xx:~/data/project/slam/octomap-devel/build$ cmake ..
#编译
xx:~/data/project/slam/octomap-devel/build$ make

现在我们执行一下install

~/data/project/slam/octomap-devel/build$ sudo make install
[sudo] bamboo 的密码: 
[  4%] Built target octomath-static
[  7%] Built target octomath
.......
[100%] Built target exampleEDT3D
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/include/octomap/AbstractOcTree.h
-- Installing: /usr/local/include/octomap/AbstractOccupancyOcTree.h
-- Installing: /usr/local/include/octomap/ColorOcTree.h
....
-- Installing: /usr/local/include/octomap/math/Utils.h
-- Installing: /usr/local/include/octomap/math/Vector3.h
-- Installing: /usr/local/share/octomap/package.xml

-- Installing: /usr/local/share/octomap/octomap-config.cmake
-- Installing: /usr/local/share/octomap/octomap-config-version.cmake
-- Installing: /usr/local/lib/pkgconfig/octomap.pc

-- Installing: /usr/local/lib/liboctomath.so.1.9.5
-- Installing: /usr/local/lib/liboctomath.so.1.9

-- Set runtime path of "/usr/local/lib/liboctomath.so.1.9.5" to "/usr/local/lib"

-- Installing: /usr/local/lib/liboctomath.so
-- Installing: /usr/local/lib/liboctomath.a
-- Installing: /usr/local/lib/liboctomap.so.1.9.5
-- Installing: /usr/local/lib/liboctomap.so.1.9
-- Set runtime path of "/usr/local/lib/liboctomap.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/liboctomap.so
-- Installing: /usr/local/lib/liboctomap.a

-- Installing: /usr/local/share/octomap/octomap-targets.cmake
-- Installing: /usr/local/bin/graph2tree
-- Set runtime path of "/usr/local/bin/graph2tree" to "/usr/local/lib"
-- Installing: /usr/local/bin/log2graph
-- Set runtime path of "/usr/local/bin/log2graph" to "/usr/local/lib"
-- Installing: /usr/local/bin/binvox2bt
-- Set runtime path of "/usr/local/bin/binvox2bt" to "/usr/local/lib"
-- Installing: /usr/local/bin/bt2vrml
-- Set runtime path of "/usr/local/bin/bt2vrml" to "/usr/local/lib"
-- Installing: /usr/local/bin/edit_octree
-- Set runtime path of "/usr/local/bin/edit_octree" to "/usr/local/lib"
-- Installing: /usr/local/bin/convert_octree
-- Set runtime path of "/usr/local/bin/convert_octree" to "/usr/local/lib"
-- Installing: /usr/local/bin/eval_octree_accuracy
-- Set runtime path of "/usr/local/bin/eval_octree_accuracy" to "/usr/local/lib"
-- Installing: /usr/local/bin/compare_octrees
-- Set runtime path of "/usr/local/bin/compare_octrees" to "/usr/local/lib"
-- Installing: /usr/local/bin/octovis
-- Set runtime path of "/usr/local/bin/octovis" to "/usr/local/lib:/home/bamboo/data/software/anaconda3/lib"
-- Installing: /usr/local/lib/liboctovis.a
-- Installing: /usr/local/lib/liboctovis.so.1.9.5
-- Installing: /usr/local/lib/liboctovis.so.1.9
-- Set runtime path of "/usr/local/lib/liboctovis.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/liboctovis.so
-- Installing: /usr/local/share/octovis/octovis-targets.cmake
-- Installing: /usr/local/include/octovis/ColorOcTreeDrawer.h
-- Installing: /usr/local/include/octovis/OcTreeDrawer.h
-- Installing: /usr/local/include/octovis/OcTreeRecord.h
-- Installing: /usr/local/include/octovis/PointcloudDrawer.h
-- Installing: /usr/local/include/octovis/SceneObject.h
-- Installing: /usr/local/include/octovis/SelectionBox.h
-- Installing: /usr/local/include/octovis/TrajectoryDrawer.h
-- Installing: /usr/local/share/octovis/octovis-config.cmake
-- Installing: /usr/local/share/octovis/octovis-config-version.cmake
-- Installing: /usr/local/share/octovis/package.xml
-- Installing: /usr/local/include/dynamicEDT3D/bucketedqueue.h
-- Installing: /usr/local/include/dynamicEDT3D/bucketedqueue.hxx
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDT3D.h
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDTOctomap.h
-- Installing: /usr/local/include/dynamicEDT3D/dynamicEDTOctomap.hxx
-- Installing: /usr/local/include/dynamicEDT3D/point.h
-- Installing: /usr/local/share/dynamic_edt_3d/package.xml
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DConfig.cmake
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DConfig-version.cmake
-- Installing: /usr/local/lib/pkgconfig/dynamicEDT3D.pc
-- Installing: /usr/local/lib/libdynamicedt3d.so.1.9.5
-- Installing: /usr/local/lib/libdynamicedt3d.so.1.9
-- Set runtime path of "/usr/local/lib/libdynamicedt3d.so.1.9.5" to "/usr/local/lib"
-- Installing: /usr/local/lib/libdynamicedt3d.so
-- Installing: /usr/local/lib/libdynamicedt3d.a
-- Installing: /usr/local/share/dynamicEDT3D/dynamicEDT3DTargets.cmake

至少可以看到四点:

  • .h文件安装到了 /usr/local/octomap 文件夹下了
-- Installing: /usr/local/include/octomap/AbstractOcTree.h
  • .so文件安装到了 /usr/local/lib/ 文件夹下了
-- Installing: /usr/local/lib/liboctomath.so.1.9.5
  • 可执行文件安装到了/usr/local/bin 文件夹下了
-- Installing: /usr/local/bin/octovis
  • .cmake文件 安装到了/usr/local/share/octomap 文件夹下了
-- Installing: /usr/local/share/octomap/octomap-targets.cmake

还有一点,也特别重要:
设置 runtime path

-- Set runtime path of "/usr/local/lib/liboctomath.so.1.9.5" to "/usr/local/lib"

我们来看看这个文件长成神马样子

xx:cd /usr/local/share
xx:/usr/local/share$ ls
ca-certificates  dynamic_edt_3d  dynamicEDT3D  eigen3  fonts  man  octomap  octovis  pcl-1.10  pkgconfig  sgml  xml
xx:/usr/local/share$ cd octomap/
xx:/usr/local/share/octomap$ ls
octomap-config.cmake  octomap-config-version.cmake  octomap-targets.cmake  package.xml
xx:/usr/local/share/octomap$ vim octomap-config.cmake
  1 # ===================================================================================
  2 #  The OctoMap CMake configuration file
  3 #
  4 #             ** File generated automatically, do not modify **
  5 #
  6 #  Usage from an external project:
  7 #    In your CMakeLists.txt, add these lines:
  8 #
  9 #    FIND_PACKAGE(OCTOMAP REQUIRED )
 10 #    INCLUDE_DIRECTORIES(${OCTOMAP_INCLUDE_DIRS})
 11 #    TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${OCTOMAP_LIBRARIES})
 12 #
 13 #
 14 #    This file will define the following variables:
 15 #      - OCTOMAP_LIBRARIES      : The list of libraries to links against.
 16 #      - OCTOMAP_LIBRARY_DIRS   : The directory where lib files are. Calling
 17 #                                 LINK_DIRECTORIES with this path is NOT needed.
 18 #      - OCTOMAP_INCLUDE_DIRS   : The OctoMap include directories.
 19 #      - OCTOMAP_MAJOR_VERSION  : Major version.
 20 #      - OCTOMAP_MINOR_VERSION  : Minor version.
 21 #      - OCTOMAP_PATCH_VERSION  : Patch version.
 22 #      - OCTOMAP_VERSION        : Major.Minor.Patch version.
 23 #
 24 # ===================================================================================
 25 
 26 
 27 ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
 28 ####### Any changes to this file will be overwritten by the next CMake run ####
 29 ####### The input file was octomap-config.cmake.in                            ########

 31 get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)
 32 
 33 macro(set_and_check _var _file)
 34   set(${_var} "${_file}")
 35   if(NOT EXISTS "${_file}")
 36     message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
 37   endif()
 38 endmacro()
 39 
 40 macro(check_required_components _NAME)
 41   foreach(comp ${${_NAME}_FIND_COMPONENTS})
 42     if(NOT ${_NAME}_${comp}_FOUND)
 43       if(${_NAME}_FIND_REQUIRED_${comp})
 44         set(${_NAME}_FOUND FALSE)
 45       endif()
 46     endif()
 47   endforeach()
 48 endmacro()
 50 ####################################################################################
 51 
 52 set(OCTOMAP_MAJOR_VERSION "1")
 53 set(OCTOMAP_MINOR_VERSION "9")
 54 set(OCTOMAP_PATCH_VERSION "5")
 55 set(OCTOMAP_VERSION "1.9.5")
 56 
 57 set_and_check(OCTOMAP_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
 58 set_and_check(OCTOMAP_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
 59 
 60 # Set library names
 61 set(OCTOMAP_LIBRARIES
 62   "${PACKAGE_PREFIX_DIR}/lib/liboctomap.so"
 63   "${PACKAGE_PREFIX_DIR}/lib/liboctomath.so"
 64 )
 65 
 66 include(${CMAKE_CURRENT_LIST_DIR}/octomap-targets.cmake)

未完待续

CMAKE_CURRENT_SOURCE_DIR
这是当前处理的CMakeLists.txt所在的目录

CMAKE_CURRENT_LIST_DIR
(自2.8.3开始)这是当前正在处理的列表文件的目录.

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值