[CMake] Creating dependencies after adding an external project?

Alexander Neundorf a.neundorf-work at gmx.net
Wed Apr 20 16:14:31 EDT 2011


On Wednesday 20 April 2011, Lori Pritchett-Sheats wrote:
> I have a project that depends on HDF5. A user can either specify an
> existing installation and thus use a find_package or choose to have HDF5
> built with the project.  I've been using Paraview as a template to
> implement this but I can't seem to get the dependencies for my project
> defined correctly when it builds HDF5.
>
> So what I'm doing is an ExternalProject_Add command like this:
>
> ExternalProject_Add(hdf5
>                         URL     ${HDF5_url}/${HDF5_gz}
>                         URL_MD5 ${HDF5_md5}
>                         UPDATE_COMMAND ""
>                         PREFIX  ${HDF5_prefix}
>                         CMAKE_ARGS
>                            -DBUILD_SHARED_LIBS:Bool=OFF
>                            -DBUILD_TESTING:Bool=OFF
>                            -DHDF5_ENABLE_Z_LIB_SUPPORT:Bool=ON
>                            -DZLIB_INCLUDE_DIR:STRING=${ZLIB_INCLUDE_DIR}
>                            -DZLIB_LIBRARY:STRING=${ZLIB_LIBRARY}
>                            -DHDF5_BUILD_HL_LIB:Bool=ON
>                            -DHDF5_BUILD_TOOLS:Bool=ON
>                            -DCMAKE_INSTALL_PREFIX:PATH=${HDF5_prefix}
>                         )
>
> and then to be consistent with the find_package logic, I define
> HDF5_INCLUDE_DIR, HDF5_LIBRARIES based on the installation paths I know
> eventually will exist like this
>
> set(HDF5_LIBRARY_DIR "${HDF5_prefix}/lib")
> set(HDF5_LIBRARY
> "${HDF5_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}hdf5${CMAKE_STATIC_LIBRA
>RY_PREFIX}") set(HDF5_HL_LIBRARY
> "${HDF5_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}hdf5_hl${CMAKE_STATIC_LI
>BRARY_PREFIX}")
>
> set(HDF5_LIBRARIES "${HDF5_HL_LIBRARY};${HDF5_LIBRARY}")
>
> and then when I need to build a binary that links against HDF5, I have
> in a CMakeLists.txt file
>
> add_executable(test.x ${test_src_files})
> target_link_libraries(test.x ${HDF5_LIBRARIES})
>
> But at build time I see errors complaining about "No rule to make target
> <path to HDF5_prefix>/libhdf5.a needed for test.x". I am confused. Do I

As the hdf5 external project been built ?
If not, you have to make sure via add_dependencies() that it gets build before 
the target which uses it is built.

Alex


More information about the CMake mailing list