0

After searching a lot and reading a lot of information, I cannot decide which tool I should use for compiling my code. My codebase is mainly c++. I use primarily linux as my development machine.

Based on opinions I read before, my final candidates are waf and cmake, but I cannot decide myself which one should be more appropiate.

My primary requirements are:

  1. Must be able to compile software in windows/linux and android.
  2. Must be ready to run tests.
  3. Must be able to play nicely with other libraries that must be compiled with another build system but most likely will have to be compiled from source.
  4. Must be able to add custom steps, like for example, generating some data from some files (mainly graphics) before compiling, all integrated in the build system.

Some strong preferences are:

  1. Being ready to support MAC compilation.
  2. Being able to cross-compile from linux as many platforms as I can (maybe windows/linux/android but cannot MAC?)
  3. Being able to add support for iOS compilation if the need arises.
  4. Would be nice if the invocation interface was similar to that of autotools, since it is the one many people know and it is well documented.

Some questions:

  1. If I have some rare requirement, which build system would be more ready to be extended?
  2. Are both currently well maintained? (I wonder about waf mainly).
  3. Community: if I find a problem, both communities are big enough to support me, in your experience?

For now my feeling is that I favour waf a bit as a tool, but cmake seems to have been quite successful for whatever reason.

Germán Diago
  • 7,473
  • 1
  • 36
  • 59

2 Answers2

4

Don't know much about waf, but CMake fits your requirements pretty well. I do know waf is written in Python, my personal favourite programming language ATM.

My primary requirements are:

Must be able to compile software in windows/linux and android.

CMake does Windows and Linux very well but so does any other build system worth its salt. Someone wrote some Android scripts for CMake. Can't find anything similar for waf (my Google-fu turns up nothing.)

Must be ready to run tests.

CMake has a sibling testing framework.

Must be able to play nicely with other libraries that must be compiled with another build system but most likely will have to be compiled from source.

CMake has good integration with pkg-config, and can link against arbitrary shared libraries.

Must be able to add custom steps, like for example, generating some data from some files (mainly graphics) before compiling, all integrated in the build system.

CMake can generate custom rules.

Some strong preferences are:

Being ready to support MAC compilation.

CMake supports Mac quite well. It will even make you an Xcode project if you want, but it can also do command line builds.

Being able to cross-compile from linux as many platforms as I can (maybe windows/linux/android but cannot MAC?)

Cross-compiling is supported in CMake. CMake will not be the primary source of pain with cross-compiling - literally everything else will.

Especially with regards to cross-compiling for Mac. It's possible, but not worth it to cross-compile for that platform, considering you need access to a Mac anyways to get the libraries and header files, you need to patch GCC and clang and LLVM, etc. The only sound reason I've heard for going through this much pain is running an automated build server. Anyways, if you get a working Linux -> Mac toolchain, you should be able to cross-compile with CMake as if it were any other Unix platform.

Being able to add support for iOS compilation if the need arises.

iOS cross-compilation can be done, but you need a Mac.

Would be nice if the invocation interface was similar to that of autotools, since it is the one many people know and it is well documented.

Write a configure script that just calls CMake (cmake .). Then your users can do a ./configure && make && make install on platforms where that makes sense. There's also CPack which lets you generate DEB, RPM, NSIS (Windows) and DMG (Mac) installers/packages.

Some questions:

If I have some rare requirement, which build system would be more ready to be extended?

CMake is very extensible. It can be extended to support new languages and target platforms. (Given that waf is written in Python, it's going to be pretty hackable too.)

Are both currently well maintained? (I wonder about waf mainly).

CMake is mature and well-maintained.

Community: if I find a problem, both communities are big enough to support me, in your experience?

The community and extensions available are what keeps me coming back to CMake, from things like bakefile, honestly.

Community
  • 1
  • 1
  • 1
    Your reply is pretty informative. I voted up but won't close as the definitive answer only because I would like someone to make similar comments on waf for all the questions. Under similar features, I'd rather go with waf because I know python. Unless there is any big inconvenience in waf, of course... – Germán Diago Oct 08 '13 at 06:00
  • I already tried waf. The tool is good, does its job, but it seems that it doesn't have too much out of the box. I feel that with autotools, even if more difficult, everything was shorter, more automatic. I will try CMake and will share my experience. It's worth to mention that tup caught my eye lately due to its ultra fast builds, though there is no standard "autoconf" there. It's just a make replacement. – Germán Diago Dec 19 '13 at 17:50
  • 1
    CMake supports `ninja` (a `make` replacement) on some platforms which will net you faster builds. – Jonathan Baldwin Dec 19 '13 at 20:36
  • Though to be fair, as a user I've never found CMake-using packages to be as intuitive to install as an end user compared to autoconf. Configure options on CMake packages require flags of the form `-DMYOPTION=SOMEVALUE` which is not as intuitive as `--MYOPTION MYVALUE` (a la `configure`) IMO. However, this is not a huge problem and can be easily worked around by providing a `configure`-style wrapper script. CMake has a GUI for setting configure options, which is very nice on Windows, but feels weird on Unix where the command line reigns supreme. – Jonathan Baldwin Dec 19 '13 at 20:48
2

WAF

  • is pure Python
  • becomes part of your project, i.e. no external dependency
  • supports many build tools
  • can be used to do all kind of automations, not just building

It works perfectly for Linux, Mac or Windows.

On Android, gradle is the chosen build tool of Google. To use that is wise, because it is set up to work by Google. You can call waf from gradle and vice-versa, though.

If you want to learn all the low level Android SDK tools, you could also use WAF directly.

The SDK has

  • javac for Android Runtime (formerly Dalvik), Android\'s JVM, and produces a .class file
  • jar can also be used for Android
  • d8 (formerly dx) produces .dex files, with Dalvik executable code
  • aapt2 can then produce the .apk

javac and jar are known to WAF. For dx and aapt2 you would need to create your own tasks, which is very easy.

You would best make a WAF tool and share it. Tools are either part of WAF or there is waftools. There are also these Steinwurf tools.

If you make Android native code using NDK:

  • you use CLANG, which is known to WAF

Further on you mentioned requirements:

  • WAF has waf_unit_test
  • WAF can do gnu_cross compilation. The Gnu toolchain knowns many targets. But for Android you would need to set things up yourself using the SDK or NDK. For NDK you could use the Gnu toolchain.
  • You would do waf configure, waf build instead of configure, make, but you could wrap a Configure or Makefile around waf to have the same commands.
  • WAF is very easily extendible with Python
  • WAF is now on gitlab and constantly worked on.
  • The community is surely smaller than for CMake. But it is Python. You can look into it and find out for yourself. You can also contribute and become part of the community.
Roland Puntaier
  • 3,250
  • 30
  • 35