理解的目的CMake的背后 [英] Understanding the Purpose Behind CMake

查看:201
本文介绍了理解的目的CMake的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解背后C进行的目的。为什么它的设计就像它是现在。这里有一些问题,我想回答。

I am trying to understand the purpose behind CMake. Why it is designed like it is right now. Here are some questions I would like to have answered.


  • 为什么CMake的生成Makefile而不是仅仅建立项目?

  • 为什么CMake的文件的一系列命令,而不仅仅是配置文件,例如:INI / XML / YAML

  • 什么是应该做的,我写的命令到的CMakeLists.txt?只需调用编译器将是太容易我猜

  • 在其中为了我应该做的命令?

  • 一切都区分大小写?我可以写的一切小写?

  • 为什么教程建议我列出所有源文件明确?

  • 如何构建我的CMakeLists.txt让我简短,维护简单。我在实际项目中抬起头来的每个文件都显得很凌乱。

推荐答案

它可以是很难理解的CMake如何工作的。我会尽我所能简单地回答一些您发布的问题。

It can be difficult to understand how CMake works. I'll do my best to briefly answer some of the questions you posted.

为什么CMake的生成Makefile而不是仅仅建立项目?

Why does cmake generate makefiles instead of just building the project?

CMake的是跨平台使系统并为编译器无关。它不会产生只是使构建系统,而且还生成Visual Studio解决方案文件。在相同的CMakeList.txt文件的人可以很容易地创建一个Windows版本(Visual Studio中)或Linux构建(G ++)。

CMake is a cross-platform make system and is compiler independent. It doesn't generate just make build systems, but also generates Visual Studio solution files. With the same CMakeList.txt file someone can easily create a windows build (Visual Studio) or a Linux build (g++).

为什么CMake的文件[系列]命令,而不只是配置文件,例如:INI / XML / YAML

Why are cmake files [a series of] commands and not just configuration files eg: ini/xml/yaml

编译器不使用的通用配置,因此必须的CMake为目标的编译器相适应。

Compilers don't use a universal configuration, so CMake must adapt for the target compiler.

CMake的文件的一系列命令以生成用于目标编译器适当的配置。

CMake files are a series of commands to generate the appropriate configuration for the target compiler.

什么是我写的进入应该做的CMakeLists.txt的命令?只需调用编译器将是太容易我猜

What are the commands that I write into the CMakeLists.txt supposed to do? Just calling the compiler would be too easy I guess

它们假设以生成用于目标编译器适当的配置,它们将如果正确写入。

They are suppose to generate the appropriate configuration for the target compiler, and they will if written correctly.

在这为了我应该做的命令?

In which order am I supposed to do the commands?

在顺序问题,如果订单的问题都没有。是的,它是一个模糊的答案,但是这取决于项目。例如,包括()命令将被用于添加额外的CMake的文件,如果将它们包含在错误的顺序,就可以打破一代的构建系统。

In the order that matters, if the order matters at all. Yes it's a vague answer, but it depends on the project. For example the include() command will be used to add additional cmake files, and if you include them in the wrong order, it can break generation of the build system.

在您的CMake文件中的第一个命令必须是所需的最低版本的CMake的最新版本(3.0.1)。从那里,它依赖。 :)

The first command in your cmake file must be the minimum required version with the latest version of CMake (3.0.1). From there it depends. :)

例如这个命令不会CMake的版本低于2.6工作。
cmake_minimum_required(版本2.6)

For example this command will not work with versions of CMake less than 2.6. cmake_minimum_required (VERSION 2.6)

看到一些教程链接在此答案的结尾。

See some of the tutorial links at the end of this answer.

一切都区分大小写?我可以写的一切小写?

Is everything case insensitive? Can I write everything lower case?

由于对CMake的维基语言的语法页面说明,所有的命令都是区分不敏感的,但你必须考虑的情况下传递给命令的内容。

As stated on the CMake wiki's language syntax page, all of the commands are case insensitive, but you must consider case for contents passed to a command.

为什么教程建议我列出所有源文件明确?

Why do tutorials advise me to list every source file explicitly?

因为你要列出所有源文件中明确。这可以在一个cmake的文件或在cmake的文件中引用一个单独的文件列表内进行。请参阅安东尼奥的回答使用一个单独的文件列表的警告。

Because you have to list every source file explicitly. This can be done inside a cmake file or a separate file list that is referenced in the cmake file. Please see Antonio's answer for a caveat of using a separate file list.

CMake的确实提供了一个命令 aux_source_directory 会聚集在一个指定的目录和存储列表给一个变量的所有源文件的名称,但它应该只用于为生成的源文件在安东尼的答案提到同样的道理。

CMake does provide a command aux_source_directory which collects the names of all the source files in a specified directory and stores the list to a variable, but it should only be used for "generated" source files for the same reason mentioned in Antonio's answer.

如何构建我的CMakeLists.txt以保持它短,维护简单。我在实际项目中抬起头来的每个文件都显得很凌乱。

How do I structure my CMakeLists.txt to keep it short and simple to maintain. Every file I looked up in real projects looked very cluttered.

这很容易弄乱一个CMake的文件,和一个方法来帮助这个是使用.cmake您参考使用包括命令文件。

It's very easy to clutter a CMake file, and one way to help with this is to use .cmake files that you reference using the include command.

一个很好的资源(虽然仍在开发中),可以在 CMake的有关页面

A good resource (although still under development) can be found on the CMake about page.

它分为几个部分:


  1. 概述

  2. 统计(开发中)

  3. 参与者

  4. 文档

  5. 许可证

  6. 成功案例

  7. 出版物

  8. 新闻

  1. Overview
  2. Statistics (under development)
  3. Participants
  4. Documentation
  5. License
  6. Success Stories
  7. Publications
  8. News

教程

CMake的教程 - 从官方的CMake文档页面

CMake Tutorial - From the official CMake documentation page

开始使用CMake - 使用CMake的有A教程海湾合作委员会。

Getting Started With CMake - A tutorial that uses CMake with gcc.

使用cmake来建立QT项目 - 使用CMake的与QT的指南

Using CMake To Build QT Projects - A tutorial that uses CMake with QT.

这篇关于理解的目的CMake的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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