# Example of using FetchContent to bring HDF5 ?

**URL:** <https://forum.hdfgroup.org/t/example-of-using-fetchcontent-to-bring-hdf5/12097>\
**Category:** C++ Users' Group\
**Created:** [March 19, 2024, 3:12pm UTC](https://forum.hdfgroup.org/t/example-of-using-fetchcontent-to-bring-hdf5/12097 "2024-03-19T15:12:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurent.aphecetche](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/laurent.aphecetche/32/1934_2.png) [@laurent.aphecetche](https://forum.hdfgroup.org/u/laurent.aphecetche)\
**Post date:** [March 19, 2024, 3:12pm UTC](https://forum.hdfgroup.org/t/example-of-using-fetchcontent-to-bring-hdf5/12097/1 "2024-03-19T15:12:47Z")

</div>

Dear all,

I’m looking for a working example of using FetchContent to bring HDF5 (and its CPP wrapper) into a larger CMake build.

I’m confused by what exactly I have to define prior to calling FetchContent and, more trivially, what kind of target names are supposed to be defined…

This is what I’ve tried :

```auto
include(FetchContent)

set(HDF5_ENABLE_SZIP_SUPPORT OFF CACHE INTERNAL "")
set(HDF5_ENABLE_SZIP_ENCODING OFF CACHE INTERNAL "")
set(HDF5_BUILD_EXAMPLES OFF CACHE INTERNAL "")
set(HDF5_BUILD_CPP_LIB ON CACHE INTERNAL "")
set(HDF5_ENABLE_Z_LIB_SUPPORT OFF CACHE INTERNAL "")
set(HDF5_EXTERNALLY_CONFIGURED 1 CACHE INTERNAL "")
set(HDF5_NAMESPACE hdf5::)
FetchContent_Declare(HDF5
  URL https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_14_3.tar.gz
  URL_HASH SHA256=df5ee33c74d5efb59738075ef96f4201588e1f1eeb233f047ac7fd1072dee1f6 
  DOWNLOAD_EXTRACT_TIMESTAMP FALSE
  FIND_PACKAGE_ARGS)
FetchContent_MakeAvailable(HDF5)

```

But during configure phase I get a `target was not found`, clearly indicating I’m misunderstanding how the target ought to be named…

```auto
CMake Error at utils/CMakeLists.txt:9 (target_link_libraries):
  Target "toashort-to-h5" links to:

    hdf5::hdf5

  but the target was not found. Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

```

Thanks,

---

<div class="post-metadata">

**Author:** ![byrn](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@byrn](https://forum.hdfgroup.org/u/byrn)\
**Post date:** [March 22, 2024, 1:20pm UTC](https://forum.hdfgroup.org/t/example-of-using-fetchcontent-to-bring-hdf5/12097/2 "2024-03-22T13:20:13Z")

</div>

Take a look at the HDF5 source for the config/cmake/HDFLibMacros.cmake file where we use FetchContent\_\* to compile in the zlib/libaec libs.  
Note that FetchContent\_MakeAvailable call is a combo of the

```auto
if(NOT hdf5_zlib_POPULATED)
    FetchContent_Populate

```

but after that if block, notice the add\_library and set commands; these would likely be equivalent to the ALIAS reason.
