[CMake] Setting dependencies between libraries (cmake projects)

Michael Wild themiwi at gmail.com
Fri Nov 4 05:56:45 EDT 2011


On 11/04/2011 10:47 AM, Ludovic Hoyet wrote:
> Hi,
> 
> I am using cmake to build an application made up of a dozen projects. We
> use cmake to automatically generate solutions for x86, x64, and both VS
> 2005 and 2010.
> 
> Here is an idea of our organisation:
> 
>   * a.lib, which has no dependency
>   * b.lib, which has no dependency
>   * c.lib, which depends on a and b
>   * d.dll, which depends on c
> 
> Each project lies in its own subdirectory, and has its own
> CMakeLists.txt file. In order to keep track of the lib/dll generated for
> our different platforms, we automatically post-fix each lib/dll with
> _x86/_x64 and _vc80/_vc100 (e.g., a_x86_vc100.lib), and with an _d for
> debug (e.g., a_x86_vc100_d.lib).
> 
> In the CMakeLists.txt files, I use target_link_libraries to link each
> target with the corresponding libraries, for instance:
> 
>     TARGET_LINK_LIBRARIES( c debug a_${VS}_${PLATFORM}/d optimized
>     a/${VS_DIR}/${PLATFORM} debug b/${VS}_${PLATFORM}/d optimized
>     b/${VS_DIR}_${PLATFORM})
> 
> In Visual Studio, the different "Project Dependencies" between the
> various projects do not appear. I wonder if there is something I miss,
> or if it is simply not compatible with our library post-fix. I also
> tried to use ADD_DEPENDENCIES(c a b) but it does not seem to work either.
> 
> Does anyone has an idea how to solve this?
> 
> Cheers,
> 
> Ludovic 


Are these projects completely isolated, i.e. there is no higher-level
CMakeLists.txt file that calls add_subdirectory() for each of the
project directories?

1: if they belong to the same project, then you should use the *target*
names, not the *output* names in target_link_libraries().

2: if they indeed are independent projects, you should take a look at
this:
http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
and for each of the libraries create a <libname>Config.cmake file.

A bit more information on how your projects are structured would help.
Also, showing example code is always useful.

HTH

Michael


More information about the CMake mailing list