[CMake] ExternalProject_Add and Dependent Targets

Lori Pritchett-Sheats lpritch at lanl.gov
Thu Sep 22 10:13:20 EDT 2011



David Cole wrote:
> On Wed, Sep 21, 2011 at 11:45 AM, Lori Pritchett-Sheats
> <lpritch at lanl.gov> wrote:
>   
>> Reading the documentation it is not clear how the DEPENDS option works in
>> ExternalProject_Add.
>>
>> For example, I add HDF5 to my build and HDF5 depends on zlib the following
>> doesn't work
>>
>> find_package(ZLIB)
>> add_library(zlib UNKNOWN IMPORTED)
>> set_target_properties(zlib PROPERTIES IMPORTED_LOCATION ${ZLIB_LIBRARY})
>>
>> ExternalProject_Add(hdf5 DEPENDS zlib ......)
>>
>> throws an error with the message 'No rule to make /zlib-done', needed by
>> external_projects/src/hdf5-stamp/hdf5-configure
>>
>> For ExternalProject_Add, are the targets listed under the DEPENDS option
>> only targets that will be built with another ExternalProject_Add, not
>> existing libraries?
>>
>>     
>
> That's correct.
>
> The first argument to ExternalProject_Add does become the name of a
> custom target, though. So after the ExternalProject_Add call, you can
> do:
>
> ExternalProject_Add(hdf5 ...)
>
> add_dependencies(hdf5 zlib)
>
> However, in this particular case, you are finding an existing zlib and
> then using an imported target to say where it is *for other
> non-external project targets in the same CMake build*... For the
> ExternalProject build of hdf5, you're going to have to pass down in
> the location of zlib via some arguments, because the ExternalProject
> build knows nothing about the context of what else is built in the
> current CMake build...
>
> So in this particular case, the hdf5 custom target does not actually
> depend (in a build order sense) on the zlib target -- because the zlib
> target doesn't build anything, it's just imported. So you don't
> actually need the dependency... you just need to tell hdf5 where zlib
> is.
>
> Does that make sense?
>
>
> HTH,
> David
>
>   

I think so. The HDF5 configuration has switch options to pass in the 
zlib include and library path, both are available once I call 
find_package(ZLIB). But if I'm building a library that depends on HDF5 I 
need to include the zlib target in the dependency definitions, correct?

If I'm understanding this correctly, after the ExternalProject_Add call, 
I need to define HDF5_INCLUDE_PATH, HDF5_LIBRARIES, since the project 
will not exist when CMake runs. Then when I create a library or 
executable that needs the HDF5 libraries for linking, I would do the 
following:

add_library(mylib ${some_source})
target_link_libraries(mylib ${HDF5_LIBRARIES} zlib)


-- 
Lori A. Pritchett-Sheats, PhD.
CCS-2, Computational Physics and Methods
Office: 505-665-6675
Fax: 505-665-4972

Los Alamos National Laboratory
P.O. Box 1663
MS D413
Los Alamos, NM 87544



More information about the CMake mailing list