当前位置:网站首页>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.
边栏推荐
- TypeScript:const
- idea中新建的XML文件变成普通文件的解决方法.
- En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
- Microservice development steps (Nacos)
- Solidty智能合约开发-简易入门
- 【15. 区间合并】
- 生成随机数(4位、6位)
- 定了!2022海南二级造价工程师考试时间确定!报名通道已开启!
- Mongodb second call -- implementation of mongodb high availability cluster
- Build MySQL master-slave server under Ubuntu 14.04
猜你喜欢
随机推荐
C#学习笔记(5)类和继承
Error-tf.function-decorated function tried to create variables on non-first call
NPDP产品经理国际认证报名有什么要求?
241. 为运算表达式设计优先级
Don't want to knock the code? Here comes the chance
Zabbix API与PHP的配置
问题随记 —— Oracle 11g 卸载
Develop small programs and official account from zero [phase III]
The markdown editor uses basic syntax
One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
Fundamentals of C language
手把手带你入门 API 开发
JVM second conversation -- JVM memory model and garbage collection
购物商城6.27待完成
Mongodb second talk - - mongodb High available Cluster Implementation
Sqlachemy common operations
微服务开发步骤(nacos)
Word2vec yyds dry goods inventory
Generate random numbers (4-bit, 6-bit)
Configuration of ZABBIX API and PHP









