cmake之配置常用库
常用库
catkin
#catkin
find_package(catkin REQUIRED COMPONENTS
roscpp
image_transport
cv_bridge
)
include_directories(${catkin_INCLUDE_DIRS})
boost
# boost
find_package( Boost COMPONENTS system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
opencv
# opencv
find_package(OpenCV 3 REQUIRED)
include_directories(${OpenCV_LIBRARIES})
pcl
# pcl
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
yaml
# yaml
find_package(yaml-cpp REQUIRED)
eigen
# eigen
include_directories( "/usr/include/eigen3" )
catkin_package()
ceres
# ceres
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLDUE_DIRS})
g2o
# g2o
# 因为g2o不是常用库, 因此需要添加findg2o.cmake文件
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )
set(G2O_ROOT /usr/local/include/g2o)
find_package( G2O REQUIRED )
include_directories(${G2O_INCLUDE_DIRS})
openmp
# openMP
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
set(CMAKE_SHARE_LINKER_FLAGS "${CMAKE_SHARE_LINKER_FLAGS} ${OpenMP_SHARE_LINKER_FLAGS}")
endif()
cuda
# cuda
find_package(CUDA REQUIRED)
if(CUDA_FOUND)
message("FOUND CUDA ${CUDA_VERSION}.\n")
# set CUDA_NVCC_FLAGS as you would do with CXX/C FLAGS
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DMY_DEF=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMY_DEF=1" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMY_DEF=1" )
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3 -std=c++11")
# only necessary if you wish to create a lib
set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF)
set(BUILD_SHARED_LIBS ON)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})
endif()
使用
# executable
add_executable(node src/node.cpp)
target_link_libraries(node
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBRARIES})
chrislzy: 如有疑惑,错误或者建议,请在评论区留下您宝贵的文字; 转载请注明作者和出处,未经允许请勿用于商业用途!