views:

113

answers:

1

Hi,

I recently began setting up my own library and projects using a cross platform build system (generates make files, visual studio solutions/projects etc on demand) and I have run into a problem that has likely been solved already.

The issue that I have run into is this: When an application has a dependency that also has dependencies then the application being linked must link the dependency and also all of its sub-dependencies. This proceeds in a recursive fashion e.g.

(For arguments sake lets assume that we are dealing exclusively with static libraries.)

  • TopLevelApp.exe
    • dependency_A
      • dependency_A-1
      • dependency_A-2
    • dependency_B
      • dependency_B-1
      • dependency_B-2

So in this example TopLevelApp will need to link dependency_A, dependency_A-1, dependency_A-2 etc and the same for B. I think the responsibility of remembering all of these manually in the target application is pretty sub optimal. There is also the issue of ensuring the same version of the dependency is used across all targets (assuming that some targets depend on the same things, e.g. boost).

Now linking all of the libraries is required and there is no way of getting around it. What I am looking for is a build system that manages this for you. So all you have to do is specify that you depend on something and the appropriate dependencies of that library will be pulled in automatically.

The build system I have been looking at is premake premake4 which doesn't handle this (as far as I can determine). Does anyone know of a build system that does handle this? and if there isn't then why not?

+1  A: 

The typical way that this is handled is by having the library on which you depend tell you what it, in turn, requires and what versions it has linked against. One way of doing this is via pkg-config. For example, if you invoke pkg-config name_of_package --cflags, it will print out the necessary flags that should include flags needed to add headers of indirect dependencies. Similarly, pkg-config name_of_package --ldflags would print the necessary linker flags that include that particular library as well as its dependencies. As for build system, my recommendation would be to use CMake. In CMake, dependencies are found via an invocation of FIND_PACKAGE(name_of_package), which in turn defines the variable name_of_package_FOUND as 1 if the package was found, and also -- if it was found -- defines name_of_package_LIBRARIES and name_of_package_INCLUDE_DIRS to the libraries and header paths for that package as well as to the libraries and headers of its dependencies. That said, the FIND_PACKAGE mechanism works via pluggable modules written by third parties, and so while the system is supposed to set the _LIBRARIES and _INCLUDE_DIRS variables such that dependencies of dependencies are included recursively, not all of the modules do this correctly last I checked.

Michael Aaron Safyan