CMakelist.txt 配置各种库

Posted neu-2015

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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})

 

以上是关于CMakelist.txt 配置各种库的主要内容,如果未能解决你的问题,请参考以下文章

将外部库添加到 CMakeList.txt c++

rhel7 编写CMakeList.txt编译运行MySQL官方例子代码

在 cmakelist.txt 中添加和链接 mysql 库

在 cmakelist.txt 中添加和链接 mysql 库

C++学习(二五六)CMakelist.txt和Android.mk

怎样编写Cmake的配置文件Cmakelist.txt