当前位置:网站首页>Cmake learning and use notes (1)
Cmake learning and use notes (1)
2022-07-07 13:17:00 【ly_ zszcyx】
Catalog
problem : To be solved ?---- Solved
set Set a variable ------------------------- Add version number
Set the system's own variables
add_definitions------------------------- Add macro definition
Using tools :
vs 2019, Clion
System : Windows
Refer to the website :cmake Use the tutorial ( One )- start - Nuggets
Project settings :
project(<PROJECT-NAME> [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]] [LANGUAGES <language-name>...])
You can only set the project name : Such as :
project ("cPulsPlusTestProject")You can also set the item description , Project address, etc
project (cPulsPlusTestPrj
VERSION 1.0.0
DESCRIPTION " Project description :xxxxx"
HOMEPAGE_URL " Project address , such as :github Address "
LANGUAGES CXX)Be careful : The above code fragment must be capitalized , Otherwise, the compilation will not pass , such as (LANGUAGES CXX, DESCRIPTION etc. )
Build the program
Use cmake To build programs :
Use cmake .
Before building :

After construction :

But I use it clion The built program always defaults to vs 2019
After construction :

If you want to re cmake , Need to delete cache 

make
windows Prompt make Not an internal command
If you use MinGW, Yours make It's called mingw32-make
If you use MSVC, Yours make It's called nmake
problem : To be solved ?---- Solved
cmake . Always default to vs2019
Suspected : Not understanding cmake Back point (.) What does that mean?
After testing, it should be the path , It should be exactly CMakeList.txt The position of , therefore I should be ../ Return to upper level

Always use the upper path , therefore cmake come out Always default to vs 2019 
When I enter mingw Next , What we build is not vs 2019 The environment : Such as :

set Set a variable ------------------------- Add version number
set(KEY VALUE) Take two parameters , Used to declare variables . stay camke Use... In grammar KEY You can't get... Directly VALUE, You have to use ${KEY} This way of writing to get VALUE.
Set the system's own variables
Such as :C++ standard
set(cmake_cxx_standard 11)
Set custom variables
Set custom variables , for example : Set the header file search path

CMAKE_CURRENT_SOURCE_DIR
This is the currently processed CMakeLists.txt directory
Add version number
First set two variables
set (cPlusPlusTest_version_major 1)
set (cPlusPlusTest_version_minor 0)
configure_file(
"${PROJECT_SOURCE_DIR}/cPlusPlusTestConfig.h.in"
"${PROJECT_BINARY_DIR}/cPlusPlusTestConfig.h"
)
stay cPlusPlusTestConfig.h.in Add
#define cPlusPlusTest_version_major @[email protected]
#define cPlusPlusTest_version_minor @[email protected]

Use 
Expand :
configure_file(input output options)
Put a file ( from input Parameter assignment ) Copy to the specified location ( from output Parameter assignment ), And according to options Modify its contents .
configure_file Commands are generally used to customize compilation options or customize macro scenarios .configure_file The order will be based on options Specified rule :
- COPYONLY: Just copy files , Don't do any variable substitution . This option specifies
NEWLINE_STYLEOption cannot be used ( Invalid ). - ESCAPE_QUOTES: Avoid any backslash (C style ) escape .
take input File copy to output file , And the variables in the input file content , Replace the reference with @[email protected] or ${VAR} Variable value . Each variable reference will be replaced with the current value of the variable , If the variable is not defined , Is an empty string .
for example :cPlusPlusTestConfig.h.in
1. Definition CMakeList.txt
set (cPlusPlusTest_version_major 1.9)
set (cPlusPlusTest_version_minor 0)
configure_file(
"${PROJECT_SOURCE_DIR}/cPlusPlusTestConfig.h.in"
"${PROJECT_BINARY_DIR}/cPlusPlusTestConfig.h"
)2. cPlusPlusTestConfig.h.in( Input file )
#define cPlusPlusTest_version_major @[email protected]
#define cPlusPlusTest_version_minor @[email protected]
3. cPlusPlusTestConfig.h( The output file )
Automatic generation , There is no need for us to manually input

PROJECT_BINARY_DIR: The official explanation is The full path used to generate the project directory
for example :

PROJECT_SOURCE_DIR: PROJECT_SOURCE_DIR Include for PROJECT() The most recent CMakeLists.txt The folder where the file is located .
for example : The inner layer of the CMakeLists.txt Medium not included project()
An error will occur Tell me the file doesn't exist

I put it on the outer layer , There is no error

add_definitions------------------------- Add macro definition
Add one flag For pretreatment
There are two ways to add :
- -D start
- /D start
for example :add_definitions(-DMyDebug)

Use :
Be careful : Do not use the front -D
边栏推荐
- Practical example of propeller easydl: automatic scratch recognition of industrial parts
- leecode3. 无重复字符的最长子串
- Mongodb meets spark (for integration)
- 记一次 .NET 某新能源系统 线程疯涨 分析
- LIS 最长上升子序列问题(动态规划、贪心+二分)
- Scripy tutorial classic practice [New Concept English]
- Why can basic data types call methods in JS
- DETR介绍
- About the problem of APP flash back after appium starts the app - (solved)
- 【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
猜你喜欢

QQ的药,腾讯的票

Analysis of DHCP dynamic host setting protocol

Practical example of propeller easydl: automatic scratch recognition of industrial parts

PAcP learning note 1: programming with pcap

【学习笔记】AGC010

基于鲲鹏原生安全,打造安全可信的计算平台
![[learning notes] agc010](/img/2c/37f2537a4dadd84adacf3da5f1327a.png)
[learning notes] agc010

存储过程的介绍与基本使用

Sequoia China completed the new phase of $9billion fund raising

记一次 .NET 某新能源系统 线程疯涨 分析
随机推荐
JS判断一个对象是否为空
存储过程的介绍与基本使用
单片机原理期末复习笔记
DHCP 动态主机设置协议 分析
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
How to continue after handling chain interruption / sub chain error removed from scheduling
Adopt a cow to sprint A shares: it plans to raise 1.85 billion yuan, and Xu Xiaobo holds nearly 40%
LIS 最长上升子序列问题(动态规划、贪心+二分)
Ogre入门尝鲜
Storage principle inside mongodb
JS determines whether an object is empty
Sequoia China completed the new phase of $9billion fund raising
Unity 构建错误:当前上下文中不存在名称“EditorUtility”
[learning notes] zkw segment tree
JNA learning notes 1: Concepts
Differences between MySQL storage engine MyISAM and InnoDB
【学习笔记】AGC010
Practical case: using MYCAT to realize read-write separation of MySQL
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property