当前位置:网站首页>CMake使用基础汇总
CMake使用基础汇总
2022-07-28 04:22:00 【Mr FF】
target_include_directories做什么用?
指定目标包含的头文件路径。
里面的INTERFACE|PUBLIC|PRIVATE起什么作用?
INTERFACE:target对应的头文件使用
PRIVATE:target对应的源文件使用
PUBLIC:target对应的头文件、源文件都使用
例子:
target_include_directories(${LIBRARY_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
${XXX_INCLUDE_DIR}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
project()是什么?
project用于指定cmake工程的名称,实际上,它还可以指定cmake工程的版本号(VERSION关键字)、简短的描述(DESCRIPTION关键字)、主页URL(HOMEPAGE_URL关键字)和编译工程使用的语言
(LANGUAGES关键字)
例子:
project(XXX LANGUAGES CXX VERSION 0.1.0)
add_library()是什么?
add_library命令用来使用指定的源文件向工程中添加一个目标库(生成库文件),主要有一下几种形式。
add_library(<name> [STATIC | SHARED | MODULE]
[EXCLUDE_FROM_ALL]
[<source>...])
添加一个从source列表列出的文件构建而来的目标名为name的库,name必须全局唯一。(构建库的源文件可以直接指定,也可以后续使用target_sources()指定。)
STATIC(静态库) SHARED(动态库) MODULE(模块库)用来指定库的类型。使用STATIC构建生成静态库(name.a),使用SHARED构建生成动态库(name.so)。
例子:
add_library(${LIBRARY_NAME} SHARED
${SRC_LIST}
)
aux_source_directory()是什么?
搜集所有在指定路径<dir>下的源文件的文件名,将输出结果列表储存在指定的变量<variable>中。
aux_source_directory(<dir> <variable>)
该命令旨在供使用显式模板实例化的项目使用。 模板实例化文件可以存储在Templates子目录中,并使用此命令自动收集,以避免手动列出所有实例化。
install()是什么?
install用于指定在安装时运行的规则。它可以用来安装很多内容,可以包括目标二进制、动态库、静态库以及文件、目录、脚本等
(执行make install时,会将指定的头文件,库安装到指定的位置。)
TARGETS:TARGET可以是很多种目标文件,最常见的是通过ADD_EXECUTABLE或者ADD_LIBRARY定义的目标文件,即可执行二进制、动态库、静态库。
ARCHIVE 静态库 ${CMAKE_INSTALL_LIBDIR} lib
LIBRARY 动态库 ${CMAKE_INSTALL_LIBDIR} lib
RUNTIME 可执行二进制文件 ${CMAKE_INSTALL_BINDIR} bin
PUBLIC_HEADER 与库关联的PUBLIC头文件 ${CMAKE_INSTALL_INCLUDEDIR} include
PRIVATE_HEADER 与库关联的PRIVATE头文件 ${CMAKE_INSTALL_INCLUDEDIR} include
为了符合一般的默认安装路径,如果设置了DESTINATION参数,推荐配置在安装目录变量下的文件夹。
下面的例子会将:可执行二进制myrun安装到${CMAKE_INSTALL_BINDIR}目录,动态库libmylib.so安装到${CMAKE_INSTALL_LIBDIR}目录,静态库libmystaticlib.a安装到${CMAKE_INSTALL_LIBDIR}目录。
例子1:
INSTALL(TARGETS myrun mylib mystaticlib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
例子2:
install(TARGETS ${LIBRARY_NAME} EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
目录的安装,使用DIRECTORY, 该命令将一个或多个目录的内容安装到给定的目的地,目录结构被逐个复制到目标位置。每个目录名称的最后一个组成部分都附加到目标目录中,但是可以使用后跟斜杠来避免这种情况,因为它将最后一个组成部分留空。
DIRECTORY后面如果是abc意味着abc这个目录会安装在目标路径下,abc/意味着abc这个目录的内容会被安装在目标路径下,而abc目录本身却不会被安装。即,如果目录名不以/结尾,那么这个目录将被安装为目标路径下的abc,如果目录名以/结尾,代表将这个目录中的内容安装到目标路径,但不包括这个目录本身。
例子3:
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
边栏推荐
- MATLB | location and constant volume IEEE30 node implementation of distributed energy
- [performance optimization methodology series] III. core idea of performance optimization (2)
- Information system project manager (2022) - key content: Project Risk Management (11)
- 金仓数据库KingbaseES安全指南--6.2. 身份验证相关的配置文件
- Do Netease and Baidu have their own tricks for seizing the beach AI learning machine?
- 25 openwrt guest network add
- Un7.27: common commands of redis database.
- 将数据库拿到的数据渲染到elementUI 中的table中去
- glusterfs 文件未挂载,权限: r-s
- 重要的 SQL Server 函数 - 日期函数
猜你喜欢

上班摸鱼打卡模拟器微信小程序源码

Shanghai Telecom released public computing services and signed the action plan of "Joint Innovation Center for intelligent computing applications" with Huawei and other partners

40: Chapter 4: Development File Service: 1:fastdfs: (1): introduction to fastdfs;

Null security and exception

Information system project manager (2022) - key content: Project Portfolio Management (19)

Information system project manager (2022) - key content: information system integrated testing and management, project management maturity model, quantitative project management (21)

High number_ Chapter 4__ Curvilinear integral_ Exercise solution
![[performance optimization methodology series] III. core idea of performance optimization (2)](/img/3c/9a2daea9bc136ae48d20d96e8f0402.png)
[performance optimization methodology series] III. core idea of performance optimization (2)

Detailed explanation of pl/sql parameters ("box model")

Learn regular expressions (regexp)
随机推荐
Applet form-2
Machine learning 06: Decision Tree Learning
10 more advanced open source command line tools
Study notes of Gu Yujia on July 27, 2022
Information system project manager (2022) - key content: Project Risk Management (11)
Information system project manager (2022) - key content: Strategic Management (17)
The unsatisfied analysis of setup and hold timing is the solution
功耗:Leakage Power
Shell rental reptile
[record of question brushing] 9. Number of palindromes
Harmony's Application on the shelves reported an error. The solution of "please use the API of the released version to develop the application and apply for listing"
Kingbasees Security Guide for Jincang database -- 5.1. database transmission security
The simulation test disconnects the server from the public network
Adding DSP library to STM32F103 and its solution
High number_ Chapter 4__ Curvilinear integral_ Exercise solution
Elementary level of C language -- while, for, do while
[Niuke] find 1+2+3+... +n
RT-Thread改变打印串口(在BSP的基础上添加其他功能)
Remove screen cutting and copying restrictions
Fedformer MOE module