当前位置:网站首页>Cmake uses the basic grammar of basic knowledge I
Cmake uses the basic grammar of basic knowledge I
2022-04-22 09:04:00 【Quan Yi】
One .cmake Predefined variables in
PROJECT_SOURCE_DIR The root directory of the project
PROJECT_BINARY_DIR function cmake Directory of commands , Usually ${PROJECT_SOURCE_DIR}/build
CMAKE_INCLUDE_PATH environment variable
CMAKE_LIBRARY_PATH environment variable
CMAKE_CURRENT_SOURCE_DIR What is being processed CMakeLists.txt Path
CMAKE_CURRENT_BINARY_DIR target Compile Directory
CMAKE_CURRENT_LIST_FILE The output calls the variable CMakeList.txt Full path to
CMAKE_CURRENT_LIST_LINE Output the line of the variable
CMAKE_MODULE_PATH Define your own cmake The path of the module
EXECUTABLE_OUTPUT_PATH Redefine the storage location of the target binary executable
LIBRARY_OUTPUT_PATH Redefine the storage location of the target link library file
PROJECT_NAME Back to pass PROJECT The name of the project defined by the directive
Two . system information
1.
CMAKE_MAJOR_VERSION
CMAKE_MINOR_VERSION
CMAKE_PATCH_VERSION
2.
CMAKE_SYSTEM System name , Such as linux-2.6.22
CMAKE_SYSTEM_NAME System name without version , Such as linux
CMAKE_SYSTEM_VERSION Such as :2.6.22
CMAKE_SYSTEM_PROCESSOR Processor name , Such as i686
3、 ... and . Switch options
BUILD_SHARED_LIBS Control the default library compilation method , If present and true, This will result in all libraries being built as shared libraries , Unless the library is explicitly added as a static library . This variable is usually used as OPTION Add to the project , So that each user of the project can decide whether to use shared libraries or static libraries to build the project .
CMAKE_C_FLAGS Set up C Compilation options
CMAKE_CXX_FLAGS Set up C++ Compilation options
Four . Basic grammar rules
1.cmake Variable usage ${} Method value , But in IF The variable name is used directly in the control statement
2. Instructions ( Parameters 1 Parameters 2)
Parameters use parentheses , Parameters are separated by spaces or semicolons
3. Instructions are case independent , Parameters and variables are case dependent .
5、 ... and . List of some common commands
1.PROJECT
Specify project name
2.SET
Defining variables
3.MESSAGE
Output user-defined information or variable values to the terminal
STATUS
WARNING
AUTHOR_WARNING
FATAL_ERROR error , Terminate all processes
SEND_ERROR error , Carry on , However, the generation step will be skipped
4.ADD_EXECUTABLE
Generate executable files
5.ADD_LIBRARY
Generate dynamic or static libraries
6.SET_TARGET_PROPERTIES
Set the name of the output , Set the version and of the dynamic library API edition
7.CMAKE_MINIMUM_REQUIRED
Statement CMake Version requirements for
8.ADD_SUBDIRECTORY
Add a subdirectory to the current project where the source files are stored , And you can specify the storage location of intermediate binary and target binary .
ADD_SUBDIRECTORY(src_dir [binary_dir] [EXCLUDE_FROM_ALL])
EXCLUDE_FROM_ALL Indicates that this directory is excluded from the compilation process .
9.INCLUDE_DIRECTORIES
Add multiple specific header file search paths to the project
10.LINK_DIRECTORIES
Add non-standard search paths for shared libraries
11.TARGET_LINK_LIBRARIES
by target Add a shared library that needs to be connected
12.ADD_DEFINITIONS
towards C/C++ Compiler added -D Definition
13.ADD_DEPENDENCIES
Definition target Other dependent target, Make sure target Before building , It depends on target It's built .
14.AUX_SOURCE_DIRECTORY
AUX_SOURCE_DIRECTORY(dir VAR)
Find all source code files in a directory and store the list in a variable
15.INCLUDE
INCLUDE(file [OPTIONAL]) Used to load CMakeLists.txt
16.FIND_
FIND_FILE(<VAR> name path1 path2 ...)
VAR The variable represents the full path of the file found , Include file name
FIND_LIBRARY(<VAR> name path1 path2 ...)
VAR The variable represents the full path of the library found , Contains the library file name
17.IF
IF(expression)
IF(not exp)
IF(var1 AND var2)
IF(var1 OR var2)
IF(COMMAND cmd)
IF(EXISTS dir)
IF(file1 IS_NEWER_THAN file2)
IF(DEFINED var)
IF(var MATCHES regex)
18. Number comparison expressions
IF(variable LESS number)
IF(string LESS number)
IF(variable GREATER number)
IF(string GREATER number)
IF(variable EQUAL number)
IF(string EQUAL number)
19. Compare in alphabetical order
IF(variable STRLESS number)
IF(string STRLESS number)
IF(variable STRGREATER number)
IF(string STRGREATER number)
IF(variable STREQUAL number)
IF(string STREQUAL number)
20.WHILE
WHILE(condition)
COMMAND(ARGS ...)
COMMAND(ARGS ...)
ENDWHILE(condition)
21.FOREACH
FOREACH(loop_var arg1 arg2 ...)
COMMAND(ARGS ...)
COMMAND(ARGS ...)
ENDFOREACH(loop_var)
22.LIST usage
list(LENGTH <list><output variable>)
list(GET <list> <elementindex> [<element index> ...]<output variable>)
list(APPEND <list><element> [<element> ...])
list(FIND <list> <value><output variable>)
list(INSERT <list><element_index> <element> [<element> ...])
list(REMOVE_ITEM <list> <value>[<value> ...])
list(REMOVE_AT <list><index> [<index> ...])
list(REMOVE_DUPLICATES <list>)
list(REVERSE <list>)
list(SORT <list>)
LENGTH return list The length of
GET return list in index Of element To value in
APPEND Add new element To list in
FIND return list in element Of index, No return found -1
INSERT Will be new element Insert into list in index The location of
REMOVE_ITEM from list Delete a element
REMOVE_AT from list Delete the specified index Of element
REMOVE_DUPLICATES from list Delete duplicate element
REVERSE take list Content reversal of
SORT take list Sort alphabetically
6、 ... and . common problem
1.cmake How to generate dynamic and static libraries in
ADD_LIBRARY and SET_TARGET_PROPERTIES
2.cmake How to use dynamic and static libraries in
INCLUDE_DIRECTORIES, LINK_DIRECTORIES, TARGET_LINK_LIBRARIES
3.cmake How to specify the output path of the generated file
Use SET Command redefine ECECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH Variable to specify the location of the final binary file .
4.cmake How to add compilation options in
CMAKE_C_FLAGS
CMAKE_CXX_FLAGS
Use ADD_DEFINITION add to
5.cmake How to add header file path in
INCLUDE_DIRECTORIES
6.cmake How to assign values to variables in
SET
AUX_SOURCE_DIRECTORY
7. Specify installation path
CMake Variable ``CMAKE_INSTALL_PREFIX'' Used to determine the installation location of files . If you use cmake --install You can customize the installation directory through --prefix Parameter assignment . For multi configuration tools , Please use --config Parameter assignment
configuration .
版权声明
本文为[Quan Yi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220817339771.html
边栏推荐
猜你喜欢

MySQL-高级-5 存储引擎

Playing with kubernetes - Basic Concepts

Learning objectives and general contents of C language

Rhel7 configuring local Yum source

数组传参的本质

A 2500 word article will take you to understand the basic knowledge of performance testing

简述变长数组

Rhel7 logical volume management - Notes

const修饰变量

Little known "three letter word"
随机推荐
51 单片机学习_3-4 独立按键控制发光LED左移&右移
A growing tree
51 single chip microcomputer learning_ 3-3 independent key control LED binary display
单片机开发之裸机也能 “多任务”?
Vs compiler annotation style
2022 R1 quick opening pressure vessel operation exercises and online simulation examination
内存地址的概念与理解
实现“ 字体逐渐展现 ”程序
链表中倒数第k个节点(顺序查找、快慢指针)
C 位开始公测啦
云原生微服务的下一站 微服务引擎 MSE 升级
Tar source package management - source package installation method
How to empty the input buffer
LeetCode 1450 - 1453
On the difference between local variables and global variables
flink 学习(十一)Watermark
Installing PostgreSQL under Linux (CentOS)
The server is set to start automatically and regularly
反转链表II
Flink流处理引擎系统学习(一)