Home » C++ » Maven-like dependency management for C++? [closed]

Maven-like dependency management for C++? [closed]

Posted by: admin November 29, 2017 Leave a comment

Questions:

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?

Answers:

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
Questions:
Answers:

For the dependency management, it exists a new project (it is a startup company) which is implementing this type of tool: https://www.biicode.com/ (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)

Questions:
Answers:

I recommend the following high-level build systems:

Questions:
Answers:

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.

Questions:
Answers:

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 [email protected]

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

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

Questions:
Answers:

Recently released: biicode A multi-platform tool and hosting service for developers

Edit:

Biicode is deprecated

Alternative: Conan.io

Questions:
Answers:

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

Questions:
Answers:

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

See also, NuGet for C++

Questions:
Answers:

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”.

Questions:
Answers:

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

Questions:
Answers:

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.

Questions:
Answers:

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