当前位置:网站首页>Cmake usage base summary
Cmake usage base summary
2022-07-28 04:33:00 【Mr FF】
target_include_directories What to do ?
Specify the path of the header file contained in the target .
Inside INTERFACE|PUBLIC|PRIVATE What's the effect ?
INTERFACE:target The corresponding header file uses
PRIVATE:target The corresponding source file uses
PUBLIC:target Corresponding header file 、 Source files are used
Example :
target_include_directories(${LIBRARY_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
${XXX_INCLUDE_DIR}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
project() What is it? ?
project Is used to specify the cmake The name of the project , actually , It can also specify cmake Version number of the project (VERSION keyword )、 A short description (DESCRIPTION keyword )、 Home page URL(HOMEPAGE_URL keyword ) And the language used to compile the project
(LANGUAGES keyword )
Example :
project(XXX LANGUAGES CXX VERSION 0.1.0)
add_library() What is it? ?
add_library The command is used to add a target library to the project using the specified source file ( Generate library files ), There are mainly the following forms .
add_library(<name> [STATIC | SHARED | MODULE]
[EXCLUDE_FROM_ALL]
[<source>...])
Add a from source The target name built from the files listed in the list is name The library of ,name It has to be globally unique .( The source file for building the library can be directly specified , It can also be used later target_sources() Appoint .)
STATIC( Static library ) SHARED( Dynamic library ) MODULE( Module library ) Used to specify the type of Library . Use STATIC Build and generate static libraries (name.a), Use SHARED Build and generate dynamic libraries (name.so).
Example :
add_library(${LIBRARY_NAME} SHARED
${SRC_LIST}
)
aux_source_directory() What is it? ?
Collect all in the specified path <dir> The file name of the source file under , Store the output result list in the specified variable <variable> in .
aux_source_directory(<dir> <variable>)
This command is intended for projects instantiated with explicit templates . Template instantiation files can be stored in Templates Subdirectory , And use this command to automatically collect , To avoid manually listing all instantiations .
install() What is it? ?
install Used to specify rules to run at installation time . It can be used to install a lot of content , Can include target binary 、 Dynamic library 、 Static libraries and files 、 Catalog 、 Script etc.
( perform make install when , The specified header file , Install the library to the specified location .)
TARGETS:TARGET It can be many kinds of target files , The most common is through ADD_EXECUTABLE perhaps ADD_LIBRARY Defined target file , You can execute binary 、 Dynamic library 、 Static library .
ARCHIVE Static library ${CMAKE_INSTALL_LIBDIR} lib
LIBRARY Dynamic library ${CMAKE_INSTALL_LIBDIR} lib
RUNTIME Executable binary ${CMAKE_INSTALL_BINDIR} bin
PUBLIC_HEADER Associated with the library PUBLIC The header file ${CMAKE_INSTALL_INCLUDEDIR} include
PRIVATE_HEADER Associated with the library PRIVATE The header file ${CMAKE_INSTALL_INCLUDEDIR} include
In order to conform to the general default installation path , If set DESTINATION Parameters , It is recommended to configure the folder under the installation directory variable .
The following example will : Executable binary myrun The installation to ${CMAKE_INSTALL_BINDIR} Catalog , Dynamic library libmylib.so The installation to ${CMAKE_INSTALL_LIBDIR} Catalog , Static library libmystaticlib.a The installation to ${CMAKE_INSTALL_LIBDIR} Catalog .
Example 1:
INSTALL(TARGETS myrun mylib mystaticlib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Example 2:
install(TARGETS ${LIBRARY_NAME} EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Directory installation , Use DIRECTORY, This command installs the contents of one or more directories to a given destination , The directory structure is copied to the target location one by one . The last component of each directory name is appended to the target directory , But you can use a trailing slash to avoid this , Because it leaves the last component blank .
DIRECTORY If it is abc signify abc This directory will be installed in the target path ,abc/ signify abc The contents of this directory will be installed in the target path , and abc The directory itself is not installed . namely , If the directory name is not / ending , Then this directory will be installed as abc, If the directory name is / ending , Represents the installation of the contents of this directory to the target path , But not the directory itself .
Example 3:
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
边栏推荐
- Important SQL server functions - numeric functions
- Applet form-2
- 《KG-BERT: BERT for Knowledge Graph Completion》
- 重要的 SQL Server 函数 - 日期函数
- Fearless of side impact damage, Chery arize 8 fully protects the safety of passengers
- Explain initialization list
- 【sylar】框架篇-Chapter23-模块篇总结
- Password key hard coding check
- Thoroughly understand the sharing function in wechat games
- Campus stray cat information recording and sharing applet source code
猜你喜欢

Render the data obtained from the database to the table in elementui

Bio annotation of emotion analysis aste triples extraction

DNS series (III): how to avoid DNS spoofing

Advanced architects, 16 common principles of microservice design and Governance

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"

Kotlin -- function

23 openwrt switch VLAN configuration

Practice and thinking of AI standardization engine in pink client

重要的 SQL Server 函数 - 数字函数

Constructor of member function
随机推荐
24-Openwrt dnsmasq
Space complexity calculation super full sorting!! (calculation of hand tearing complexity
Solana's "deceptive behavior": making mobile phones and opening stores
Learn regular expressions (regexp)
Study of the Intel aria 10 Avalon mm DMA interface for PCI Express solutions User Guide
高数_第4章__曲线积分_习题解法
Ma Yi, Shen Xiangyang, Cao Ying's latest AI overview is hot! It took 3 months to build, netizens: required papers
Practice and thinking of AI standardization engine in pink client
2022-7-27 顾宇佳 学习笔记
Information system project manager (2022) - key content: information system integrated testing and management, project management maturity model, quantitative project management (21)
Information system project manager (2022) - key content: Strategic Management (17)
gerrit操作-回退掉某个patch_set
23 openwrt switch VLAN configuration
How to select reliable securities analysts?
Fearless of side impact damage, Chery arize 8 fully protects the safety of passengers
Information system project manager (2022) - key content: organization level project management, process management, project set management (18)
[blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]
网页源代码查看竟然有这么多方法!你都知道吗?
【sylar】框架篇-Chapter22-辅助模块
【sylar】框架篇-Chapter15-Stream 模块