# FetchContent\_Populate with custom unpacker

**URL:** https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679
**Category:** Code
**Created:** [May 17, 2022, 6:57am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679 "2022-05-17T06:57:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [May 17, 2022, 6:57am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679/1 "2022-05-17T06:57:45Z")

</div>

How to use `FetchContent_Populate` and a custom unpack function? In my case there is a nested tar archive that needs to be unpacked.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 17, 2022, 9:27am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679/2 "2022-05-17T09:27:07Z")

</div>

Sounds like you want to have it download the archive, but not unpack it, then add your own custom command to do the unpacking. You can use the `DOWNLOAD_NO_EXTRACT` option to do the first part (the `ExternalProject` docs explain how to use it). Then you could add a custom step using `ExternalProject_AddStep()` with the `COMMAND` that invokes your custom unpacker. Make sure to set up the dependencies between your custom step and the ones to come before and after it so that you get it invoked when required.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [May 17, 2022, 10:46am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679/3 "2022-05-17T10:46:25Z")

</div>

Does that mean I need to do this entirely with `ExternalProject` instead of `FetchContent`? So effectively the download step happens as part of the build step instead of at the configure step?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 17, 2022, 11:10am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679/4 "2022-05-17T11:10:00Z")

</div>

Ugh, yes, sorry, I mixed two things. Had my head buried in other things. What I mentioned would be appropriate for using ExternalProject, but not quite for FetchContent. You can still use the `DOWNLOAD_NO_EXTRACT` keyword, but instead of adding a custom step, I guess you could abuse the `PATCH_COMMAND` to do the unpacking for you instead.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [May 18, 2022, 11:56am UTC](https://discourse.cmake.org/t/fetchcontent-populate-with-custom-unpacker/5679/5 "2022-05-18T11:56:10Z")

</div>

I kept `FetchContent_Populate` but added a `UPDATE_COMMAND` to do a second unpack of the tar file.
