使用Makefile和CMake编译代码的区别 [英] Difference between using Makefile and CMake to compile the code

查看:36
本文介绍了使用Makefile和CMake编译代码的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C/C++ 上编写代码并使用 (GNU) Makefile 来编译代码.我可以用 CMake 做同样的事情并得到一个 MakeFile.但是,使用 Makefile 和 CMake 编译代码有什么区别?

I code on C/C++ and use a (GNU) Makefile to compile the code. I can do the same with CMake and get a MakeFile. However, what is the difference between using Makefile and CMake to compile the code?

推荐答案

Make(或者更确切地说是 Makefile)是一个构建系统 - 它驱动编译器和其他构建工具来构建您的代码.

Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code.

CMake 是构建系统的生成器.它可以生成 Makefile,可以生成 Ninja 构建文件,可以生成 KDEvelop 或 Xcode 项目,可以生成 Visual Studio 解决方案.从相同的起点,相同的 CMakeLists.txt 文件.因此,如果您有一个独立于平台的项目,CMake 也是一种使其独立于构建系统的方法.

CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions. From the same starting point, the same CMakeLists.txt file. So if you have a platform-independent project, CMake is a way to make it buildsystem-independent as well.

如果您的 Windows 开发人员习惯了 Visual Studio 和 Unix 开发人员,他们对 GNU Make 发誓,那么 CMake 是(其中一种)可行的方法.

If you have Windows developers used to Visual Studio and Unix developers who swear by GNU Make, CMake is (one of) the way(s) to go.

如果您希望您的项目是多平台或广泛使用的,我总是建议使用 CMake(或其他构建系统生成器,但 CMake 是我个人的偏好).CMake 本身也提供了一些不错的功能,例如依赖项检测、库接口管理或与 CTest、CDash 和 CPack 的集成.

I would always recommend using CMake (or another buildsystem generator, but CMake is my personal preference) if you intend your project to be multi-platform or widely usable. CMake itself also provides some nice features like dependency detection, library interface management, or integration with CTest, CDash and CPack.

使用构建系统生成器可以让您的项目更加面向未来.即使您现在只使用 GNU-Make,如果您以后决定扩展到其他平台(无论是 Windows 还是嵌入式平台),或者只想使用 IDE,该怎么办?

Using a buildsystem generator makes your project more future-proof. Even if you're GNU-Make-only now, what if you later decide to expand to other platforms (be it Windows or something embedded), or just want to use an IDE?

这篇关于使用Makefile和CMake编译代码的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