I'm looking at starting a new project in C++ - just in my own time initially - and I'm investigating the build systems that are available. It would appear that the answer is "Many, and they're all awful".
我正在考虑用c++启动一个新项目——就在我最初的时候——我正在研究可用的构建系统。答案似乎是“很多,而且都很糟糕”。
The features that I specifically need for this are:
我特别需要的特点是:
- C++11 support
- c++ 11支持
- Cross platform (Linux as main target, but able to build on at least Windows as well)
- 跨平台(主要目标是Linux,但至少可以在Windows上构建)
- Decent unit testing support
- 良好的单元测试支持
- Support for multiple modules for separating code out
- 支持多个模块分离代码
- Support for code generation (Using asn1c or protobuf - not 100% sure yet)
- 支持代码生成(使用asn1c或protobuf -还不是100%确定)
- Easy to maintain
- 易于维护
Now, I know I can do 1-4 of those using CMake and Autotools easily enough. Probably also with SCons and Waf and the couple of others too. The problem is that I've never worked out how to correctly do code generation using them - that is source files that do not exist until the build process is first run, so source files that the build system must be able to convert into executable code but doesn't actually know about until the build starts... (ASN1C in particular generates dozens of header and source files that must be able to work together, and the actual set of files generates depends on the contents of your asn file) There's also the fact that none of these are especially easy to maintain - CMake and Autotools have their own huge set of scripts that you need to manage for them to work, and Waf and Scons require that anybody working with them has decent knowledge of python (I don't) to work with them...
现在,我知道我可以很容易地使用CMake和Autotools来做1-4个。可能还有SCons、Waf和其他一些公司。问题是,我从来没有研究出如何正确做代码生成使用它们——这是源文件不存在,直到第一次运行构建过程,所以源文件构建系统必须能够转换成可执行代码但实际上并不知道,直到构建开始……(特别是ASN1C生成数十头文件和源文件,必须能够一起工作,和实际的文件集生成取决于asn文件)的内容也有这些的事实尤其易于维护,CMake Autotools有自己的巨大的脚本,您需要管理他们的工作,和Waf您需要有人与他们合作有像样的python的知识(我不)与他们合作……
So - what build systems are recommended for something like this? Or will I be stuck with make files and shell scripts for now?
那么,什么样的构建系统被推荐给这样的东西呢?或者,我现在还需要做文件和shell脚本吗?
8 个解决方案
#1
102
+1 for, "Many, and they're awful."
+1表示“很多,而且很糟糕。”
But, the "richest" and "most-scalable" is probably CMake, which is a Makefile-generator (also generates native MSVC++ *.proj
/*.sln
). Weird syntax, but once you learn it, it can allow you to nicely generate builds for different platforms. If I "started-fresh", I'd probably use CMake
. It should handle your list, although your "code-generation" could take on "a-life-of-its-own" beyond the build system depending on what you want to do. (See below.)
但是,“最富有的”和“最可扩展的”可能是CMake,它是一个makefile生成器(也生成本地MSVC++ *.proj/*.sln)。奇怪的语法,但是一旦您学习了它,它就可以很好地为不同的平台生成构建。如果我“新鲜出炉”,我可能会用CMake。它应该处理您的列表,尽管您的“代码生成”可以根据您想要做的事情,在构建系统之外采用“独立的生命”。(见下文)。
For simple projects, the QMake generator is ok (you don't need to use the Qt libraries to use QMake). But, you're not describing "simple" -- code generation and "extra-phases" means you probably want CMake
or something with a rich API for your own extensions, like Scons
(or Waf
).
对于简单的项目,QMake生成器是ok的(您不需要使用Qt库来使用QMake)。但是,您并不是在描述“简单的”——代码生成和“额外阶段”,这意味着您可能希望CMake或其他具有丰富API的插件,比如Scons(或Waf)。
We use Scons at work. It produces "bullet-proof-builds", but it's really slow. No other system will be as bullet-proof as Scons
. But, it's slow. It is written in Python and we've extended the interface for our "workspace-organization" (where we merely specify module dependencies), and that is part of the Scons
design intent (this type of extension through Python). Convenient, but builds are slow. You get bullet-proof builds (any developer box can make the final release), but it's slow. And, it's slow. Don't forget that if you use Scons
, though, that it's slow. And, it's slow.
我们在工作中使用Scons。它会生成“项目验证构建”,但速度非常慢。没有其他系统会像Scons一样防弹。但是,它的缓慢。它是用Python编写的,我们扩展了“工作空间组织”的接口(我们只指定模块依赖关系),这是Scons设计意图的一部分(通过Python实现的这种类型的扩展)。很方便,但是构建是缓慢的。您可以得到防弹的构建(任何开发人员框都可以生成最终版本),但是它很慢。它是缓慢的。不要忘记,如果你使用Scons,它会很慢。它是缓慢的。
It makes me ill to think that a decade after the Year 2000, we still don't have flying cars. We'll probably have to wait another hundred years or something to get them. And, we will then all probably be flying around in our flying cars that are still being constructed with crappy build systems.
我很难想象,在2000年后的十年里,我们仍然没有会飞的汽车。我们可能得再等上一百年才能得到它们。然后,我们很可能会乘坐我们的飞车到处飞,这些飞车仍然是用糟糕的建筑系统建造的。
Yes, they are all awful.
是的,都很糟糕。
[ABOUT CODE GENERATION]
(对代码生成)
Scons
works on "phases", and they are "somewhat-static". It can build code that is generated as part of the build (people are doing this in a couple of different ways), but this has been described as, "something very un-Scons-like".
Scons在“阶段”工作,它们是“某种静态的”。它可以构建作为构建的一部分生成的代码(人们以几种不同的方式进行此工作),但是这被描述为“非常不符合标准的东西”。
If it's simple "preprocess some files and generate source files", then no biggie (you have lots of options, and this is why qmake
was written -- for the moc
preprocessing of *.hpp/*.cpp
files).
如果它是简单的“预处理一些文件并生成源文件”,那么就没有大问题(您有很多选项,这就是为什么编写qmake——用于*.hpp/*的moc预处理。cpp文件)。
However, if you are doing this in a "heavy-manner", you're going to need to script your own. For example, we had as-a-part-of-the-build scripts that queried the databases and generated C++ classes to interface between the "layers" (in traditional 3-tier application development). Similarly, we generated server/client source code through IDLs, and embedded version information to permit multiple clients/servers to run simultaneously with different versions (for the same "client" or "server"). Lots of generated source code. We could "pretend" that is "the-build-system", but really, it's a non-trivial-infrastructure for "configuration management", of which part of it is the "build-system". For example, this system had to, "take-down" and "start-up" servers as a part of this process. Similarly, the regression-tests were executed as a part of this process, with heavy "reporting" and "difference-testing" between versions -- all as a part of our "build-scripts".
然而,如果您正在以一种“沉重的方式”进行此操作,您将需要编写自己的脚本。例如,我们有作为构建部分的脚本,该脚本查询数据库并生成c++类以在“层”之间进行接口(在传统的三层应用程序开发中)。类似地,我们通过IDLs生成服务器/客户端源代码,以及嵌入的版本信息,允许多个客户机/服务器同时运行不同的版本(对于相同的“客户端”或“服务器”)。大量生成的源代码。我们可以“假装”这是“构建系统”,但实际上,它是“配置管理”的非日常基础设施,其中一部分是“构建系统”。例如,这个系统必须将“拆卸”和“启动”服务器作为这个过程的一部分。类似地,回归测试作为这个过程的一部分执行,在版本之间进行大量的“报告”和“差异测试”——所有这些都是“构建脚本”的一部分。
#2
32
You can use Gradle now: https://docs.gradle.org/current/userguide/native_software.html
现在可以使用Gradle: https://docs.gradle.org/current/userguide/native_software.html
This seems to have matured quite a bit in the years since I originally posted this. The page saying that the project is "incubating" has disappeared, but I can't find any official announcement removing this status.
自从我发布这篇文章以来,这似乎已经成熟了不少。说这个项目正在“孵化”的页面已经消失了,但是我找不到任何官方声明删除这个状态。
#3
14
I recently found out about these, I have not personally used them yet:
我最近发现这些,我还没有亲自使用过:
Ninja, a small build system focused on speed. Google now uses Ninja to build Android instead of Make: link.
忍者,一个专注于速度的小型建筑系统。谷歌现在使用Ninja来构建Android,而不是Make: link。
Shake, a powerful and fast build system.
Shake是一个强大而快速的构建系统。
Tup, a high performance build system. Algorithmic based design. Analysis of Tup.
一个高性能的构建系统。基于算法的设计。锤头的分析。
All are now cross-platform and support Windows. I'm not yet sure about the rest of your requirements as, again, I have yet to test them myself. They are being used in commercial development, CIG picked Ninja up. First two are akin to Scons, Ant, etc.
所有这些现在都是跨平台和支持窗口。我还不确定你的其他要求,因为我还没有亲自测试。他们被用于商业开发,CIG挑选忍者。前两个类似于Scons, Ant等。
#4
10
Scons is very friendly and flexible system, but you right, Lothar, it really slow.
Scons是个非常友好和灵活的系统,但是你说的对,洛塔尔,它真的很慢。
But there is a way to increase the performance of programs written in Python. This use of the JIT. Of all known projects, PyPy is a very powerful, fast-growing and motivated JIT-backed - Python 2.7 implementation. PyPy compatibility with Python 2.7 is simply amazing. However, Scons declared as unsupported project on the PyPy compatibility wiki. Waf, on the other hand, modeled as python-based autotools sucessor, is fully supported by PyPy infrastructure. In my projects the speed of the assembly has increased 5-7 times in the transition to PyPy. You can see the performance reports from PyPy.
但是有一种方法可以提高用Python编写的程序的性能。JIT的使用。在所有已知的项目中,PyPy是一个非常强大的、快速增长的、受jit支持的Python 2.7实现。PyPy与Python 2.7的兼容性简直太棒了。然而,在PyPy兼容性wiki上,Scons声明为不受支持的项目。另一方面,Waf被建模为基于python的autotools sucessor,完全由PyPy基础结构支持。在我的项目中,在过渡到PyPy时,程序集的速度增加了5-7倍。您可以看到PyPy的性能报告。
For modern and relatively fast build system Waf is good choice.
对于现代和相对快速的构建系统来说,Waf是很好的选择。
#6
6
I used SCons and am impressed by this build system. SCons is extensible by python and python itself - it's great, because Python has all that you need, just code the logic, all the low-level functionality is already implemented in SCons and Python and is crossplatform. If have good programming skills then your build scripts will be looking perfect and easy.
我使用了SCons,并对这个构建系统印象深刻。SCons是由python和python本身可扩展的——这很好,因为python有您需要的所有功能,只需编写逻辑代码,所有的底层功能都已经在SCons和python中实现,并且是交叉格式。如果您有良好的编程技能,那么您的构建脚本将看起来完美而简单。
Make, CMake and similar build systems seems as trash of macroses. Waf is SCons analog. I'm trying Waf but SCons will be more friendly and so I stayed with SCons.
Make、CMake和类似的构建系统似乎都是宏的垃圾。Waf您模拟。我在试Waf,但是SCons会更友好一些,所以我和SCons在一起。
By crowd opinion SCons is too slow, but in the middle of a project I didn't see any difference between make and SCons by build speed. Instead, SCons has well worked with parallel builds, while make has big troubles with it.
人们认为SCons太慢了,但在一个项目中,我并没有看到build speed对make和SCons的区别。相反,SCons很好地处理了并行构建,而make却有很大的问题。
Also, SCons allows you to get - configure, build, deploy, generate configuration from templates, run tests and do any other task that can be done can coding with python and SCons - all in one. That is a very big advantage.
此外,SCons允许您从模板中获取——配置、构建、部署、生成配置、运行测试,以及执行任何其他可以通过python和SCons进行编码的任务——所有这些都可以合并在一起。这是一个很大的优势。
For a simple project CMake is also a good choice.
对于一个简单的项目来说,CMake也是一个不错的选择。
#7
5
just to add my cents: premake
只是为了增加我的钱:预制。
http://industriousone.com/premake
http://industriousone.com/premake
there is also a dedicated webpage on the wiki.
维基上还有一个专门的网页。
#8
2
You can use Ceedling. Note, however it only supports C at the moment and it is tightly coupled to the author's Unity and CMock testing frameworks.
您可以使用Ceedling。注意,它目前只支持C,并且与作者的Unity和CMock测试框架紧密耦合。
It can be forked and modified to work with a C++ compiler and unit testing / mocking framework fairly easily.
可以对它进行分叉和修改,以便与c++编译器和单元测试/ mock框架一起工作。
Also Tup is a worthy mention. It is extremely fast but it knows nothing about testing frameworks etc. which means you'll have to write your own build system using Tup. If you plan on doing TDD, Tup is probably the way to go.
同样,Tup也是值得一提的。它非常快,但是它对测试框架一无所知,这意味着您必须使用Tup编写自己的构建系统。如果你计划去做TDD,那你可能就该走了。
#1
102
+1 for, "Many, and they're awful."
+1表示“很多,而且很糟糕。”
But, the "richest" and "most-scalable" is probably CMake, which is a Makefile-generator (also generates native MSVC++ *.proj
/*.sln
). Weird syntax, but once you learn it, it can allow you to nicely generate builds for different platforms. If I "started-fresh", I'd probably use CMake
. It should handle your list, although your "code-generation" could take on "a-life-of-its-own" beyond the build system depending on what you want to do. (See below.)
但是,“最富有的”和“最可扩展的”可能是CMake,它是一个makefile生成器(也生成本地MSVC++ *.proj/*.sln)。奇怪的语法,但是一旦您学习了它,它就可以很好地为不同的平台生成构建。如果我“新鲜出炉”,我可能会用CMake。它应该处理您的列表,尽管您的“代码生成”可以根据您想要做的事情,在构建系统之外采用“独立的生命”。(见下文)。
For simple projects, the QMake generator is ok (you don't need to use the Qt libraries to use QMake). But, you're not describing "simple" -- code generation and "extra-phases" means you probably want CMake
or something with a rich API for your own extensions, like Scons
(or Waf
).
对于简单的项目,QMake生成器是ok的(您不需要使用Qt库来使用QMake)。但是,您并不是在描述“简单的”——代码生成和“额外阶段”,这意味着您可能希望CMake或其他具有丰富API的插件,比如Scons(或Waf)。
We use Scons at work. It produces "bullet-proof-builds", but it's really slow. No other system will be as bullet-proof as Scons
. But, it's slow. It is written in Python and we've extended the interface for our "workspace-organization" (where we merely specify module dependencies), and that is part of the Scons
design intent (this type of extension through Python). Convenient, but builds are slow. You get bullet-proof builds (any developer box can make the final release), but it's slow. And, it's slow. Don't forget that if you use Scons
, though, that it's slow. And, it's slow.
我们在工作中使用Scons。它会生成“项目验证构建”,但速度非常慢。没有其他系统会像Scons一样防弹。但是,它的缓慢。它是用Python编写的,我们扩展了“工作空间组织”的接口(我们只指定模块依赖关系),这是Scons设计意图的一部分(通过Python实现的这种类型的扩展)。很方便,但是构建是缓慢的。您可以得到防弹的构建(任何开发人员框都可以生成最终版本),但是它很慢。它是缓慢的。不要忘记,如果你使用Scons,它会很慢。它是缓慢的。
It makes me ill to think that a decade after the Year 2000, we still don't have flying cars. We'll probably have to wait another hundred years or something to get them. And, we will then all probably be flying around in our flying cars that are still being constructed with crappy build systems.
我很难想象,在2000年后的十年里,我们仍然没有会飞的汽车。我们可能得再等上一百年才能得到它们。然后,我们很可能会乘坐我们的飞车到处飞,这些飞车仍然是用糟糕的建筑系统建造的。
Yes, they are all awful.
是的,都很糟糕。
[ABOUT CODE GENERATION]
(对代码生成)
Scons
works on "phases", and they are "somewhat-static". It can build code that is generated as part of the build (people are doing this in a couple of different ways), but this has been described as, "something very un-Scons-like".
Scons在“阶段”工作,它们是“某种静态的”。它可以构建作为构建的一部分生成的代码(人们以几种不同的方式进行此工作),但是这被描述为“非常不符合标准的东西”。
If it's simple "preprocess some files and generate source files", then no biggie (you have lots of options, and this is why qmake
was written -- for the moc
preprocessing of *.hpp/*.cpp
files).
如果它是简单的“预处理一些文件并生成源文件”,那么就没有大问题(您有很多选项,这就是为什么编写qmake——用于*.hpp/*的moc预处理。cpp文件)。
However, if you are doing this in a "heavy-manner", you're going to need to script your own. For example, we had as-a-part-of-the-build scripts that queried the databases and generated C++ classes to interface between the "layers" (in traditional 3-tier application development). Similarly, we generated server/client source code through IDLs, and embedded version information to permit multiple clients/servers to run simultaneously with different versions (for the same "client" or "server"). Lots of generated source code. We could "pretend" that is "the-build-system", but really, it's a non-trivial-infrastructure for "configuration management", of which part of it is the "build-system". For example, this system had to, "take-down" and "start-up" servers as a part of this process. Similarly, the regression-tests were executed as a part of this process, with heavy "reporting" and "difference-testing" between versions -- all as a part of our "build-scripts".
然而,如果您正在以一种“沉重的方式”进行此操作,您将需要编写自己的脚本。例如,我们有作为构建部分的脚本,该脚本查询数据库并生成c++类以在“层”之间进行接口(在传统的三层应用程序开发中)。类似地,我们通过IDLs生成服务器/客户端源代码,以及嵌入的版本信息,允许多个客户机/服务器同时运行不同的版本(对于相同的“客户端”或“服务器”)。大量生成的源代码。我们可以“假装”这是“构建系统”,但实际上,它是“配置管理”的非日常基础设施,其中一部分是“构建系统”。例如,这个系统必须将“拆卸”和“启动”服务器作为这个过程的一部分。类似地,回归测试作为这个过程的一部分执行,在版本之间进行大量的“报告”和“差异测试”——所有这些都是“构建脚本”的一部分。
#2
32
You can use Gradle now: https://docs.gradle.org/current/userguide/native_software.html
现在可以使用Gradle: https://docs.gradle.org/current/userguide/native_software.html
This seems to have matured quite a bit in the years since I originally posted this. The page saying that the project is "incubating" has disappeared, but I can't find any official announcement removing this status.
自从我发布这篇文章以来,这似乎已经成熟了不少。说这个项目正在“孵化”的页面已经消失了,但是我找不到任何官方声明删除这个状态。
#3
14
I recently found out about these, I have not personally used them yet:
我最近发现这些,我还没有亲自使用过:
Ninja, a small build system focused on speed. Google now uses Ninja to build Android instead of Make: link.
忍者,一个专注于速度的小型建筑系统。谷歌现在使用Ninja来构建Android,而不是Make: link。
Shake, a powerful and fast build system.
Shake是一个强大而快速的构建系统。
Tup, a high performance build system. Algorithmic based design. Analysis of Tup.
一个高性能的构建系统。基于算法的设计。锤头的分析。
All are now cross-platform and support Windows. I'm not yet sure about the rest of your requirements as, again, I have yet to test them myself. They are being used in commercial development, CIG picked Ninja up. First two are akin to Scons, Ant, etc.
所有这些现在都是跨平台和支持窗口。我还不确定你的其他要求,因为我还没有亲自测试。他们被用于商业开发,CIG挑选忍者。前两个类似于Scons, Ant等。
#4
10
Scons is very friendly and flexible system, but you right, Lothar, it really slow.
Scons是个非常友好和灵活的系统,但是你说的对,洛塔尔,它真的很慢。
But there is a way to increase the performance of programs written in Python. This use of the JIT. Of all known projects, PyPy is a very powerful, fast-growing and motivated JIT-backed - Python 2.7 implementation. PyPy compatibility with Python 2.7 is simply amazing. However, Scons declared as unsupported project on the PyPy compatibility wiki. Waf, on the other hand, modeled as python-based autotools sucessor, is fully supported by PyPy infrastructure. In my projects the speed of the assembly has increased 5-7 times in the transition to PyPy. You can see the performance reports from PyPy.
但是有一种方法可以提高用Python编写的程序的性能。JIT的使用。在所有已知的项目中,PyPy是一个非常强大的、快速增长的、受jit支持的Python 2.7实现。PyPy与Python 2.7的兼容性简直太棒了。然而,在PyPy兼容性wiki上,Scons声明为不受支持的项目。另一方面,Waf被建模为基于python的autotools sucessor,完全由PyPy基础结构支持。在我的项目中,在过渡到PyPy时,程序集的速度增加了5-7倍。您可以看到PyPy的性能报告。
For modern and relatively fast build system Waf is good choice.
对于现代和相对快速的构建系统来说,Waf是很好的选择。
#5
#6
6
I used SCons and am impressed by this build system. SCons is extensible by python and python itself - it's great, because Python has all that you need, just code the logic, all the low-level functionality is already implemented in SCons and Python and is crossplatform. If have good programming skills then your build scripts will be looking perfect and easy.
我使用了SCons,并对这个构建系统印象深刻。SCons是由python和python本身可扩展的——这很好,因为python有您需要的所有功能,只需编写逻辑代码,所有的底层功能都已经在SCons和python中实现,并且是交叉格式。如果您有良好的编程技能,那么您的构建脚本将看起来完美而简单。
Make, CMake and similar build systems seems as trash of macroses. Waf is SCons analog. I'm trying Waf but SCons will be more friendly and so I stayed with SCons.
Make、CMake和类似的构建系统似乎都是宏的垃圾。Waf您模拟。我在试Waf,但是SCons会更友好一些,所以我和SCons在一起。
By crowd opinion SCons is too slow, but in the middle of a project I didn't see any difference between make and SCons by build speed. Instead, SCons has well worked with parallel builds, while make has big troubles with it.
人们认为SCons太慢了,但在一个项目中,我并没有看到build speed对make和SCons的区别。相反,SCons很好地处理了并行构建,而make却有很大的问题。
Also, SCons allows you to get - configure, build, deploy, generate configuration from templates, run tests and do any other task that can be done can coding with python and SCons - all in one. That is a very big advantage.
此外,SCons允许您从模板中获取——配置、构建、部署、生成配置、运行测试,以及执行任何其他可以通过python和SCons进行编码的任务——所有这些都可以合并在一起。这是一个很大的优势。
For a simple project CMake is also a good choice.
对于一个简单的项目来说,CMake也是一个不错的选择。
#7
5
just to add my cents: premake
只是为了增加我的钱:预制。
http://industriousone.com/premake
http://industriousone.com/premake
there is also a dedicated webpage on the wiki.
维基上还有一个专门的网页。
#8
2
You can use Ceedling. Note, however it only supports C at the moment and it is tightly coupled to the author's Unity and CMock testing frameworks.
您可以使用Ceedling。注意,它目前只支持C,并且与作者的Unity和CMock测试框架紧密耦合。
It can be forked and modified to work with a C++ compiler and unit testing / mocking framework fairly easily.
可以对它进行分叉和修改,以便与c++编译器和单元测试/ mock框架一起工作。
Also Tup is a worthy mention. It is extremely fast but it knows nothing about testing frameworks etc. which means you'll have to write your own build system using Tup. If you plan on doing TDD, Tup is probably the way to go.
同样,Tup也是值得一提的。它非常快,但是它对测试框架一无所知,这意味着您必须使用Tup编写自己的构建系统。如果你计划去做TDD,那你可能就该走了。