[CMake] Outputs from add_custom_command not global?

Philip Lowman philip at yhbt.com
Sun Mar 29 02:14:59 EDT 2009


On Sat, Mar 28, 2009 at 7:26 PM, James Bigler <jamesbigler at gmail.com> wrote:

> Below.
>
> On Mar 28, 2009, at 12:21 PM, Tyler Roscoe <tyler at cryptio.net> wrote:
>
>  On Sat, Mar 28, 2009 at 12:16:21AM -0600, James Bigler wrote:
>>
>>> I have an add_custom_command in a subdirectory, and I'm trying to use
>>> that output as a dependency in a parent directory.
>>>
>>> Unfortunately, the parent directory doesn't see that I made a rule
>>> (add_custom_command) for the file in the subdirectory.
>>>
>>>
>>> top level CMakeLists.txt:
>>> ...
>>> add_subdirectory(sub1)
>>>
>>> add_custom_target(generate ALL
>>>  DEPENDS ${CMAKE_BINARY_DIR}/myfile.txt
>>>  )
>>>
>>> sub1/CMakeLists.txt:
>>> add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/myfile.txt
>>>  COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/genmyfile.cmake
>>>  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
>>>  )
>>>
>>
>> I would just do the add_custom_target in the same CMakeLists where you
>> do the add_custom_command. That target will still be available from your
>> top-level CMakeLists. I use this approach all over the place.
>>
>> tyler
>>
>
> Unfortunately, I have several directories that all pool their files into
> the same target. I don't want to have a single target per file as this would
> clutter up Visial Studio projects quite quickly.
>
> Unless there's a different way to make the add_custom_command behave
> globally I'll have to somehow call this function only from the directory I
> call add_custom_target from. :(


See the thread titled "problem with add_custom_command / add_custom_target
in different directories" from a month ago.  I had the same exact problem.
There were two suggested solutions.

1. Make add_custom_command and add_custom_target be in the same directory
2. Create helper targets using add_custom_command and add_custom_target
along the way and then add them to a global target.

http://www.cmake.org/pipermail/cmake/2009-February/027314.html

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


More information about the CMake mailing list