[CMake] Recursive custom target

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Jul 31 19:08:43 EDT 2008


On 2008-07-31 19:07-0000 Piotr JaroszyÅ~Dski wrote:

>>> is it possible to add a custom target so that it would be visible in
>>> all the subdirectories?
>>
>> My experience is that targets are actually available in all directories.
>
> $ mkdir /tmp/test
> $ cd /tmp/test
> $ echo "add_custom_target(bar)" > CMakeLists.txt
> $ echo "add_subdirectory(foo)" >> CMakeLists.txt
> $ mkdir foo
> $ cmake .
>
> $ make bar
> Built target bar
> $ cd foo && make bar
> make: *** No rule to make target `bar'.  Stop.
>
> $ cmake --version
> cmake version 2.4-patch 8

I misunderstood your original request to mean "how to gain access to targets
within cmake", and my reply answers that question.

AFAIK, targets are available to _make_ (as opposed to cmake) in the
directory where they are defined by cmake and also in the top-level
directory.  However, the targets are not available in any other directory
than those two as confirmed by your example and also by some private
experiments I just did.

To confirm that at least the target is available to make in the top-level
(and also the original directory) try the following experiment which creates
the bar target in the foo subdirectory.

mkdir /tmp/test
cd /tmp/test
echo "add_subdirectory(foo)" > CMakeLists.txt
mkdir foo
cd /tmp/test/foo
echo "add_custom_target(bar)" > CMakeLists.txt
cd /tmp/test
cmake .

Here are the make results.

cd /tmp/test
make bar
Built target bar
cd foo
make bar
Built target bar

If you need more than originating and top-level target availability _for make_
you probably need to do a feature request.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list