Autotools, Cmake和Scons之间有什么区别?


了解Autotools的重要一点是,它们不是一个通用的构建系统——它们只实现GNU编码标准。如果您想要制作一个遵循所有GNU标准的包,那么Autotools是一个很好的工具。如果你没有,那么你应该使用Scons或CMake。(例如,请看这个问题。)这个常见的误解是使用Autotools的大部分挫败感的来源。


这与GNU编码标准无关。

autotools目前的好处——特别是与automake一起使用时——是它们与构建Linux发行版集成得非常好。

以cmake为例,它总是“我需要的是-DCMAKE_CFLAGS还是-DCMAKE_C_FLAGS ?”不,都不是,它是"-DCMAKE_C_FLAGS_RELEASE"。或-DCMAKE_C_FLAGS_DEBUG。这很令人困惑-在autoconf中,它只是。/configure CFLAGS="- o0 -ggdb3"然后你就有了它。

在与构建基础架构集成时,scons存在不能使用make %{?_smp_mflags},在本例中,_smp_mflags是一个RPM宏,它大致扩展到(管理员可以设置它)系统功率。人们把- jncpu之类的东西放在他们的环境中。使用scons是不行的,所以使用scons的包只能在发行版中被序列化。


An important distinction must be made between who uses the tools. Cmake is a tool that must be used by the user when building the software. The autotools are used to generate a distribution tarball that can be used to build the software using only the standard tools available on any SuS compliant system. In other words, if you are installing software from a tarball that was built using the autotools, you are not using the autotools. On the other hand, if you are installing software that uses Cmake, then you are using Cmake and must have it installed to build the software.

The great majority of users do not need to have the autotools installed on their box. Historically, much confusion has been caused because many developers distribute malformed tarballs that force the user to run autoconf to regenerate the configure script, and this is a packaging error. More confusion has been caused by the fact that most major linux distributions install multiple versions of the autotools, when they should not be installing any of them by default. Even more confusion is caused by developers attempting to use a version control system (eg cvs, git, svn) to distribute their software rather than building tarballs.


事实上,Autotools唯一真正的“可取之处”是它是所有GNU项目都在大量使用的。

Autotools的问题:

Truly ARCANE m4 macro syntax combined with verbose, twisted shell scripting for tests for "compatibility", etc. If you're not paying attention, you will mess up cross-compilation ability (It should clearly be noted that Nokia came up with Scratchbox/Scratchbox2 to side-step highly broken Autotools build setups for Maemo/Meego.) If you, for any reason, have fixed, static paths in your tests, you're going to break cross-compile support because it won't honor your sysroot specification and it'll pull stuff from out of your host system. If you break cross-compile support, it renders your code unusable for things like OpenEmbedded and makes it "fun" for distributions trying to build their releases on a cross-compiler instead of on target. Does a HUGE amount of testing for problems with ancient, broken compilers that NOBODY currently uses with pretty much anything production in this day and age. Unless you're building something like glibc, libstdc++, or GCC on a truly ancient version of Solaris, AIX, or the like, the tests are a waste of time and are a source for many, many potential breakages of things like mentioned above. It is pretty much a painful experience to get an Autotools setup to build usable code for a Windows system. (While I've little use for Windows, it is a serious concern if you're developing purportedly cross-platform code.) When it breaks, you're going to spend HOURS chasing your tail trying to sort out the things that whomever wrote the scripting got wrong to sort out your build (In fact, this is what I'm trying to do (or, rather, rip out Autotools completely- I doubt there's enough time in the rest of this month to sort the mess out...) for work right now as I'm typing this. Apache Thrift has one of those BROKEN build systems that won't cross-compile.) The "normal" users are actually NOT going to just do "./configure; make"- for many things, they're going to be pulling a package provided by someone, like out of a PPA, or their distribution vendor. "Normal" users aren't devs and aren't grabbing tarballs in many cases. That's snobbery on everyone's part for presuming that is going to be the case there. The typical users for tarballs are devs doing things, so they're going to get slammed with the brokenness if it's there.

