CMakeLists笔记

CMakeLists笔记

常用命令

  • 表明cmake的最低版本要求
# 版本要求
cmake_minimum_required(VERSION 3.10)
  • 设置项目名称
# set the project name
project(Tutorial)
# set the project name and version
project(Tutorial VERSION 1.0)
  • 指明c++标准
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(protobuf)
# add the executable
add_executable(Tutorial tutorial.cxx)
add_library(MathFunctions mysqrt.cxx)
include_directories(${protobuf_INCLUDE_DIRS})
include_directories("/usr/local/Cellar/vips/8.6.0/include")
link_directories(${protobuf_LIBRARY_DIRS})
link_directories("/usr/local/Cellar/glib/2.54.2/lib")

target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}")
target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})

在cmake语法中,link_libraries和target_link_libraries是很重要的两个链接库的方式,虽然写法上很相似,但是功能上有很大区别:

1,link_libraries用在add_executable之前,target_link_libraries用在add_executable之后

2,link_libraries用来链接静态库,target_link_libraries用来链接导入库,即按照header file + .lib + .dll方式隐式调用动态库的.lib库

add_subdirectory(MathFunctions)
set_target_properties(SqrtLibrary PROPERTIES
                        POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
                        )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值