views:

648

answers:

11

Imagine you're free to choose a tool like GNU make for a new C++ project. What would you choose? Are any usable substitutes out there?

It shall have/be

  • a command line interface
  • "easy" to understand ;)
  • easy to set up for a default c++ project
  • may support src/bin seperation as common for Java
  • may not add too much dependencies to other software/libs
  • platform independent (new)
  • features:
    • build rules / templates like make but in an human readable way
    • recursively crawling directories and applying the rules if there is no other "Makefile"
    • configuration by exception

Note:

Nothing's wrong with GNU make. I just don't like its grammar, all the stuff that grows in the years and the silly recursive make problems. I'm using gmake for years now, but now I've the chance to switch to something new. So, I'll take the chance and asking the community. ;)

I thank all of you for your contribution!

A: 

Personally, I prefer just using Bash scripts.

Adam Crume
Ouch, is there a reason I was downvoted? Comment, please.
Adam Crume
@Adam, I didn't downvote, but I felt like it. Bash scripts aren't a build tool. I'd personally hate to work on a project that thought a bash script was a good substitute for a real build system
Glen
downvote: bash scripts aren't build tools and never ever a substitute for make.
tuergeist
You could write a build system in bash. However, I couldn't imagine it being any easier or better than any existing build systems..
Phillip Jacobs
I don't see a problem with this for small projects. The one issue I see is that it isn't cross-platform (doesn't work on Windows, at least without some hackery).
Imagist
I wouldn't downvote this one. Personally, I also wouldn't use bash scripts, but I could see how this could be interesting. Bash script is a powerful language in its own right, and with the right experience can be used in the same fashion as, say, ant or MSBuild.
mos
@Imagist Neither is make. Microsoft's nmake uses a different file format. You could argue for cygwin, but at that point you get bash, and suddenly both are cross-platform. ;)
mos
The option I would consider as an alternative to bash would be Python, not cygwin (Python is much easier to install and works consistently, while every time I've used cygwin it has had a hack-ish feel, which is what I meant when I said "at least without some hackery").
Imagist
@Adam, using bash scripts you have only two possibilities. 1) ignore dependencies and build everything whenever you perform a build, or 2) try and include some sort of dependency checking so that you build only those parts that you need to which becomes **really** cumbersome, very quickly! HTH
Rob Wells
Apparently my answer is a bit controversial. I know I didn't mention it, but I would agree that Bash scripts aren't good for monstrous projects. I was assuming the project was smallish. I would also like to point out that mos is right, make is not cross-platform. Makefiles ultimately depend on running binaries by name, and that often includes basic *nix commands like rm that don't exist in Windows (unless you install a compatibility layer like Cygwin).
Adam Crume
downvote: you must code dependency-checking manually, and bash doesn't keep a list of built targets. See "Dependency Checking: make vs. Shell Scripts" at http://docs.sun.com/app/docs/doc/805-4035/6j3r2rqne?a=view
Jason Catena
I'll admit I have some single-file helper binaries that I compile with a bash script, since (a) it's just one file and (b) they are rarely re-built. However, I have a bug against myself for each one to go put it into the main build scripts.
jeffamaphone
I've not downvoted this, as I've seen a lot of "Makefiles" that are 80% bash scripting anyway!
rq
+4  A: 

SCons + swtoolkit

Grant Limberg
+2  A: 

What's wrong with gmake?

What issues does it have that mean you want to use it. There's no point in recommending another tool if it has the same perceived issues as gmake.

we're using gmake in our build system and we're extremely happy with it's performance, flexibility and features

Glen
Nothing's wrong with it. I just don't like its grammar, all the stuff that grows in the years and the silly recursive make problems.I'm using gmake for years now, but now I've the chance to switch to something new. So, I'll take the chance and asking the community. ;)
tuergeist
@tuergeist, some fair points. We're using gmake with non-recursive makefiles and it's so much better than the traditional recursive makefile system. The only real downside is that it takes a lot of work to setup the initial non-recursive system. on the plus side non-recursive make has dramatically reduced our build times (3000 source files, ~1 million lines of code compiled in about 6-8 minutes), allows great dependency tracking and parallel builds. (all things you can probably get from other tools)
Glen
@Glen: sounds good. My last experience was to wait 45mins for the nearly the same amount of code and files on a dual-core 3GHz PC :( (with recursive make files and a three stage build system - stages for idl, libs+objects, binaries))
tuergeist
+6  A: 