It works...most of the time...is all you can say about Autotools. It's a system that solves several problems that only really concerns the GNU project...for their base, core toolchain code. (Edit (05/24/2014): It should be noted that this type of concern is a potentially BAD thing to be worrying about- Heartbleed partially stemmed from this thinking and with correct, modern systems, you really don't have any business dealing with much of what Autotools corrects for. GNU probably needs to do a cruft removal of the codebase, in light of what happened with Heartbleed) You can use it to do your project and it might work nicely for a smallish project that you don't expect to work anywhere except Linux or where the GNU toolchain is clearly working correctly on. The statement that it "integrates nicely with Linux" is quite the bold statement and quite incorrect. It integrates with the GNU toolsuite reasonably well and solves problems that IT has with it's goals.

这并不是说本文讨论的其他选项没有问题。

SCons更像是Make/GMake等的替代品。从各方面来看,看起来都很不错。

It is still really more of a POSIX only tool. You could probably more easily get MinGW to build Windows stuff with this than with Autotools, but it's still really more geared to doing POSIX stuff and you'd need to install Python and SCons to use it. It has issues doing cross-compilation unless you're using something like Scratchbox2. Admittedly slower and less stable than CMake from their own comparison. They come up with half-hearted (the POSIX side needs make/gmake to build...) negatives for CMake compared to SCons. (As an aside, if you're needing THAT much extensibility over other solutions, you should be asking yourself whether your project's too complicated...)

在这个线程中给出的CMake的例子有点假。

然而……

你需要学习一门新的语言。 如果你习惯了Make、SCons或Autotools,就会有一些反直觉的事情。 您需要在正在构建的系统上安装CMake。 如果没有预先构建的二进制文件,则需要一个可靠的c++编译器。

事实上,你的目标应该决定你在这里的选择。

Do you need to deal with a LOT of broken toolchains to produce a valid working binary? If yes, you may want to consider Autotools, being aware of the drawbacks I mentioned above. CMake can cope with a lot of this, but it worries less with it than Autotools does. SCons can be extended to worry about it, but it's not an out-of-box answer there. Do you have a need to worry about Windows targets? If so, Autotools should be quite literally out of the running. If so, SCons may/may not be a good choice. If so, CMake's a solid choice. Do you have a need to worry about cross-compilation (Universal apps/libraries, things like Google Protobufs, Apache Thrift, etc. SHOULD care about this...)? If so, Autotools might work for you so long as you don't need to worry about Windows, but you're going to spend lots of time maintaining your configuration system as things change on you. SCons is almost a no-go right at the moment unless you're using Scratchbox2- it really doesn't have a handle on cross-compilation and you're going to need to use that extensibility and maintain it much in the same manner as you will with Automake. If so, you may want to consider CMake since it supports cross-compilation without as many of the worries about leaking out of the sandbox and will work with/without something like Scratchbox2 and integrates nicely with things like OpenEmbedded.

There is a reason many, many projects are ditching qmake, Autotools, etc. and moving over to CMake. So far, I can cleanly expect a CMake based project to either drop into a cross-compile situation or onto a VisualStudio setup or only need a small amount of clean up because the project didn't account for Windows-only or OSX-only parts to the codebase. I can't really expect that out of an SCons based project- and I fully expect 1/3rd or more Autotools projects to have gotten SOMETHING wrong that precludes it building right on any context except the host building one or a Scratchbox2 one.


虽然从开发人员的角度来看,cmake是目前最容易使用的,但从用户的角度来看,autotools有一个很大的优势

Autotools生成单个文件配置脚本,生成该脚本的所有文件都随发行版一起提供。在grep/sed/awk/vi的帮助下,它很容易理解和修复。与此相比,Cmake中有许多文件位于/usr/share/cmak*/Modules中,除非用户拥有管理员权限,否则无法修复这些文件。

因此,如果有些东西不能正常工作,通常可以通过使用标准Unix工具(grep/sed/awk/vi等)以一种大锤式的方式来“修复”,而不需要了解构建系统。

您是否曾经在您的cmake构建目录中查找错误的地方?与可以从上到下读取的简单shell脚本相比,跟踪生成的Cmake文件来了解发生了什么是相当困难的。此外,与CMake,适应FindFoo。cmake文件不仅需要了解cmake语言,还可能需要超级用户权限。