[CMake] Re: ADD_DEPENDENCIES: "non-existent target"??

Bill Hoffman bill.hoffman at kitware.com
Tue Mar 20 14:19:04 EST 2007


Matthew Woehlke wrote:
> Matthew Woehlke wrote:
>> Matthew Woehlke wrote:
>>> I have a project with some Doxygen doc that has examples. I want to 
>>> add a non-default target to build the examples. I tried this:
>>>
>>> src/CMakeLists.txt:
>>> ADD_CUSTOM_TARGET(examples)
>>>
>>> src/examples/CMakeLists.txt:
>>> MACRO(ADD_EXAMPLE name)
>>>     ADD_EXECUTABLE(${name} EXCLUDE_FROM_ALL ${name}.c)
>>>     TARGET_LINK_LIBRARIES(${name} mylib)
>>>     ADD_TEST(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
>>>     ADD_DEPENDENCIES(examples ${name})
>>> ENDMACRO(ADD_EXAMPLE)
>>> ADD_EXAMPLE(foo)
>>>
>>>
>>> ...but I always get this error:
>>> src/examples/CMakeLists.txt:5:
>>> ADD_DEPENDENCIES Adding dependency to non-existent target: examples
>>>
>>>
>>> What am I doing wrong?
>>
>> Ok, apparently ADD_DEPENDENCIES only works on targets *in the current 
>> directory*. So how do I add a dependency to a top-level target in the 
>> CMakeLists.txt of a subdirectory?
>
> Ok, I got this to work:
>
> MACRO(EXAMPLE_SUBDIRS)
>   SUBDIRS(${ARGV})
>   ADD_CUSTOM_TARGET(examples)
>   FOREACH(subdir ${ARGV})
>     ADD_CUSTOM_TARGET(examples_${subdir} cd ${subdir} && make examples)
>     ADD_DEPENDENCIES(examples examples_${subdir})
>   ENDFOREACH(subdir)
> ENDMACRO(EXAMPLE_SUBDIRS)
>
> MACRO(ADD_EXAMPLE prefix name)
>   ADD_EXECUTABLE(${name} EXCLUDE_FROM_ALL ${name}.c)
>   TARGET_LINK_LIBRARIES(${name} mylib)
>   ADD_TEST(${prefix}/${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
>   ADD_CUSTOM_TARGET(examples)
>   ADD_DEPENDENCIES(examples ${name})
> ENDMACRO(ADD_EXAMPLE)
>
> ...but this is exactly the sort of recursive calling of 'make' that 
> CMake is supposed to *avoid*! Surely there is a better way?!
>
Did you try ADD_SUBDIRECTORY instead of SUBDIRS?  Also, what version of
CMake are you using?

-Bill




More information about the CMake mailing list