[CMake] problem with add_custom_command / add_custom_target in different directories

Philip Lowman philip at yhbt.com
Thu Feb 26 02:12:23 EST 2009


On Wed, Feb 25, 2009 at 8:54 AM, Brad King <brad.king at kitware.com> wrote:

>
>  What works for me (CMake-CVS, Mac OS X 10.5, Makefile generator) is the
>> following:
>> - add an empty custom target "untar" with no dependencies to
>> CMakeLists.txt BEFORE any of the add_subdirectory calls
>> - in the test/CMakeLists.txt add a custom target "untarFoo" which depends
>> on the output of the custom command
>> - in the test/CMakeLists.txt add a dependency of the top-level "untar"
>> target on the "untarFoo" helper target
>>
>
> This approach is correct, but could unfortunately create too many extra
> targets that the user will see in IDE generators like VS and Xcode.  I
> suggest instead doing all the untar rules in a single target defined in
> one directory.  One can use the WORKING_DIRECTORY option to make each
> rule execute in the proper directory.


This is the approach I'll probably use for now.  Thanks for the advice.

Meanwhile, there are a few potential problems with the untar-in-source
> approach in the first place:
>
>  1.) The source tree might be read-only.  You can untar into the
>      build tree and refer to things there.
>
>  2.) Your example specifies a directory as the output of the custom
>      command.  Since the directory timestamp gets updated by a
>      variety of operations, the untar rule may not rerun reliably
>      when the tarball changes.  I suggest making the extraction
>      rule generate a stamp file with "cmake -E touch ...".



Thanks for pointing out those two problems.  Not too worried about either of
them at the moment given what this is intended for.  Another thing did
concern me which was the removal of the untar'd directory on a "make
clean".  Is there any easy way to disable this?

The ultimate goal here would be
1.) User types "make"
1a.) CMake untars several source tarballs each in different directories
1b.) CMake patches several source trees in different directories
1c.) CMake automatically detects those directories now exist, recurses into
them with add_subdirectory() and builds stuff
2.) User types "make clean" and only compiled code gets cleaned, not
generated directories.

I'm pretty sure I can get something working with several independent custom
targets and an additional running of cmake at step 1c. at the worst case
(i.e. "make untar" && "make patch" && "cmake .." && "make").  Not sure I'll
be able to figure out how to chain it all together to be kicked of via just
by running "make".  Still kinda new to add_custom_target/add_custom_command
and learning so any advice would be appreciated.


-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090226/fa70f17a/attachment.htm>


More information about the CMake mailing list