当前位置:网站首页>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
)
边栏推荐
- 26 openwrt port forwarding DMZ UPnP
- Information system project manager (2022) - key content: intellectual property rights and standards and specifications (22)
- Attempt method in laravel user authentication
- Zhejiang University and other recent review papers on deep learning new drug design
- Use Baidu developer tool 4.0 to build a dedicated applet IDE
- 【二、移动web网页开发】2D&3D转换与动画、移动端布局、响应式布局
- Jupyter notebook installation code prompt function
- Blooming old trees -- quickly build a map bed application with imageprocessor
- Some personal understandings of openpose
- MySQL:数据类型和运算符
猜你喜欢

Internet of things industrial serial port to WiFi module wireless routing WiFi module selection

The simulation test disconnects the server from the public network
![[record of question brushing] 9. Number of palindromes](/img/01/74b0f40a29aaec487898a791cc8b79.png)
[record of question brushing] 9. Number of palindromes

Important SQL server functions - numeric functions

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"

Practice and thinking of AI standardization engine in pink client

Jupyter Notebook安装代码提示功能

Study of the Intel aria 10 Avalon mm DMA interface for PCI Express solutions User Guide

Transformer landing | next vit realizes the real-time landing of industrial tensorrt, surpassing RESNET and cswin

MySQL: data types and operators
随机推荐
The unsatisfied analysis of setup and hold timing is the solution
将数据库拿到的数据渲染到elementUI 中的table中去
[Sylar] framework Chapter 6 collaborative scheduling module
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"
MySQL: data types and operators
[blood vessel detection] Based on MATLAB mom method, combined with Hessian and curve fitting, blood vessel diameter measurement [including Matlab source code, 1970]
Space complexity calculation super full sorting!! (calculation of hand tearing complexity
[Sylar] framework -chapter9-hook module
[Sylar] framework -chapter12 bytearray module
[Sylar] framework -chapter11 socket module
上班摸鱼打卡模拟器微信小程序源码
10 more advanced open source command line tools
MySQL:数据类型和运算符
If mongoose exists, it will be updated; if it does not exist, it will be added
Information system project manager (2022) - key content: Information System Security Management (20)
[Sylar] framework -chapter14 tcpserver module
重要的 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
Explain initialization list
Kotlin -- function