How about "gnu make"?

You asked for something like it without giving any indication of what features you want that aren't supported by gnu make.

Bryan Oakley
sorry, I edited my question. My aim was not to narrow your thoughts.
tuergeist
+6  A: 

SCons and waf are good (well, IMHO anyway) build systems, and depend only on Python.

PiotrLegnica
Hmm, ok. But as you stated waf brings dependencies to Python :(
tuergeist
+1 for SCons. The Python dependency isn't an issue--we build on Mac, Win, Linux.
jeffamaphone
I like waf better than scons, but I can't quite understand how to extend either for the life of me. Ultimately I prefer make for how easy it is to add new rules/target types and for how fast it starts working. Scons performance on large projects is just woeful.
Bklyn
+6  A: 

CMake should answer most, if not all for your requirements.

  • It will generate the Makefiles for you.

  • It has a good domain specific primitives, plus a simple language for the times you need to do something special.

  • It solves most of the problems with recursive make (see recursive make is considered harmful paper).

  • It uses an out-of-source build, so you have your bin / src separation.

I found it easy to write, easy to maintain, and fast to build.

... Plus:

  • It is cross platform.

  • With CText and CDash it has what you need for setup a continues integration service.

See also this answer to Recursive Make - friend or foe?

Chen Levy
+17  A: 

I use cmake, and I'm very glad I made the switch.

EDIT

Feature list as found in the wikipedia article:

  • Configuration files are CMake scripts, which use a programming language specialized to software builds
  • Automatic dependency analysis built-in for C, C++, Fortran and Java
  • Support of SWIG, Qt, via the CMake scripting language
  • Built-in support for many versions of Microsoft Visual Studio including versions 6, 7, 7.1, 8.0, and 9.0
  • Generates build files for Eclipse CDT (C/C++ Development Tools)
  • Detection of file content changes using traditional timestamps,
  • Support for parallel builds
  • Cross-compilation
  • Global view of all dependencies, using CMake to output a graphviz diagram
  • Support for cross-platform builds, and known to work on
    • Linux and other POSIX systems (including AIX, *BSD systems, HP-UX, IRIX/SGI, and Solaris)
    • Mac OS X
    • Windows 95/98/NT/2000/XP, Windows Vista and MinGW/MSYS
  • Integrated with DART (software), CDash, CTest and CPack, a collection of tools for software testing and release

But to be honest: Just about anything is better than the gnu toolchain.

soulmerge
why?
Adriano Varoli Piazza
yes, why?
tuergeist
Another advantage is easy cross platform installation/packaging commands.
thekidder
@soulmerge: thanks for edit
tuergeist
I actually like gmake, with a bunch of special makefiles I've prepared over the years. But I recently switched to cmake and it simplified cross-platform development (Linux, OS X, Windows) so much that cmake is my new default for new projects.
Larry Gritz
I see cmake more like complete replacement for automake/conf including gmake. And I agree that cmake is far easier to use than somewhat arcane m4 macros ;-)Additionally, for large projects, it is significantly faster than gmake.
drhirsch
I like CMake a lot as well, but it involves a lot of pain whenever you try to do something nonstandard.
Eric
CMake is the only tool out there capable of generating **real** Visual Studio projects, i.e. not makefile-projects which invoke some external tool.
JesperE
"Another advantage is easy cross platform installation/packaging commands" I think that `./configure --host=arm-linux-gnueabi` or `./configure --host=i586-mingw32msvc` is simple enouhg?
Artyom
+1  A: 

apache Ant

