Maven-like dependency management for C++?

C++MavenBuildDependency Management

C++ Problem Overview


Say I have a C++ project that is split in several subprojects. The subproject all produce a DLL and different teams of developers work on each of the subproject. Now if I want to build the main project, is there a way to avoid having to build all the subprojects by myself?

In short, I'm looking for something that does the dependency management (i.e. for binary files and headers) in a similar way as Maven does for Java.

In fact, I tried to use Maven for this but this is rather cumbersome because I have to create the packages manually and quite frequently, Maven misses to pick up the most recent changes. Also, running the compilation is a bit of a hack as I have to call NAnt from within Maven (I use NAnt's feature to build Visual Studio solutions directly).

Any hints and ideas of how to do this?

C++ Solutions


Solution 1 - C++

Initial Answer: I would suggest using CMake. It is a multi-platform make file generator (generates Visual Studio or Eclipse CDT projects as well).

http://www.cmake.org/

I did really good experience with it. The best thing I like about it was the ability to produce generic project structure. So you can generically include sub-projects look-up for unit tests etc. without changing the script every time.

They have also lots of modules on how to find pre-installed build libraries, required for the project (like Boost, QT etc.)


Update: In the mean time there was some effort to introduce package management for C++. Some projects worth looking at:

  • conan.io integrates with major build tools:
    • CMake
    • Visual Studio
    • Makefile
    • XCode
    • ...
  • cpm based on CMake (Note CPM is not being actively maintained.)
  • Buckaroo

Note as pointed out by @RAM in the comments cpm is no longer actively maintained.

Solution 2 - C++

For the dependency management, it exists a new project (it is a startup company) which is implementing this type of tool: https://github.com/biicode (a C++ dependency manager). You could add your dependencies and it should work.

Currently, the project's name is conan.io, they were acquired by JFrog.

UPDATE: The project is dead... Unfortunately, it seems the startup couldn't get enough premium paying customers, but the server seems is working fine...

UPDATE2: It seems there is a substitute project: conan.io (thanks @mucaho)

Solution 3 - C++

I recommend the following high-level build systems:

Solution 4 - C++

If you only want dependency management, try Ivy, it integrates nicely with Ant (and I assume NAnt can do the same based on this blog, which is linked from the Ivy site).

There is also Byldan, a .Net version of Maven. Don't know how well that will work for you though.

Solution 5 - C++

Make and GCC are a great combo for really good dependency checking.

GCC can generate 'make' dependency files automatically (-MD commandline switch), so as to be able to rebuild all sourcefiles that depend upon a given header, for example.

I have some simple rules that I cut-n-paste into my makefiles:

# compile c files	
%.o:	%.c
	${CC} ${CFLAGS} -c $< -MD -MF $(<:%.c=%.dep) -o $@

# compile c++ files
%.opp:	%.cpp
	${CPP} ${CPPFLAGS} -c $< -MD -MF $(<:%.cpp=%.dep) -o $@

Now if your object files are declared in say an OBJ_C and an OBJ_CPP list:

.PHONY:	cleandep
cleandep:
	rm -f $(OBJ_C:%.o=%.dep) $(OBJ_CPP:%.opp=%.dep)

-include $(OBJ_C:%.o=%.dep) $(OBJ_CPP:%.opp=%.dep)

Make can of course track dependencies with other projects and such, e.g. rebuilding a shared libary as necessary, too.

For example, if your other teams always put their latest DLLs on some shared folder:

myapp: ${SRC_CPP} ${LIB_DIR}other_team.lib
  ...

${LIB_DIR}other_team.lib: /shared_folder/latest/other_team.lib
  cp /shared_folder/latest/other_team.lib ${LIB_DIR}other_team.lib

Solution 6 - C++

Edit:

Biicode is deprecated

Alternative: Conan.io

Solution 7 - C++

I recommend conan, which I was using these days. It's very powerful to maintain all the dependent libraries and binaries in your project.

Solution 8 - C++

You can create NuGet package for used libraries and use NuGet for dependency management.

See also, NuGet for C++

Solution 9 - C++

There is a number of tools sitting on top of SCons, providing higher-level functionality similar to that of Autotools which are trying to make the developers life easier (e.g. WAF, SNOCS). Unfortunately, SCons itself has the major drawback - longer compilation time for the large projects.

I can recommend to try out SNOCS (which is a SCons reversed) for those of you looking for an easy dependency management and choosing compilation options in the single command (compiler, x86/x64, Debug/Release, static/shared libraries, test/install targets, etc.).

SNOCS also tries to tackle the long compilation time problem by storing the projects configuration output in the separate files, which allows the consequent builds to skip configuration phase altogether and go straight to the building phase (last feature is under construction now)

CMake's configuration becomes tedious in a larger solutions, so the build system maintenance takes a large fraction of the developer time. Luckily as Martijn already mentioned there is biicode which "uses CMake to generate your project with its dependencies".

Solution 10 - C++

Try SCons

SCons is an Open Source software construction tool—that is, a next-generation build tool. Think of SCons as an improved, cross-platform substitute for the classic Make utility with integrated functionality similar to autoconf/automake and compiler caches such as ccache. In short, SCons is an easier, more reliable and faster way to build software.

Solution 11 - C++

I recommend to use the mother of all build dependency systems: make.

Solution 12 - C++

Try scons, you will be hooked. Make is outdated, difficult and expensive to maintain.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwebersteView Question on Stackoverflow
Solution 1 - C++ovanesView Answer on Stackoverflow
Solution 2 - C++carlos.baezView Answer on Stackoverflow
Solution 3 - C++carlosvinView Answer on Stackoverflow
Solution 4 - C++Rich SellerView Answer on Stackoverflow
Solution 5 - C++WillView Answer on Stackoverflow
Solution 6 - C++Martijn MellensView Answer on Stackoverflow
Solution 7 - C++Ben ChenView Answer on Stackoverflow
Solution 8 - C++KindDragonView Answer on Stackoverflow
Solution 9 - C++oleg.blinnikovView Answer on Stackoverflow
Solution 10 - C++BuriView Answer on Stackoverflow
Solution 11 - C++Martin v. LöwisView Answer on Stackoverflow
Solution 12 - C++piotrView Answer on Stackoverflow