当前位置:网站首页>Section 6: introduction to cmake grammar
Section 6: introduction to cmake grammar
2022-07-26 23:37:00 【At three o'clock and two o'clock】
List of articles
cmake
- cmake It's an open source build tool .cmake Is the solution Makefile Many kinds , Different specifications .cmake It's a cross platform building tool . yes Makefile It's the top tool of the game . Automatically build makefile, Instead of developers building manually makefile The tedious process of .
- At present, many open source projects have CMakeLists.txt file , Fast implementation of cross platform construction source code . Truly accomplish "Write Once,Run everywhere".
CMake Variable
- cmake The file includes commands + notes + Space + Line break ;
- cmake Write the source file with CMakeLists.txt or .cmake For extended
- CMakeLists.txt Write the construction rules of the whole project ( Put the directory at the top ), It can be done by add_subdirectory() The command adds the construction rules of the next level source directory
- Cmake All valid statements in the source file of China are commands
Common variable names
- PROJECT_NAME project The project name written in the command
- CMAKE_VERSION Currently in use cmake edition
- CMAKE_SOURCE_DIR Project top level directory , machine CMakeLists File path
- PROJECT_SOURCE_DIR Same as CMAKE_SOURCE_DIR
- CMAKE_BINARY_DIR The directory where the project compilation takes place , The perform cmake Command the directory for project configuration , It's usually build
- CMAKE_CURRENT_SOURCE_DIR At present CMakeLists.txt Path
- CMAKE_CURRRENT_BINARY_DIR What is being processed CMakeLists.txt The compilation directory where the target file is generated in
- CMAKE_CURRENT_LIST_FILE: The output calls the variable CMakeLists.txt The full path to the file
notes
use “#” Annotate , From the beginning to the end of the line ;
Variable
- grammar : set( Variable name A variable's value )
- Be careful : Variable names are case sensitive
set(var 711) # Define variable values
message("var = ${var}")
message("PATH = $ENV{PATH}") # environment variable
bool Variable
- Boolean variable size sensitivity
true:1, ON, YES, TRUE, Y, Not 0 Value
false:0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, An empty string ””, With -NOTFOUND a null-terminated string
- example
set(true 1)
set(false OFF)
message("true = " ${true})
message("false = " ${false})
list
- If a variable has multiple values , An unquoted quotation cmake Will automatically split into multiple list elements at the semicolon , And pass them to the command as multiple independent parameters . Quoted quotation cmake Don't slice and keep semicolon still , The entire quotation mark is passed to the command as a parameter .
set(list_var 1 2 3 4) # list_var = 1;2;3;4
set(list_foo "5;6;7;8") # list_foo = 5;6;7;8
message(${list_var})# Output : 1234
message(${list_foo})# Output :5678
message("${list_var}")# Output :1;2;3;4
message("${list_foo}")# Output :5;6;7;8
cmake command
stay cmake in , Conditional statements , Loop statement , Function or macro , It's all orders .
The operator
Operator priority : One yuan > binary > Logic
Logic
NOT, AND, OR
One yuan
EXISTS, COMMAND, DEFINED.
binary
EQUAL, LESS, LESS_EQUAL, GREATER, GREATER_EQUAL, STREQUAL,STRLESS, STRLESS_EQUAL, STRGREATER, STRGREATER_EQUAL,VERSION_EQUAL, VERSION_LESS, VERSION_LESS_EQUAL, VERSION_GREATER, VERSION_GREATER_EQUAL,MATCHES
Conditional commands
if( expression )
# Command block to execute
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
elseif( expression 2)
# Command block to execute
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
else( expression )
# Command block to execute
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
endif( expression )
Circular command
- The loop can be used break() Command exit ,continue() The command can skip the following statement block , Immediately enter the next cycle iteration .
while( expression )
# Command block to execute
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
# break Exit loop
# continue Exit the current cycle , So let's move on to the next cycle
endwhile( expression )
Traverse
- foreach Also support break(),continue() The command operation .
foreach( Loop variable Parameters 1 Parameters 2 ...)
# Command block to execute
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
endforeach( Loop variable )
Custom command ( function )
The command can take string parameters , But no return value . Command names are case insensitive , therefore SET and set Indicates the same command , But the parameter names in the command are case sensitive ARG and arg Are two different parameters .
# Custom function command format :
function(<name> [arg1 [arg2 [arg3 ...]]])
# Custom command block
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
endfunction(<name>)
# call
name( [arg1 [arg2 [arg3 ...]]])
Custom macro commands
- Macros and functions are basically the same , Just say that function commands have their own scope , The scope of the macro command is the same as that of the caller .
macro(<name> [arg1 [arg2 [arg3 ...]]])
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
endmacro(<name>)
Scope
- Cmake Three scopes : Global layer / Directory layer / Function layer .
- Global layer : cache Variable , Visible throughout the project , Generally in use set When defining a variable, specify CACHE Parameters can be defined as cache The variable of .
- Directory layer : In the current directory CMakeLists.txt In the definition of , And included in this document ( adopt include perhaps macro Imported ) Other cmake The variables defined in the source file belong to the scope of the directory layer .
- Function layer : Variables defined in the command function , Variables within the scope of a function .
- Global layer < Directory layer < Function layer , Variables with small scope of action will cover variables with large scope of action .
- The variables of the upper scope are modified in the current scope , It will not be passed to the scope of the upper layer ( The current scope is just copying all variables of the previous scope to its own scope for modification ), For example, modify a variable defined by the directory layer scope in the function command , It does not affect the value of this variable in the directory layer .
- If the modification passes set The command explicitly specifies PARENT_SCOPE Parameters , The modified variable scope is in the upper scope , Instead of the current scope .
边栏推荐
- Security team: Recently, there is an rce vulnerability in the COREMAIL email client of windows, which may lead to the disclosure of the private key of the wallet
- The nature and proof of the center of gravity of [mathematics] tree
- Vector execution engine framework gluten announced the official open source and appeared at spark technology summit
- C.Net timestamp and time conversion support time zone
- Lesson 2 of Silicon Valley classroom - building project environment and developing lecturer management interface
- NFT展示指南:如何展示你的NFT藏品
- 力扣152题:乘积最大子数组
- Distributed lock and its implementation
- MySQL 数据的导入
- P5469 [NOI2019] 机器人(拉格朗日插值、区间dp)
猜你喜欢

会议OA之我的会议

第二部分—C语言提高篇_8. 文件操作

Re understand the life world and ourselves

告别宽表,用 DQL 成就新一代 BI

Part II - C language improvement_ 13. Recursive function

HCIA-R&S自用笔记(19)VLAN配置及实验、VLAN间路由

基本的SELECT语句

【C语言】数组

【C语言】经典的递归问题

Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
随机推荐
Problems and solutions encountered in using nextline(), nextint() and next() in scanner
Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
第二部分—C语言提高篇_8. 文件操作
The most classic Nature paper on Alzheimer's disease is suspected of fraud
Real time voice quality monitoring
企业数据治理面临的六大挑战!
使用AW9523B芯片驱动16路LED时,LED出现误点亮的问题
18、打开、保存文件对话框使用小记
第二部分—C语言提高篇_11. 预处理
Dynamic memory management and related topics
Write golang simple C2 remote control based on grpc
SQL Basics
1. Configuration environment and project creation
[flask advanced] analyze the thread isolation mechanism in flask in combination with the source code
数据供应链的转型 协调一致走向成功的三大有效策略
np. transpose & np.expand_ dims
基于gRPC编写golang简单C2远控
Signal debugging document developed by car
An online accident, I suddenly realized the essence of asynchrony
Hcia-r & s self use notes (23) DHCP