[CMake] subprojects

Michael Wild themiwi at gmail.com
Thu Oct 27 12:34:33 EDT 2011


On 10/27/2011 05:46 PM, Tomasz Grobelny wrote:
> I have several subprojects (eg. libA and libB) and I want to make a parent
> project that would group both of them. The problem is that libB depends on
> what is installed by libA. I have come up with two ideas:
>  1. Configure libA and libB as ExternalProjects - the build process works
> but when I open the parent project in Visual Studio I do not see the source
> and header files.
>  2. Use add_subdirectory command - this make the project look good in VS,
> but doesn't build well as libB build is started before installing libA.
> 
> How do I solve this problem? Is it possible to either add source files in
> (1) or add dependency on install of libA to libB in (2)? Or maybe some
> other option?

The only way of getting libA installed before libB is built is indeed
using ExternalProject.

However, in your case I would prefer to restructure libA such that it's
build tree resembles the installation tree closely enough, such that you
can build libB against it. E.g. if you need header files to be located
in a specific structure which is different from that in the source tree,
use either configure_file(... COPYONLY) commands, or if you don't want
that, you can configure_file(...) wrapper headers with the same names
which include the actual files through absolute paths.

HTH

Michael


More information about the CMake mailing list