ORB_SLAM2中CMakeLists.txt阅读

#设置cmake版本
cmake_minimum_required(VERSION 2.8)
#设置工程名为ORB_SLAM2
project(ORB_SLAM2)
#设置编译类型为Release
IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE Release)
ENDIF()
#打印编译类型
MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})
MESSAGE("Source dir: " ${PROJECT_SOURCE_DIR})
#cmake_c_flags用来设置编译选项 如 -g -wall(不展示警告)	;-march=native,GCC会自动检测你的CPU支持的指令集
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall   -O3 -march=native")

# Check C++11 or C++0x support 以下代码都用于自动判断系统编译器是否支持c++11标准;	
#检查编译器是否支持给定的标志
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) 
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   add_definitions(-DCOMPILEDWITHC11)
   message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
   add_definitions(-DCOMPILEDWITHC0X)
   message(STATUS "Using flag -std=c++0x.")
else()
   message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

#添加新element(元素?)到list中
#CMAKE_MODULE_PATH:  指定要由CMake模块加载的CMake模块的搜索路径include() 要么 find_package()命令,然后检查CMake随附的默认模块。
#cmake_modules:用于找寻不知名库时,事先在CMakeLists.txt相同位置建立一个叫cmake_modules的文件夹,在里面创建寻找库并命名的指令
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules) 
#寻找OpenCV 3.0find_package(OpenCV 3.0 QUIET)
if(NOT OpenCV_FOUND) #判断是否找到opencv包
   find_package(OpenCV 2.4.3 QUIET)
   if(NOT OpenCV_FOUND)
      message(FATAL_ERROR "OpenCV > 2.4.3 not found.")
   endif()
endif()
#寻找Eigen3包,矩阵库,此包可以支持包括固定大小、任意大小的所有矩阵操作,甚至是稀疏矩阵;支持所有标准的数值类型,并且可以扩展为自定义的数值类型;支持多种矩阵分解及其几何特征的求解
find_package(Eigen3 3.1.0 REQUIRED)
#寻找Pangolin包 是一个用于OpenGL显示/交互以及视频输入的一个轻量级、快速开发库
find_package(Pangolin REQUIRED)

#头文件指向目录
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
${EIGEN3_INCLUDE_DIR}
${Pangolin_INCLUDE_DIRS}
)
#设置CMAKE链接库输出位置在目录下lib文件夹中
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
#建立共享库SHARED是动态库,名称为PROJECT_NAMEORB_SLAM2
add_library(${PROJECT_NAME} SHARED   
src/System.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FrameDrawer.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Map.cc
src/MapDrawer.cc
src/Optimizer.cc
src/PnPsolver.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Initializer.cc
src/Viewer.cc
)
#为ORB_SLAM2库链接共享库文件
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
)

# Build examples
#指定可执行文件的输出位置为${PROJECT_SOURCE_DIR}(当前工程文件夹下)/Examples/RGB-D	CMAKE_RUNTIME_OUTPUT_DIRECTORY: 构建RUNTIME目标文件的输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)
#把Examples/RGB-D/rgbd_tum.cc目标文件编译成可执行文件rgbd_tum
add_executable(rgbd_tum
Examples/RGB-D/rgbd_tum.cc)
#可执行文件链接工程库
target_link_libraries(rgbd_tum ${PROJECT_NAME})

#重新设置执行文件的输出位置
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)

#把Examples/Stereo/stereo_kitti.cc目标文件编译成可执行文件stereo_kitti
add_executable(stereo_kitti
Examples/Stereo/stereo_kitti.cc)
#可执行文件链接工程库
target_link_libraries(stereo_kitti ${PROJECT_NAME})

#把Examples/Stereo/stereo_euroc.cc目标文件编译成可执行文件stereo_euroc
add_executable(stereo_euroc
Examples/Stereo/stereo_euroc.cc)
#可执行文件链接工程库
target_link_libraries(stereo_euroc ${PROJECT_NAME})

#与上面同理
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)

add_executable(mono_tum
Examples/Monocular/mono_tum.cc)
target_link_libraries(mono_tum ${PROJECT_NAME})

add_executable(mono_kitti
Examples/Monocular/mono_kitti.cc)
target_link_libraries(mono_kitti ${PROJECT_NAME})

add_executable(mono_euroc
Examples/Monocular/mono_euroc.cc)
target_link_libraries(mono_euroc ${PROJECT_NAME})

你可能感兴趣的:(linux,自动驾驶,c++)