[CMake] How to add dependencies to ExternalProject_Add()

Rolf Eike Beer eike at sf-mail.de
Mon Mar 28 11:14:56 EDT 2011


> On Mon, Mar 28, 2011 at 10:48 AM, Rolf Eike Beer <eike at sf-mail.de> wrote:
>
>> > I came up with this simple diff which makes everything work smoothly
>> for
>> > me:
>>
>> This also works for me and should properly detect if the dependency is
>> itself an external target or not:
>>
>> diff --git a/Modules/ExternalProject.cmake
>> b/Modules/ExternalProject.cmake
>> index 3de6b7e..90b23ce 100644
>> --- a/Modules/ExternalProject.cmake
>> +++ b/Modules/ExternalProject.cmake
>> @@ -1261,8 +1261,14 @@ function(_ep_add_configure_command name)
>>    set(file_deps)
>>   get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
>>   foreach(dep IN LISTS deps)
>> +    # Find out if this dependency is itself an external target or not.
>> +    # If it doesn't have _EP_STAMP_DIR we assume it's a normal target.
>>      get_property(dep_stamp_dir TARGET ${dep} PROPERTY _EP_STAMP_DIR)
>> -    list(APPEND file_deps ${dep_stamp_dir}${cfgdir}/${dep}-done)
>> +    if(dep_stamp_dir)
>> +      list(APPEND file_deps ${dep_stamp_dir}${cfgdir}/${dep}-done)
>> +    else(dep_stamp_dir)
>> +      list(APPEND file_deps ${dep})
>> +    endif(dep_stamp_dir)
>>    endforeach()
>>
>>   get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND
>> SET)

> I am not sure I like this patch, or not. I'm on the fence.
>
> I would recommend just using:
>
>   ExternalProject_Add(xyz ...)
>   add_dependencies(xyz mylib)
>
> to add non-ExternalProject dependencies. Just to make it clear that the
> dependencies are target-level dependencies and not file dependencies.

This only "sort-of" works. If I delete the library from the build try
(only the .so) and rebuild the external project does not get relinked.
Also the documentation of ExternalProject_Add says:

  [DEPENDS projects...]       # Targets on which the project depends

No word that these need to be file-level dependencies. In fact since
ExternalProject.cmake unconditionally uses the _EP_STAMP_DIR property of
the target this will only work with ExternalProject targets at all (not
even file level dependencies) which looks just wrong to me.

Eike


More information about the CMake mailing list