1. 程式人生 > >CMakelist.txt 配置各種庫

CMakelist.txt 配置各種庫

1.基本

# 設定為DEBUG模式
set(CMAKE_BUILD_TYPE "Debug")

# 宣告要求的cmake最低版本
cmake_minimum_required(VERSION 2.8)

# 宣告一個cmake工程
project(HelloSLAM)

# 新增一個可執行程式
# 語法:add_executable(程式名 原始碼檔案)
add_executable(helloSLAM helloSLAM.cpp)
add_library(hello libHelloSLAM.cpp)
add_executable(useHello useHello.cpp)
add_library(hello_shared SHARED libHelloSLAM.cpp)
target_link_libraries(useHello hello_shared)

2. Eigen

cmake_minimum_required(VERSION 3.2)

PROJECT(geometry)

include_directories("/usr/local/include/eigen3")

add_executable(Geometry useGeometry.cpp)

3.Sophus

cmake_minimum_required( VERSION 2.8 )  
project( useSophus )  
  
  
 set(Sophus_DIR /home/jxq/Sophus/Sophus/build)
# 為使用 sophus,您需要使用find_package命令找到它  
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})
  
add_executable( useSophus useSophus.cpp )  
target_link_libraries(useSophus ${Sophus_LIBRARIES})

4.Opencv

set(CMAKE_CXX_FLAGS "-std=c++11")

project(myopencv)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(imageBasics imageBasics.cpp)

target_link_libraries(imageBasics ${OpenCV_LIBS})

5. ceres + g2o

cmake_minimum_required( VERSION 2.8 )
project( g2o_curve_fitting )

set( CMAKE_BUILD_TYPE "Release" ) set( CMAKE_CXX_FLAGS "-std=c++11 -O3" ) # 新增cmake模組以使用ceres庫 list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules ) # 尋找G2O find_package(G2O REQUIRED) include_directories(${G20_INCLUDE_DIRS}) include_directories( ${G2O_INCLUDE_DIRS} "/usr/local/include/eigen3" ) # OpenCV find_package( OpenCV REQUIRED ) include_directories( ${OpenCV_DIRS} ) add_executable( curve_fitting main.cpp ) # 與G2O和OpenCV連結 target_link_libraries( curve_fitting ${OpenCV_LIBS} g2o_core g2o_stuff )
cmake_minimum_required(VERSION 3.2)

add_compile_options(-std=c++11)

project(MyCeres)

find_package(OpenCV REQUIRED)

find_package( Ceres REQUIRED)

include_directories("/usr/local/include/eigen3")

include_directories("/usr/local/include/ceres")

include_directories(${OpenCV_INCLUDE_DIRS})

include_directories( ${CERES_INCLUDE_DIRS})

add_executable(main main.cpp)

target_link_libraries(main ${OpenCV_LIBS} ${CERES_LIBRARIES})