[CMake] add_dependencies being ignored for add_custom_command?

Iosif Neitzke iosif.neitzke+cmake at gmail.com
Fri Oct 23 21:21:17 EDT 2015


The command "add_dependencies" [0] only works on targets.

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

[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