views:

931

answers:

5

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?

A: 

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

Martin v. Löwis
I use this extensively.GCC can make dependency files that 'make' can eat. Enough for another answer, perhaps...
Will
+2  A: 

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.

Rich Seller
+1  A: 

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
Will
see my comment attached to the question regarding my concerns with this solution
weberste
If a target is dependent on another file e.g. your executable is dependent on a shared library, you can have a rule for that shared library that makes sure your copy of the library is up-to-date without needing the source, e.g. by simply fetching the latest copy from a particular location or from executing some version control update or such.
Will
A: 

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

Regards,
Ovanes

ovanes
I used CMake a few months back and indeed, checking for pre installed libraries worked very nicely. However, other binary dependencies (i.e. the ones coming from my subprojects) could not be managed easily. Am I missing something?
weberste
A: 

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

piotr
I had a look at Scons but did not find a way to manage binary dependencies. Do you have an example for this?
weberste
Since scons is python, you can code whatever you want to manage your binary dependencies quite easily. Perhaps having an "SConscript" in the directory of your binary dependencies also helps. I'm not sure what are your requirements here tough.Pedro.
piotr