[CMake] Redefine target in nested project

Marcel Loose loose at astron.nl
Tue Apr 28 03:50:18 EDT 2009


Hi Tyler,

What I meant is the following.

I would like to be able to run 'make check' at any directory level in
the build tree. Currently, this is not possible, because AFAIK, you then
need to multiply define the target 'check' (for each separate project),
which is not possible, because CMake does not allow it.

Let me try to clarify things a bit more.

Suppose I configure bigproject with CMake in the build tree
$HOME/build/bigproject. There, I define a new target 'check' using
add_custom_target(), and I make all my test programs depend on this
target using add_dependencies().

Now I can run 'make check' *only* from the directory where
add_custom_target() was invoked (in my case this is the toplevel build
directory $HOME/build/bigproject). However, I would like to be able to
drill down to $HOME/build/bigproject/subproject1 and issue the same
'make check' command. However, in that directory, the target 'check' is
unknown, and CMake does not allow me to (re)define it.

Still in other words: I would like to use 'make check' the same way that
you can simply say 'make' (which implies 'make all') at any directory
level. 'make check' should then run all the tests in the that directory
and below.

The special target 'test' does more or less the same thing. You can do a
'make test' at any directory level, and only the tests in that directory
and below are being run. Unfortunately, 'make test' does not (re)compile
the test programs. Therefore I created the 'check' target, which does
just that.

So my question is: Is it possible to (re)define the target 'check', in
such a way that I can do a 'make check' at any directory level in the
build tree?


Best regards,
Marcel Loose.



On Mon, 2009-04-27 at 09:47 -0700, Tyler Roscoe wrote:
> On Mon, Apr 27, 2009 at 03:33:39PM +0200, Marcel Loose wrote:
> > Now, suppose there's some generic target (e.g. 'check') that I would
> > like to be defined for each of these projects, such that I can do
> > 
> >   $ cd /path/to/build/directory/bigproject && make check
> > 
> > but also
> > 
> >   $ cd /path/to/build/directory/bigproject/subproject_1 && make check
> 
> I'm not sure what you mean by "some generic target". What would your
> hypothetical check target do in bigproject and in subproject_1?
> 
> I think I would solve a problem like this with a macro or function
> defined in a file included by each of your projects, but I don't really
> understand the problem.
> 
> tyler



More information about the CMake mailing list