CMake--Basic

51 篇文章 6 订阅
31 篇文章 1 订阅

1. CMake概念

	CMake 全名为 cross platform make。
	主要用来处理大型的 C/C++/java 项目。
	CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。

1.1 cmake 和 makefile 关系

makefile 通常依赖于当前的编译平台,而且编写 makefile 的工作量比较大,解决依赖关系时也容易出错。

CMake 恰好能解决上述问题, 其允许开发者指定整个工程的编译流程,
在根据编译平台,自动生成本地化的Makefile和工程文件,最后用户只需 make 编译即可,

所以可以把 CMake 看成一款自动生成 Makefile 的工具

详情如下:
在这里插入图片描述

1.1 cmake、qmake 、

	cmake是抽象层次更高的项目管理工具,cmake命令执行的CMakeLists.txt文件
	qmake是Qt专用的项目管理工具,对应的工程文件是.pro,在Linux下面它也会生成Makefile,
		当然,在命令行下才会需要手动执行qmake,完全可以在qtcreator这个专用的IDE下面打开.pro文件,使用qmake命令的繁琐细节不用你管了。

	make用来执行Makefile,cmake用来执行CMakeLists.txt,qmake用来处理*.pro工程文件。
	Makefile的抽象层次最低,cmake和qmake在Linux等环境下最后还是会生成一个Makefile。
	cmake和qmake支持跨平台,cmake的做法是生成指定编译器的工程文件,而qmake完全自成体系。

如下图,其中cl表示visual studio的编译器,gcc表示linux下的编译器
在这里插入图片描述

2. Install

2.1 Ubuntu安装教程

```bash
安装前首先安装 gcc g++ openSSL
sudo apt update
sudo apt-get install g++
sudo apt-get install libssl-dev

CMake安装有两种方法:
1.使用Linux系统自带的镜像包(可能不是最新的)
	sudo apt install cmake			
2.在官网下载相关版本
	https://cmake.org/download/			#1.下载
	tar -zxv -f cmake-3.17.1.tar.gz		#2.解压
	./bootstrap							#3.进入解压后的cmake文件夹,执行:
	make								#4.编译构建
	sudo make install					#5.安装

自此就安装完成了。

cmake --version 						#验证安装版本
```

3. Common Commands

基础–参考链接

进阶–cmake_minimum_required介绍
进阶–cmake_policy命令
进阶–cmake字符串操作
进阶–为项目输出添加后缀
进阶–缓存变量(Cache Variable)
进阶–include指令(.cmake文件/MACRO宏/function函数)
进阶–find_package命令用法

4. Cmake 创建同名静态库和动态库

参考链接

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMake is a cross-platform open-source build system that is widely used for building software projects. It provides a simple and efficient way to define, configure, and generate build files for various platforms and build environments. To use CMake in Linux, you can follow these steps: 1. Install CMake: You can install CMake from the official website or using your package manager. For example, in Ubuntu, you can use the following command to install it: ``` sudo apt-get install cmake ``` 2. Create a CMakeLists.txt file: Create a text file named "CMakeLists.txt" in the root directory of your project. This file will contain the instructions for building your project. 3. Configure the project: Open a terminal and navigate to your project's root directory. Run the following command to configure your project using CMake: ``` cmake . ``` This command will generate the necessary build files based on the instructions provided in the CMakeLists.txt file. 4. Build the project: After configuring the project, you can build it using the following command: ``` make ``` This command will compile the source code and generate the executable or library files specified in the CMakeLists.txt file. 5. Run the project: Once the build process is complete, you can run your project by executing the generated executable file. These are the basic steps to use CMake in Linux. You can customize the CMakeLists.txt file according to your project's requirements, including specifying source files, libraries, compiler options, etc.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值