当前位置:网站首页>Cmake basic learning
Cmake basic learning
2022-07-29 00:05:00 【Dusk vending machine】
CMake
CMake brief introduction
CMake It's a cross platform 、 Open source build system , A set of software construction 、 test 、 Packaged software . It uses configuration files independent of the platform and compiler to control the software compilation process .
One First time to know CMake
Use a very simple example :
Under the new project folder , Create the following two files
$ tree
.
├── CMakeLists.txt
└── main.cpp
CMakelists.txt The contents of the file in are as follows
# Set the minimum version of CMake that can be used
# To find the cmake version run
# $ cmake --version
cmake_minimum_required(VERSION 3.5)
# Set the project name
project (hello_cmake)
# Add an executable
add_executable(hello_cmake main.cpp)
main.cpp Is a simple C++ Program
#include<iostream>
using namespace std;
int main(){
cout <<" hello word !"<<endl;
return 0;
}
About CMakelists.txt We will explain the contents in later , Let's compile and run the whole program first .
Binary Directory
function cmake command The root folder or top-level folder of is called CMAKE_BINARY_DIR, Is the root folder of all binaries .CMake And support to build and generate binary files in place , It also supports the construction and generation of binary files outside the source code .
In place construction
Build in place will generate all temporary files in the folder where the source code is located , Make the source code and temporary files mixed together , This will be very inconvenient .
We execute cmake . command , Pay attention to the symbols “ . ” Means to execute in the current directory .
$ cmake .
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/panlichen/miniconda3/envs/oneflow-dev-gcc7-v2/bin/x86_64-conda_cos6-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/panlichen/miniconda3/envs/oneflow-dev-gcc7-v2/bin/x86_64-conda_cos6-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/panlichen/zrk/hello_cmake
$ tree
.
├── CMakeCache.txt
├── CMakeFiles
│ ├── 3.18.2
│ │ ├── CMakeCCompiler.cmake
│ │ ├── CMakeCXXCompiler.cmake
│ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ ├── CMakeSystem.cmake
│ │ ├── CompilerIdC
│ │ │ ├── a.out
│ │ │ ├── CMakeCCompilerId.c
│ │ │ └── tmp
│ │ └── CompilerIdCXX
│ │ ├── a.out
│ │ ├── CMakeCXXCompilerId.cpp
│ │ └── tmp
│ ├── cmake.check_cache
│ ├── CMakeDirectoryInformation.cmake
│ ├── CMakeOutput.log
│ ├── CMakeTmp
│ ├── hello_cmake.dir
│ │ ├── build.make
│ │ ├── cmake_clean.cmake
│ │ ├── DependInfo.cmake
│ │ ├── depend.make
│ │ ├── flags.make
│ │ ├── link.txt
│ │ └── progress.make
│ ├── Makefile2
│ ├── Makefile.cmake
│ ├── progress.marks
│ └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── main.cpp
└── Makefile
8 directories, 28 files
It can be seen that it has been successfully generated makefile file , Next we make once , And implement
$ make
$ ./hello_cmake
hello word !
When modifying code , There is no increase or decrease in source file modification CMakeLists.txt Just... Again make
Out of source construction ( recommend )
Build out of source , You can create a single build folder , This folder can be located anywhere on the file system . All temporary build target files are located in this directory , To keep the source directory structure clean .
We create a build Folder , stay build Execute under folder command :
cmake + CMakeLists.txt Location path
$ tree ..
..
├── build
├── CMakeLists.txt
└── main.cpp
$ cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/panlichen/miniconda3/envs/oneflow-dev-gcc7-v2/bin/x86_64-conda_cos6-linux-gnu-cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/panlichen/miniconda3/envs/oneflow-dev-gcc7-v2/bin/x86_64-conda_cos6-linux-gnu-c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/panlichen/zrk/hello_cmake/build
$ make
Scanning dependencies of target hello_cmake
[ 50%] Building CXX object CMakeFiles/hello_cmake.dir/main.cpp.o
[100%] Linking CXX executable hello_cmake
[100%] Built target hello_cmake
$ ./hello_cmake
hello word !
After off source construction , The directory structure is as follows
$ tree ..
..
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.18.2
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── a.out
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ └── tmp
│ │ │ └── CompilerIdCXX
│ │ │ ├── a.out
│ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ └── tmp
│ │ ├── cmake.check_cache
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── CMakeOutput.log
│ │ ├── CMakeTmp
│ │ ├── hello_cmake.dir
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── CXX.includecache
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.internal
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ ├── main.cpp.o
│ │ │ └── progress.make
│ │ ├── Makefile2
│ │ ├── Makefile.cmake
│ │ ├── progress.marks
│ │ └── TargetDirectories.txt
│ ├── cmake_install.cmake
│ ├── hello_cmake
│ └── Makefile
├── CMakeLists.txt
└── main.cpp
9 directories, 32 files
边栏推荐
- Apple's official website is being updated to maintain the apple store. Products such as the iPhone 13 / pro of the Bank of China will enjoy a maximum discount of 600 yuan
- Real time data warehouse: meituan reviews Flink's real-time data warehouse application sharing
- 数据中台的那些“经验与陷阱”
- SAP temporary tablespace error handling
- 1-8 props的基础使用
- 【微服务】Nacos集群搭建以及加载文件配置
- 【C】替换空格,宏实现整数的二进制奇偶位交换
- Wildcard ssl/tls certificate
- EN 1935建筑五金.单轴铰链—CE认证
- Leetcode64. Minimum path sum
猜你喜欢

pycharm新建项目

Explanation of history and chemical properties of Worthington ribonuclease B

Pycharm configuring the running environment

NAT如何配置地址转换

Leetcode62. Different paths

【C】 Introduction and Simulation Implementation of ATOI and offsetof

【MySQL系列】MySQL数据库基础

基于 FPGA 实现数字时钟详细原理讲解及验证结果

Have passed hcip and joined the company of your choice, and share the learning experience and experience of Huawei certification

RHCE first day
随机推荐
JS advanced ES6 ~ es13 new features
mysql索引失效的常见9种原因详解
EN 12101-8:2011 smoke dampers for smoke and heat control systems - CE certification
Pycharm configuring the running environment
After SAP Oracle replicates a new instance, the remote connection of the database reports an error ora-01031
Briefly introduce the working principle and characteristics of block cipher encryption block link mode (cryptography shift cipher encryption and decryption)
The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
Jincang database kingbasees client programming interface guide ODBC (2. Overview)
Compatibility description between kingbasees and Oracle (5. Pl/sql)
1-8 props的基础使用
JS高级 之 ES6~ES13 新特性
Review of categories 1-4
Leetcode61. 旋转链表
centos7安装mysql8
CANoe应用案例之DoIP通信
NAT如何配置地址转换
Working principle of fastdfs (technical principle)
PHP poster QR code synthesis
Interpretation of ISO 13400 (doip) standard
Leetcode63. 不同路径 II