当前位置:网站首页>CMakeLists. Txt how to write
CMakeLists. Txt how to write
2022-06-10 12:33:00 【Earth moving big white dog】
Recently I started to write some SLAM engineering , So do some sorting for the contents involved , So the first thing to do is to write a CMakeLists.txt. This article is about radar autopilot SLAM The engineering distance .
1 Information assignment
①cmake Version confirmation :
cmake_minimum_required(VERSION 3.1.0)
② project name :
project(lidar_localization)
③ Project option settings :
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
add_compile_options(-std=c++11)
add_definitions(-std=c++11)
2 Looking for dependent packages
④findpackage: You can find the header file containing path of the dependent package 、 The library path 、 Library name 、 Version number, etc , For details, please refer to the link
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
pcl_ros
geometry_msgs
tf
eigen_conversions
)
3 Path contains
⑤include_directories: Is used to add the specified directory to the compiler's header file search path , The specified directory is interpreted as the relative path of the current source path , Usually we go through include_directories Specify the path of the file we need to let the program know where the program is , See this for details link
There's a include The magic effect of
Due to the various calls and sometimes the if…else Judgment can lead to CMakeLists It's a mess , At this time, the calling contents of each package will be written as .cmake Files are placed in a fixed folder , This is CMakeLists As long as include these .cmake File can , Make the whole CMakeLists The results are clear .
include(cmake/glog.cmake)
include(cmake/PCL.cmake)
include(cmake/eigen.cmake)
include(cmake/geographic.cmake)
include_directories(include ${
catkin_INCLUDE_DIRS})
include(cmake/global_defination.cmake)
4 Add execution file
⑥add_executable: Create an executable based on a given source file , For details, please refer to the link
Because there may be many source files added, it will lead to CMakeLists Very miscellaneous , At this point, you can use a variable to store all the required source files , Finally, give this variable to add_executable that will do .
file(GLOB_RECURSE ALL_SRCS "*.cpp")
file(GLOB_RECURSE NODE_SRCS "src/*_node.cpp")
file(GLOB_RECURSE THIRD_PARTY_SRCS "third_party/*.cpp")
list(REMOVE_ITEM ALL_SRCS ${
NODE_SRCS})
list(REMOVE_ITEM ALL_SRCS ${
THIRD_PARTY_SRCS})
add_executable(test_frame_node src/test_frame_node.cpp ${
ALL_SRCS})
here ALL_SRCS That's the variable , adopt file() Create and list() Add or delete .
5 Connection Library
⑦target_link_libraries: Connect the given library file name to the executable file just created , For details, please refer to the link
alike , When there are many linked libraries, it will also lead to CMakeList Very miscellaneous , At this point, you can define a variable , Before 3 Medium include Some of the required libraries are merged into this variable , Finally to target_link_libraries that will do
set(ALL_TARGET_LIBRARIES "")
...include Content ...
target_link_libraries(test_frame_node ${
catkin_LIBRARIES} ${
ALL_TARGET_LIBRARIES})
here ALL_TARGET_LIBRARIES That's the variable , stay include Written .cmake The file will pass list(APPEND ALL_TARGET_LIBRARIES ${XX_LIBRARIES}) Merge the required libraries .
Variables and options
CMAKE_BUILD_TYPE: Specify the compilation type , The common one is Debug and Release
CMAKE_CXX_FLAGS_RELEASE: compile Release The compilation options used in version
add_compile_options(): Add compile options , Same as SET(CMAKE_CXX_FLAGS …) + SET(CMAKE_C_FLAGS) The effect is the same , example :add_compile_options(-std=c++11) to c++ and c Compile with c++11 Support options , link
add_definitions(): Used to add flag bits , link
Final CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(lidar_localization)
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
add_compile_options(-std=c++11)
add_definitions(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
pcl_ros
geometry_msgs
tf
eigen_conversions
)
set(ALL_TARGET_LIBRARIES "")
include(cmake/glog.cmake)
include(cmake/PCL.cmake)
include(cmake/eigen.cmake)
include(cmake/geographic.cmake)
include_directories(include ${
catkin_INCLUDE_DIRS})
include(cmake/global_defination.cmake)
catkin_package()
file(GLOB_RECURSE ALL_SRCS "*.cpp")
file(GLOB_RECURSE NODE_SRCS "src/*_node.cpp")
file(GLOB_RECURSE THIRD_PARTY_SRCS "third_party/*.cpp")
list(REMOVE_ITEM ALL_SRCS ${
NODE_SRCS})
list(REMOVE_ITEM ALL_SRCS ${
THIRD_PARTY_SRCS})
add_executable(test_frame_node src/test_frame_node.cpp ${
ALL_SRCS})
target_link_libraries(test_frame_node ${
catkin_LIBRARIES} ${
ALL_TARGET_LIBRARIES})
边栏推荐
- 技术分享| 快对讲,全球对讲
- 软件项目管理 6.10.成本预算
- eseses
- JS将阿拉伯数字翻译成中文的大写数字、JS将数字转换为大写金额(整理)
- Add line number field to SQL query results - sqlserver
- Unity3D开发MR实现模型遮挡与透明地面接收阴影
- Driver. JS - open source and independent interactive guidance tool library for web novices, powerful and highly customizable
- 通过反射获取枚举值
- C# 均衡权重分配
- 别把“IT信息化”不当“超级工程”
猜你喜欢

Altium Designer重拾之学习资料推荐

Mobile phone manufacturers "go back to their ancestors", only apple said no

(十 一)const修饰成员函数

Driver. JS - open source and independent interactive guidance tool library for web novices, powerful and highly customizable

Daniel recommended and hanged the interviewer

SLM4054独立线性锂电池充电器的芯片的学习

VDMA调试总结

FM4057S单节锂电池线性充电芯片的学习

IO file stream repeat read

Web design and development, efficient web development
随机推荐
ASP.NET 利用ImageMap控件设计导航栏
Creating basic stacks and queues in C language
VS2010 undefined identifier round
ASP. Net using imagemap control to design navigation bar
AD-PCB原理图学习(1)
无代码五月大事件|微软低代码矩阵更新;多份行业报告发布...
[limited time], full of dry goods
今天,一对情侣拿下香港最大电商IPO
Shadergraph - 302 swimming Dragon
H5弹出提示层-上下左右居中
软件项目管理 6.10.成本预算
微信web开发工具使用教程,公司开发web
[Yan Xuan], real problem analysis
Lua syntax
dom4j解析xml
VDO-SLAM源码阅读笔记[2] local optimization和global optimization
文档提升计划第二期|OceanBase 邀您一起进行文档共建
Driver. JS - open source and independent interactive guidance tool library for web novices, powerful and highly customizable
(10) Notes on null pointer accessing member function and this pointer
漏扫工具学习笔记