当前位置:网站首页>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_STYLE
Option 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
边栏推荐
- Realbasicvsr test pictures and videos
- How to reset Firefox browser
- Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
- Unity build error: the name "editorutility" does not exist in the current context
- 飞桨EasyDL实操范例:工业零件划痕自动识别
- test
- Milkdown 控件图标
- “新红旗杯”桌面应用创意大赛2022
- 滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
- Adopt a cow to sprint A shares: it plans to raise 1.85 billion yuan, and Xu Xiaobo holds nearly 40%
猜你喜欢
10 张图打开 CPU 缓存一致性的大门
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
Lingyunguang of Dachen and Xiaomi investment is listed: the market value is 15.3 billion, and the machine is implanted into the eyes and brain
详细介绍六种开源协议(程序员须知)
Differences between MySQL storage engine MyISAM and InnoDB
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集
分布式事务解决方案
MATLAB中polarscatter函数使用
OSI seven layer model
随机推荐
飞桨EasyDL实操范例:工业零件划痕自动识别
服务器到服务器 (S2S) 事件 (Adjust)
Ogre入门尝鲜
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
关于 appium 启动 app 后闪退的问题 - (已解决)
Realbasicvsr test pictures and videos
如何让electorn打开的新窗口在window任务栏上面
QQ的药,腾讯的票
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
[learning notes] zkw segment tree
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
《开源圆桌派》第十一期“冰与火之歌”——如何平衡开源与安全间的天然矛盾?
ORACLE进阶(五)SCHEMA解惑
【学习笔记】AGC010
为租客提供帮助
How does MySQL create, delete, and view indexes?
Grep of three swordsmen in text processing
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
MongoDB内部的存储原理
RealBasicVSR测试图片、视频