当前位置:网站首页>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
)
边栏推荐
- 【sylar】框架篇-Chapter11-Socket 模块
- Study of the Intel aria 10 Avalon mm DMA interface for PCI Express solutions User Guide
- 【sylar】框架篇-Chapter10-Address 模块
- Thoroughly understand the sharing function in wechat games
- Mac installs mysql5.7 through brew
- [Sylar] framework chapter -chapter10-address module
- The State Administration of market supervision exposes typical cases of food safety
- Shanghai Telecom released public computing services and signed the action plan of "Joint Innovation Center for intelligent computing applications" with Huawei and other partners
- 《Intel Arria 10 Avalon-MM DMA Interface for PCI Express Solutions User Guide》文档学习
- 《KG-BERT: BERT for Knowledge Graph Completion》
猜你喜欢

Kotlin -- function
![[blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]](/img/72/10bd8a292c3ee3445907795ebf2ae8.png)
[blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]

ESP8266 WIFI 模块和手机通信

Advanced architects, 16 common principles of microservice design and Governance

Space complexity calculation super full sorting!! (calculation of hand tearing complexity

Password key hard coding check

Zhejiang University and other recent review papers on deep learning new drug design

网页源代码查看竟然有这么多方法!你都知道吗?

idea启动项目mvn命令终端用不了法将“mvn”项识别为 cmdlet

Idea2022 change the local warehouse and configure Alibaba cloud central warehouse
随机推荐
【sylar】框架篇-Chapter11-Socket 模块
《Intel Arria 10 Avalon-MM DMA Interface for PCI Express Solutions User Guide》文档学习
Cloud native Devops status survey questionnaire solicitation: kodelurover launched jointly with oschina
Destructor of member function
22 openwrt uses external kernel and kernel_ config
Important SQL server functions - other functions
Internet of things industrial serial port to WiFi module wireless routing WiFi module selection
MySQL: data types and operators
High number_ Chapter 4__ Curvilinear integral_ Exercise solution
CMake使用基础汇总
Docking with Hang Seng express ― dolphin DB NSQ plug-in tutorial
Pyqt based grouping tool
High number_ Chapter 4__ curvilinear integral
功耗:Leakage Power
Render the data obtained from the database to the table in elementui
Solana's "deceptive behavior": making mobile phones and opening stores
Information system project manager (2022) - key content: Information System Security Management (20)
How to select reliable securities analysts?
01-Node-Express系统框架搭建(express-generator)
After login, the upper right corner changes to enter the login status