I’m working on a C++ project using CMake, where I manage all my third-party dependencies using FetchContent exclusively (i.e no other package manager is installed nor run).
I use a combination of
FetchContent_Populate (as outlined in the documentation here), as so far this has worked without any problems for dependencies that are independent from each other, i.e only my own code required them (this includes libraries like SDL2, Dear ImGui, and glm)
Recently, I tried the same approach with msdf-atlas-gen. This library uses FreeType, which in turn uses zlib and libpng. Using the above approach, I added all dependencies, making sure to fetch them in the correct order so each dependency would be ready by the time their dependents were being fetched.
This did not work at first. The fetch succeeded, but the calls to
find_package in the CMake scripts of the above libraries could not find their dependencies. I then found this part of the documentation, and using
FetchContent_MakeAvailable, I was able to run the entire CMake script with no apparent issues (i.e no more error messages from
When I try to build the project, however, anything below zlib in the dependency chain is unable to find the zlib headers, and a similar issue happens with the dependencies that require libpng. When generating with Visual Studio, I checked the vcxproj files generated by CMake, and it seems neither the include directories, nor the libraries themselves were added.
I attached a minimal reproduction of the problem. I primarily use Visual Studio 2022 as my IDE and generator, though I have tested with Ninja as well. Am I missing something? Or is this an inherent limitation of FetchContent, and/or a problem with how the CMake scripts of the dependencies are configured?
FetchContentTest.zip (3.0 KB)