Pierre
adds dependency to Java.. But, have you ever seen a C++ project using ant?
tuergeist
@tuergeist Not that I support the usage of ant (I despise their usage of XML) but why is a dependency on Java a concern? How often are you developing on a computer that doesn't or can't have Java installed?
Imagist
Here is the link to the Ant C++ Tasks: http://ant-contrib.sourceforge.net/cpptasks/index.html
h0b0
@Imagist: The problem with dependencies is that they're (in most cases) specific. Means.. to a specific version, e.g., Java 1.5 or up, or Java 1.6 or whatsoever. But Java as dependency is acceptable ;)
tuergeist
A: 

G'day,

I'd agree with the couple of answers, so far, that recommend sticking with gmake.

Maybe have another look after reading the first few chapters of Robert Mecklenburg's excellent book "Managing Projects with GNU Make" (sanitised Amazon link).

Or, even better, is to search out a copy of the previous edition called "Managing Projects With make" by Andrew Oram and Steve Talbott. The first few chapters give an excellent description of (g)make and [Mm]akefile basics.

And I see you can buy a second hand copy of the 2nd ed. from Amazon for the princely sum of $0.01! (sanitised Amazon link)

After reading that intro you'll even understand how make is backward chaining, which is a bit non-intuitive when just looking at make's behaviour.

HTH

cheers,

Rob Wells
I think this answer isn't helpful as its not an answer to my question. I did not asked for a guide recommendation.
tuergeist
@tuergeist, i considered that before answering. but i did find i considered make in a new light when i began to understand its inner workings more deeply. hence the pointers to two excellent sources of info. (-:
Rob Wells
+6  A: 

Boost.Jam

It has the features you named

  • command line interface;
  • easy;
  • it comes from the C++ library collection Boost, so it has good support for C++ (and it's not limited to C++, either);
  • it stores executables in places under the bin directory, depending on what build request you've commanded. If you use gcc 4.3.2, than you get the executables under
    • bin/gcc-4.3.2/debug -- when executing bjam
    • bin/gcc-4.3.2/release -- when executing bjam release
    • bin/gcc-4.3.2/release/inlining-off/threading-multi -- when executing bjam release inlining=off threading=multi
    • bin/gcc-4.3.2/release/threading-multi -- for bjam release inlining=full threading=multi because inlining=full is default for release.
  • it doesn't need the full Boost library collection, only Boost.Build and Boost.Jam are necessary;
  • platform independent;
  • the Jamfile syntax is easy, but powerful;
  • you can divide the build config into many Jamfiles in subdirectories.
Adrian Panasiuk
Not so sure about the 'easy' though :-)
Chris Huang-Leaver
A: 

Autotools -- autoconf/automake/libtool they are very poweful build instruments.

Its take some time to start with them, but after -- they serv you very well.

And what is more important they are significantly more powerfull then their replacements (CMake, BJam, SCons etc).

How are they more powerfull?

  • Transparrent support of building both static and shared libraries via libtool.
  • Support of uninstall (no in CMake)
  • Support of standard installation paths -- very important in packaging.
  • Full support and integration of gettext.
  • Transparent and strightforward support of cross compilation.

Many things. CMake may do most of things but for each one of them you should write long scripts or specify many things manually.

Artyom
It also have many drawbacks. For one it puts files everywhere and has not builtin mechanism I know of to remove those. It's a bit of concern when you use some versioning tool.Could you also elaborate in what ways autotools are more powerfull than says bjam or CMake ?
kriss
"For one it puts files everywhere and has not builtin mechanism I know of to remove those." First of all you may do out-of-source builds. So all files will be stored in other directory.
Artyom
Please add some pointer on how to do that. It's trivial using bjam or cmake, but I never saw one project using autotools that does not clutter source tree with a bunch of generated files. And I'm not speaking only of files generated by the building process itself but also of the bunch of files generated as soon as you type configure. I would be quite surprised if it is possible at all. If there is not generated Makefile for instance how could make possibly work after the configure part in the common triptic "./configure ; make ; make install".
kriss
>how could make possibly work after the configure part in the common triptic "./configure ; make ; make install". < Very simple: "mkdir build; cd build; ../package-xyz/configure; make; make install" -- You can run configure out of the source tree. More then that, some packages like gcc ask you to do out of source build. And do not support "in source" builds.
Artyom
Also cleaning up is quite simple : make distclean does the job.
Artyom