[CMake] [Cmake] Detect caller project for a sub-project

Andreas Mohr andi at lisas.de
Thu Jun 10 12:28:09 EDT 2010


On Thu, Jun 10, 2010 at 12:00:06PM -0400, cmake-request at cmake.org wrote:
> On Thu, Jun 10, 2010 at 06:26:27AM -0400, cmake-request at cmake.org wrote:
> > is there some kind of way for a project to detect the name of the project
> > from which it was added? In this example, can C know that was added by B?
> > (and B was added by A?)

[...]

> This should work I think, since projects should (famous last words...) have hierarchical scope
> I guess, thus any projects added in sub directories in the meantime
> shouldn't manage to influence evaluation of the parent project's name.

Argh, of course I forgot to mention the most important part:

I'm very afraid that you were asking the wrong question here. ;)
From a modularity POV, it seems pretty wrong to want to know in a sub
project which higher (i.e.: unrelated!) parent project it is being added from.
Instead, the sub project should probably offer some configuration indicator
setting (perhaps via a CMake variable, or a global/directory/... property
to be defined by a parent project) for the parent project to set/override
according to its needs, to make the sub project know which configuration
is expected currently.

Otherwise you will keep having to add exceptions to the CMake config in
the sub project whenever the parent project name / specifics change.

HTH,

Andreas Mohr


More information about the CMake mailing list