# Using CMake FetchContent() to retrieve dependency's binaries, and not sources

**URL:** https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762
**Category:** Usage
**Created:** [January 3, 2024, 7:57am UTC](https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762 "2024-01-03T07:57:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [January 3, 2024, 7:57am UTC](https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762/1 "2024-01-03T07:57:18Z")

</div>

I am relatively new to CMake.

I want to use **libpng** , and so **zlib** , for my project.

After viewing some tutorials, it seems the standard way to do that is to retrieve the dependencies sources with `FetchContent()` or `ExternalProject_Add()`. But it seems me weird to build the dependencies each time, instead of retrieving include files and compiled files.

So I plan to build the needed libs, leave the zipped binaries on a Nexus server, and in the client project, use `FetchContent()` or `ExternalProject_Add()` to retrieve the zipped file. This one would contain include files, compiled files, and a **CMakeLists.txt** with `install` commands to put the .h and compiled files where there should be so that I can build my project. So I’ll do what Conan would do…

Is it a good process ? Is there a canonic way to do this ?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 11, 2024, 1:22pm UTC](https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762/2 "2024-01-11T13:22:40Z")

</div>

If you want binaries, just ask `conan` or something to install them. Trying to embed the logic in your project means that you need to detect what the current target is and download the right binaries. `conan`, `vcpkg`, and related tools already do this (hard problem) well enough. Then your project documents what is needed and uses `find_package()` to use them.

Cc: @craig.scott

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [January 11, 2024, 3:07pm UTC](https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762/3 "2024-01-11T15:07:21Z")

</div>

Well, I tried Conan, but for now, I cannot used it, because I have to pass a toolchain to CMake, and the call to CMake is mutualized in a batch script, and I cannot modify this one without impacting many other projects.

But if someone from KitWare suggest me to use Conan instead of resolving my problem, it is surely the right way. We must change our way to build our projects.

Thanks.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 11, 2024, 3:21pm UTC](https://discourse.cmake.org/t/using-cmake-fetchcontent-to-retrieve-dependencys-binaries-and-not-sources/9762/4 "2024-01-11T15:21:40Z")

</div>

> [@Oodini](#):
>
> But if someone from KitWare suggest me to use Conan instead of resolving my problem, it is surely the right way. We must change our way to build our projects.

It _can_ be. I don’t know your situation well enough to give a concrete suggestion. It’s just one way to get precompiled C++ binaries in a platform-agnostic way.
