CMakeLists.txt文件编写

重点

# 1、cmake版本要求
cmake_minimum_required(VERSION 3.15)
# 2、工程名
project(algorithm)
# 3、支持C++ 11标准
set(CMAKE_CXX_STANDARD 11)
# 4、打印消息
message(STATUS "The CMAKE_VERSION  is ${CMAKE_VERSION}")
message(STATUS "The CMAKE_SOURCE_DIR  is ${CMAKE_SOURCE_DIR}")

# 5、类似于程序中的define
add_definitions(${PCL_DEFINITIONS})

# 6、找到包
find_package(OpenCV REQUIRED)

# 7、包含头文件
include_directories( inc  inc/LIST.hpp)
# 8、添加链接库
add_library( code_lib
        STATIC
        src/LIST.cpp)
# 9、生成可执行文件
add_executable(code main.cpp )
# 10、可执行文件又链接哪些库
target_link_libraries(code code_lib)

指令是大小写无关的,参数和变量是大小写相关的。我一般习惯用小写。

## This is a standard CMakeLists.txt template, including
## how to enable C++11 compiler option and how to set 'Release'
## target compile option

cmake_minimum_required(VERSION 2.8)
project(cmake_template)

############# Use message function to print information ############
message(STATUS "CMake version: ${CMAKE_VERSION}")

############ enable C++11 compiler###############
## Method 1
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")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
    message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
    message(STATUS "Please use a different C++ compiler.")
endif()
## Method 2
set(CMAKE_CXX_STANDARD 11)


############ #enable warnings##################
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")


#############Set cmake compiler options##############
## Method 1
set(CMAKE_BUILD_TYPE "Release")

## Method 2
IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
      FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)

################## Some useful arguments ##########################
set(CMAKE_INCLUDE_CURRENT_DIR ON)

##########
##Build###
##########
add_library(lib hello.cpp)

add_executable(main main.cpp)
target_link_libraries(main ${LINK_LIBRARIES})

zhouhua

cmake_minimum_required(VERSION 3.15)
project(algorithm)

set(CMAKE_CXX_STANDARD 11)
include_directories(
        inc
        inc/LIST.hpp
        inc/Sort.hpp
        inc/MStack.hpp
        inc/DynamicPlan.hpp
        inc/haspMap.hpp
        inc/m_string.hpp
        inc/Find_algorithm.hpp
        inc/stock.hpp
        inc/priority_queue.hpp)

add_library(
        code_lib

        STATIC
        src/LIST.cpp
        src/Sort.cpp
        src/MStack.cpp
        src/DynamicPlan.cpp
        src/haspMap.cpp
        src/m_string.cpp src/Find_algorithm.cpp
        src/BT/Tree.cpp
        src/stock.cpp
        src/map_search.cpp
        inc/map_search.hpp
        src/priority_queue.cpp)

add_executable(code main.cpp )
target_link_libraries(code code_lib)

add_executable(tree_node src/BT/FindPath/path.cpp inc/BT/FindPath/path.hpp)

add_executable(createBT src/BT/creatBT/createBT.cpp inc/BT/createBT/createBT.hpp)

add_executable(commonAncestor src/BT/lowestCommonAncestor/lowestCommonAncestor.cpp
        inc/BT/lowestCommonAncestor/lowestCommonAncestor.hpp)

add_executable(InsertTree src/BT/InsertTree/InsertTree.cpp
        inc/BT/InsertTree/InsertTree.hpp)

add_executable(partition src/BackStep/partition/partition.cpp
        inc/BackStep/partition.hpp)

add_executable(restorIP src/BackStep/restoreIpAddresses/restoreIpAddresses.cpp
        inc/BackStep/restoreIpAddresses.hpp)

add_executable(findSubsequences src/BackStep/findSubsequences/findSubsequences.cpp
        inc/BackStep/findSubsequences.hpp)

add_executable(permute src/BackStep/permute/permute.cpp
        inc/BackStep/permute.hpp)

add_executable(sudo src/BackStep/数独/solveSudoKu.cpp
        inc/BackStep/solveSudoKu.hpp)

使用OpenCV库CMakeLists文件模板

cmake_minimum_required(VERSION 2.8.12)
project(OpenCV_test)

#find packages
find_package(OpenCV REQUIRED)

#include headers
include_directories(${OpenCV_INCLUDE_DIRS})

#target generation
add_executable(OpenCV_test main.cpp)

#link libraries
target_link_libraries(OpenCV_test ${OpenCV_LIBS})

使用PCL库CMakeLists文件模板

cmake_minimum_required(VERSION 2.8.12)
project(PCL_test)

#find packages
find_package(PCL 1.7 REQUIRED)
add_definitions(${PCL_DEFINITIONS})

#include headers
include_directories(${PCL_INCLUDE_DIRS})

#target generation
add_executable(PCL_test main.cpp)

#link libraries
target_link_libraries(PCL_test ${PCL_LIBRARIES})

使用Eigen库CMakeLists文件模板

cmake_minimum_required(VERSION 2.8.12)
project(Eigen_test)

#find packages
find_package(Eigen3 REQUIRED)

#include headers
include_directories(${EIGEN3_INCLUDE_DIR})

#target generation
add_executable(Eigen_test main.cpp)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值