当前位置:网站首页>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.
边栏推荐
- leetcode:329. 矩阵中的最长递增路径
- Music player development example (can be set up)
- Salesforce, Johns Hopkins, Columbia | progen2: exploring the boundaries of protein language models
- 微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南
- TypeScript:var
- NPDP能给产品经理带来什么价值?你都知道了吗?
- [stage life summary] I gave up the postgraduate entrance examination and participated in the work. I have successfully graduated and just received my graduation certificate yesterday
- [zero basic IOT pwn] reproduce Netgear wnap320 rce
- JVM第二话 -- JVM内存模型以及垃圾回收
- Mongodb second call -- implementation of mongodb high availability cluster
猜你喜欢
[getting started with Django] 13 page Association MySQL "multi" field table (check)
Guess lantern riddles, not programmers still can't understand?
竣达技术丨多台精密空调微信云监控方案
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
C#学习笔记(5)类和继承
Official announcement: Apache Doris graduated successfully and became the top project of ASF!
One of the first steps to redis
定了!2022海南二级造价工程师考试时间确定!报名通道已开启!
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
JVM second conversation -- JVM memory model and garbage collection
随机推荐
[leetcode 324] swing sorting II thinking + sorting
Official announcement: Apache Doris graduated successfully and became the top project of ASF!
tensorflow2-savedmodel convert to tflite
Don't want to knock the code? Here comes the chance
Demand prioritization method based on value quantification
手把手带你入门 API 开发
Mongodb second call -- implementation of mongodb high availability cluster
Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界
MongoDB第二話 -- MongoDB高可用集群實現
643. Maximum average number of subarrays I
C learning notes (5) class and inheritance
Quelle valeur le pdnp peut - il apporter aux gestionnaires de produits? Vous savez tout?
Markdown编辑器使用基本语法
MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
ArrayList 扩容详解,扩容原理[通俗易懂]
Reorganize the trivial knowledge points at the end of the term
qt捕获界面为图片或label显示
[getting started with Django] 13 page Association MySQL "multi" field table (check)
In hot summer, please put away this safe gas use guide!
opencv学习笔记五--文件扫描+OCR文字识别