当前位置:网站首页>Cmake tutorial series-01-minimum configuration example
Cmake tutorial series-01-minimum configuration example
2022-06-30 02:37:00 【Ordinary people who like playing basketball】
List of articles
1. With the smallest cmake Configuration as an example
eg:
cmake_minimum_required(VERSION 3.0)
project(sample CXX)
add_library(sample sample.cpp)
add_executable(sample_exe sample_exe.cpp)
2.cmake_minimum_required
- This function specifies the cmake Minimum version .
- because cmake It's still evolving , Each version will modify some function parameters , More functions will also be added . This function is used to prevent the use of too low version cmake To configure an unexpected error .
3.project
This function declares the name of the project .
Because a project may contain multiple libraries or multiple executable programs , In sub Library / It is forbidden to use the same name as in the function declaration in the sub executable .
The second parameter of the function is the code type of the project .
- It can be stated that C or CXX or C CXX.
- The corresponding represents pure c engineering , pure c++ Engineering and mixed engineering .
Be careful : Declared code types affect compiler selection .
As mentioned above , Every cmake All projects should declare this keyword , This affects the properties of the entire project .cmake The corresponding variables of the project will also be provided
- PROJECT_NAME Project name
- PROJECT_SOURCE_DIR Project source code root directory
- PROJECT_VERSION Project version
- PROJECT_BINARY_DIR Temporary binary directories generated by the project , Used to store configuration / Compile intermediate files .
4.add_library / add_executable
The first parameter represents the Library / The name of the executable .
The second parameter represents the source file used by the binary to be generated .
- You can use list variables here .
- You can also add the source file name directly .
- You can also use functions later target_source Add source file .
- Be careful : Statement win32 When the program is executable , Should be in add_executable Add keyword after program name in WIN32 .
add_library You can also add other keywords, such as :
- SHARED Declare that the library is only generated as a dynamic library
- STATIC Declare that the library is only generated as a static library
- OBJECT Declare that target Only intermediate binary file , For others target Use
- INTERFACE Declare that library is only an interface and does not have its own binary
- ALIAS Declare that this library is only an alias for other libraries
- IMPORTED Declare that the library does not need to be built , Instead, the specific configuration has been imported . This method usually exists in the configuration provided by the dependency .
- When the first five keywords are not stated , The build type of the library depends on BUILD_SHARED_LIBS change .
5. keyword target
target stay cmake Is a very important concept , You should understand it as a object.
It contains, for example, the following :
- List of related source files
- Related compilation options
- Related dependency Libraries
- List of related header file paths
- List of related library file paths
- Other related properties
therefore , You can use this later target Name do anything . Corresponding cmake The function will use this name to automatically extract the attribute values that the function needs to use .
6. keyword PUBLC PRIVATE INTERFACE
These keywords are used to build dependencies .
PUBLIC Declare the subsequent values of the keyword in building the target When using , And provide... To the downstream .
PRIVATE Declaring the subsequent values of this keyword is only used to build this target When using , Do not provide downstream .
INTERFACE Declare that the keyword is only provided to downstream , Not building this target When using .
Reference resources :CMake Tutorial series -01- Minimum configuration example
边栏推荐
- Simple distinction between break and continue
- DHU programming exercise
- What is a self signed certificate? Advantages and disadvantages of self signed SSL certificates?
- 并发请求下如何防重复提交
- 归并排序
- How to prevent phishing emails? S/mime mail certificate
- Select sort
- 学术汇报(academic presentation)/PPT应该怎么做?
- Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
- Insert sort directly
猜你喜欢

堆排序

Five cheapest wildcard SSL certificate brands

并发请求下如何防重复提交

Le Code autojs peut - il être chiffré? Oui, présentation des techniques de chiffrement autojs

matlab代码运行教程(如何运行下载的代码)

How vscode debugs into standard library files / third-party package source code

重看《Redis设计与实现》后记录几个要点

Insert sort directly

Bubble sort

Entering Jiangsu writers and poets carmine Jasmine World Book Day
随机推荐
2022年7月深圳地区CPDA数据分析师认证
matlab代码运行教程(如何运行下载的代码)
选择排序
Global and Chinese market of relay lens 2022-2028: Research Report on technology, participants, trends, market size and share
速看 2021-2022年23项重大网络犯罪统计数据
每周推荐短视频:为什么理论正确但得不到预期结果?
What is digicert smart seal?
Implementation of Sanzi chess with C language
Global and Chinese markets for light cargo conveyors 2022-2028: Research Report on technology, participants, trends, market size and share
Insert sort directly
DHU programming exercise
Créer des compétences exquises dans l'éducation des créateurs
有流量,但没有销售?增加网站销量的 6 个步骤
Merge sort
新考纲下的PMP考试有多难?全面解析
Bubble sort
Vs realize quick replacement function
IBM websphere通道联通搭建和测试
DHU programming exercise
SSL证书格式转化的两种方法