C++ Buildsystem with ability to compile dependenci

2019-02-10 03:28发布

I'm in the middle of setting up an build environment for a c++ game project. Our main requirement is the ability to build not just our game code, but also its dependencies (Ogre3D, Cegui, boost, etc.). Furthermore we would like to be able build on Linux as well as on Windows as our development team consists of members using different operating systems.

Ogre3D uses CMake as its build tool. This is why we based our project on CMake too so far. We can compile perfectly fine once all dependencies are set up manually on each team members system as CMake is able to find the libraries.

The Question is if there is an feasible way to get the dependencies set up automatically. As a Java developer I know of Maven, but what tools do exist in the world of c++?


Update: Thanks for the nice answers and links. Over the next few days I will be trying out some of the tools to see what meets our requirements, starting with CMake. I've indeed had my share with autotools so far and as much as I like the documentation (the autobook is a very good read), I fear autotools are not meant to be used on Windows natively.

Some of you suggested to let some IDE handle the dependency management. We consist of individuals using all possible technologies to code from pure Vim to fully blown Eclipse CDT or Visual Studio. This is where CMake allows use some flexibility with its ability to generate native project files.

7条回答
SAY GOODBYE
2楼-- · 2019-02-10 03:53

In the latest CMake 2.8 version there is the new ExternalProject module. This allows to download/checkout code, configure and build it as part of your main build tree. It should also allow to set dependencies.

At my work (medical image processing group) we use CMake to build all our own libraries and applications. We have an in-house tool to track all the dependencies between projects (defined in a XML database). Most of the third party libraries (like Boost, Qt, VTK, ITK etc..) are build once for each system we support (MSWin32, MSWin64, Linux32 etc..) and are commited as zip-files in the version control system. CMake will then extract and configure the correct zip file depending on which system the developer is working on.

查看更多
淡お忘
3楼-- · 2019-02-10 03:54

There are several interesting make replacements that automatically track implicit dependencies (from header files), are cross-platform and can cope with generated files (e.g. shader definitions). Two examples I used to work with are SCons and Jam/BJam.

I don't know of a cross-platform way of getting *make to automatically track dependencies. The best you can do is use some script that scans source files (or has C++ compiler do that) and finds #includes (conditional compilation makes this tricky) and generates part of makefile. But you'd need to call this script whenever something might have changed.

查看更多
SAY GOODBYE
4楼-- · 2019-02-10 03:56

I have been using GNU Autotools (Autoconf, Automake, Libtool) for the past couple of months in several projects that I have been involved in and I think it works beautifully. Truth be told it does take a little bit to get used to the syntax, but I have used it successfully on a project that requires the distribution of python scripts, C libraries, and a C++ application. I'll give you some links that helped me out when I first asked a similar question on here.

Some more links:

  1. http://www.lrde.epita.fr/~adl/autotools.html
  2. http://www.developingprogrammers.com/index.php/2006/01/05/autotools-tutorial/
  3. http://sources.redhat.com/autobook/

One thing that I am not certain on is any type of Windows wrapper for GNU Autotools. I know you are able to use it inside of Cygwin, but as for actually distributing files and dependencies on Windows platforms you are probably better off using a Windows MSI installer (or something that can package your project inside of Visual Studio).

If you want to distribute dependencies you can set them up under a different subdirectory, for example, libzip, with a specific Makefile.am entry which will build that library. When you perform a make install the library will be installed to the lib folder that the configure script determined it should use.

Good luck!

查看更多
甜甜的少女心
5楼-- · 2019-02-10 04:02

The Question is if there is an feasible way to get the dependencies set up automatically.

What do you mean set up?

As you said, CMake will compile everything once the dependencies are on the machines. Are you just looking for a way to package up the dependency source? Once all the source is there, CMake and a build tool (gcc, nmake, MSVS, etc.) is all you need.

Edit: Side note, CMake has the file command which can be used to download files if they are needed: file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log])

Edit 2: CPack is another tool by the CMake guys that can be used to package up files and such for distribution on various platforms. It can create NSIS for Windows and .deb or .tgz files for *nix.

查看更多
地球回转人心会变
6楼-- · 2019-02-10 04:02

On many *nix systems, some kind of package manager or build system is used for this. The most common one for source stuff is GNU Autotools, which I've heard is a source of extreme grief. However, with a few scripts and an online depository for your deps you can set up something similar like so:

  • In your project Makefile, create a target (optionally with subtargets) that covers your dependencies.
  • Within the target for each dependency, first check to see if the dep source is in the project (on *nix you can use touch for this, but you could be more thorough)
  • If the dep is not there, you can use curl, etc to download the dep
  • In all cases, have the dep targets make a recursive make call (make; make install; make clean; etc) to the Makefile (or other configure script/build file) of the dependency. If the dep is already built and installed, make will return fairly promptly.

There are going to be lots of corner cases that will cause this to break though, depending on the installers for each dep (perhaps the installer is interactive?), but this approach should cover the general idea.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-02-10 04:07

Right now I'm working on a tool able to automatically install all dependencies of a C/C++ app with exact version requirement :

  • compiler
  • libs
  • tools (cmake, autotools)

Right now it works, for my app. (Installing UnitTest++, Boost, Wt, sqlite, cmake all in correct order)

The tool, named «C++ Version Manager» (inspired by the excellent ruby version manager), is coded in bash and hosted on github : https://github.com/Offirmo/cvm

Any advices and suggestions are welcomed.

查看更多
登录 后发表回答