[CMake] Depending on all and custom targets

Eric Noulard eric.noulard at gmail.com
Fri Oct 9 07:01:30 EDT 2009


2009/10/9 jens persson <jens at persson.cx>:
>>
>> I think dependency from "extras" should work did you try with
>> only "extras" and not "all"?
>
> Yes I get the following error:
>
> $ make complete
> [100%] Built target bar
> [100%] Built target extras
> make[3]: *** No rule to make target `extras', needed by
> `CMakeFiles/complete'.  Stop.
> make[2]: *** [CMakeFiles/complete.dir/all] Error 2
> make[1]: *** [CMakeFiles/complete.dir/rule] Error 2
> make: *** [complete] Error 2
>
>
> With this CMakeLists.txt file:
>
> PROJECT (tester)
> CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
> CMAKE_POLICY (VERSION 2.6)
>
> add_executable(bar
>        bar.c
> )
> add_custom_target(extras
>        DEPENDS bar
> )
> add_custom_target(complete
>        DEPENDS extras
> )
>
>
> I've tried to look into the makefiles but could not find the solution.

Better look in to the documentation first :-)
From
cmake --help-command add_custom_target

"Dependencies listed with the DEPENDS argument may reference files and
outputs of custom commands created with ADD_CUSTOM_COMMAND."

the DEPENDS argument of ADD_CUSTOM_TARGET is here to cope
with the fact that CMake cannot compute dependency precisely because
it's a CUSTOM target whose input is unknown to CMake.

thus you cannot use that to specify top-level target dependencies.
You should use add_dependencies for that.

Working CMakeLists.txt should looks like:

PROJECT (tester)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
CMAKE_POLICY (VERSION 2.6)

add_executable(bar
       bar.c
)
add_custom_target(extras)
add_dependencies(extras bar)
add_custom_target(complete)
add_dependencies(complete extras)

> Probably a bug. Will report it later.

Finally I don't think this is a bug.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list