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

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 ?

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

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.

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.