[CMake] add_dependencies being ignored for add_custom_command?

Martin Braun martin.braun at ettus.com
Mon Oct 26 13:32:42 EDT 2015


Iosif,

thanks for your answer. I have some follow-up questions, though:

On 23.10.2015 18:21, Iosif Neitzke wrote:
> The command "add_dependencies" [0] only works on targets.

What exactly is a target? I thought if I do add_library(foo ${sources}),
then 'foo' is a target? You seem to suggest otherwise, which means I'm
misunderstanding some concepts.

> See the CMake Tutorial for how to generate files as part of the build
> that later targets rely on. [1].

This describes how add_custom_command() *itself* can declare
dependencies, which is not my issue. My issue is that I need to run the
custom command *before* I build a library (which I thought was a target).

I would assume there's a way to declare this kind of dependency, but
other than add_dependencies(), I can't seem to find anything.

Thanks again,
Martin

> 
> [0] https://cmake.org/cmake/help/v2.8.12/cmake.html#command:add_dependencies
> 
> [1] https://cmake.org/cmake-tutorial/#s5
> 
> On Fri, Oct 23, 2015 at 7:35 PM, Martin Braun <martin.braun at ettus.com> wrote:
>> Hey,
>>
>> I'm at a loss here:
>>
>> I have a command that's run with add_custom_command(). I need to run it
>> before compiling a library that I add with add_library(), because it
>> generates some header files.
>>
>> This was my first try:
>>
>> file1:
>> {{{
>> add_custom_command(
>>     OUTPUT foo.hpp
>>     COMMAND bar
>> )
>> }}}
>>
>> file2:
>> {{{
>> add_library(baz ${sources})
>> add_dependencies(baz ${CMAKE_BINARY_DIR}/path/to/foo.hpp)
>> }}}
>>
>> ==> This didn't work. If I run make -j4, it will always try and compile
>> my ${sources} before it ran the command. Maybe I'm specifying targets
>> the wrong way?
>>
>> Next try:
>>
>> file1:
>> {{{
>> add_custom_command(TARGET baz
>>     PRE_BUILD
>>     OUTPUT foo.hpp
>>     COMMAND bar
>> )
>> }}}
>>
>> file2:
>> {{{
>> add_library(baz ${sources})
>> }}}
>>
>>
>> ==> Same behaviour.
>>
>> I'm using CMake 2.8.2.12. Really, I need something that works with CMake
>> 2.8.0 because that's the minimum we guarantee our customers.
>>
>> Any ideas? Thanks in advance!
>>
>> Cheers,
>> Martin
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list