当前位置:网站首页>Basic use process of cmake
Basic use process of cmake
2022-07-01 14:56:00 【JACKSONMHLN】
1、 Directory of complete projects
A complete project , It should be divided into at least these parts . among ,bin Under the directory is the runnable file ,build Under the directory is the temporarily built file ,include Under the directory is the header file used ,src Under the directory is the implementation file of the header file . Of course, you can add test The test file ,third Third party library files, etc

2、cmake Use
cmake Easy to use , Can cross platform , Build the project compilation environment . Especially better than writing directly Makefile Simple ( In building large-scale project compilation when , Need to write a lot of File Dependencies ), It can be done by simple CMake Generate responsible Makefile file . We often use External build ,
Use external build , We can create a build folder that can be located anywhere on the file system . All temporary builds and target files are located in this directory , To keep the source code tree clean .( You can specify the location of the target file ). Take the above example :
cd /build/ go to build Under the table of contents
cmake .. cmake Because of Engineering CMakeLists.txt At the previous level , So there is ..
make The previous step will generate makefile file ,make perform .
3、CMakeLists.txt Compiling
cmake_minimum_required(VERSION 3.10)
# Appoint camke The smallest version of , You can specify the minimum to maximum version
project(sum1)
# Set up project name
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Appoint Generated executable file Storage directory
set(SOURCES
src/sum.cpp)
main.cpp)
# Create a variable , Name is SOURCES. It contains the specified cpp file
add_executable(sum11 ${SOURCES})
# Generate an executable file with all the source files , Because it defines SOURCE Variable , So there is no need to list cpp The file
target_include_directories(sum11
PRIVATE
${PROJECT_SOURCE_DIR}/include)
# Set this executable file sum11 The path of the library to be included , Note the executable sum11 The path of the library to be included .Finish writing this CMakeList.txt After the document , You can follow the step 2 Do what you say .
The above description is a simple step , With the complexity of the project , Need to write more . Summarize and distinguish some common quantities .
1、aux_source_directory(<dir> <variable>) And set(<variable> target.cpp)
Find all source files in the directory . Collect in the specified directory Names of all source files , And store the list in the provided variable .
set(SOURCES src/sum.cpp) Collect designated The specified source file in the directory , And store .
2、include_directories(${PROJECT_SOURCE_DIR}/include) And
target_include_directories(sum11 PRIVATE ${PROJECT_SOURCE_DIR}/include)
effect : Add header file search path to source file : Add the specified directory to the compiler's header file search path , The specified directory is interpreted as the relative path of the current source path .
first : At present CMakeList.txt Medium All goals as well as All after its call point All targets in the added subdirectories will have header file search paths .
the second : Designated target Include header file path .
Usage of intermediate attributes :<INTERFACE|PUBLIC|PRIVATE> Basis of use
- PRIVATE - The directory is added to the target ( library ) In the included path of .
- INTERFACE - The directory was not added to the target ( library ) In the included path of , It links to other targets of the library ( Library or executable program ) Included in path
- PUBLIC - The directory is added to the target ( library ) In the included path of , Also added to other targets linked to this library ( Library or executable program ) In the included path of
in other words , Depending on whether the library contains this path , And whether other targets that call the library contain this path , It can be divided into three types scope.
边栏推荐
- [Verilog quick start of Niuke question series] ~ use functions to realize data size conversion
- Develop small programs and official account from zero [phase III]
- Opencv interpolation mode
- 三十之前一定要明白的职场潜规则
- Task.Run(), Task.Factory.StartNew() 和 New Task() 的行为不一致分析
- tensorflow2-savedmodel convert to pb(frozen_graph)
- Reorganize the trivial knowledge points at the end of the term
- How to view the state-owned enterprises have unloaded Microsoft office and switched to Kingsoft WPS?
- 互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
- The State Administration of Chia Tai market supervision, the national development and Reform Commission and the China Securities Regulatory Commission jointly reminded and warned some iron ores
猜你喜欢

The first technology podcast month will be broadcast soon

JVM performance tuning and practical basic theory part II
![[14. Interval sum (discretization)]](/img/e5/8b29aca7068a6385e8ce90c2742c37.png)
[14. Interval sum (discretization)]

Blog recommendation | in depth study of message segmentation in pulsar

2022-2-15 learning the imitation Niuke project - Section 3 post details

关于重载运算符的再整理

C learning notes (5) class and inheritance
![[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion](/img/e1/d35e1d382e0e945849010941b219d3.png)
[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion

Music player development example (can be set up)
![After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]](/img/ac/ab6053e6ea449beedf434d4cf07dbb.png)
After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]
随机推荐
Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables
Tensorflow 2. X realizes iris classification
【锁】Redis锁 处理并发 原子性
MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
Filter &(登录拦截)
Microservice development steps (Nacos)
2022-2-15 learning the imitation Niuke project - Section 3 post details
Official announcement: Apache Doris graduated successfully and became the top project of ASF!
【LeetCode】16、最接近的三数之和
Fundamentals of C language
Ensure production safety! Guangzhou requires hazardous chemical enterprises to "not produce in an unsafe way, and keep constant communication"
Zabbix API与PHP的配置
互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
leetcode:329. 矩阵中的最长递增路径
The data in the database table recursively forms a closed-loop data. How can we get these data
项目中字符串判空总结
Generate random numbers (4-bit, 6-bit)
[leetcode 324] 摆动排序 II 思维+排序
Solid smart contract development - easy to get started
关于重载运算符的再整理