# Configuration error when fetching two dependencies when there is a dependency between them

**URL:** <https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225>\
**Category:** Code\
**Created:** [August 7, 2022, 11:42pm UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225 "2022-08-07T23:42:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [August 7, 2022, 11:42pm UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/1 "2022-08-07T23:42:27Z")

</div>

I was hoping to pull in both zeromq and azmq (asio binding) for a personal project. I’m using CMake 3.23 on Windows 10 with Visual Studio 2019 MSVC.

In my project CMake I do this:

```auto
FetchContent_Declare(
    zeromq
    GIT_REPOSITORY https://github.com/zeromq/libzmq
    GIT_TAG v4.3.4
    GIT_SHALLOW TRUE
    GIT_PROGRESS TRUE
)
FetchContent_Declare(
    azmq
    GIT_REPOSITORY https://github.com/zeromq/azmq.git
    GIT_TAG v1.0.3
    GIT_SHALLOW TRUE
    GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(zeromq azmq)

```

but when CMake tries to configure azmq, it can’t find zeromq.

```auto
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find ZeroMQ (missing: ZeroMQ_INCLUDE_DIRS ZeroMQ_LIBRARIES)
  (Required is at least version "4.0")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  D:/Projects/build-QWar-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/_deps/azmq-src/config/FindZeroMQ.cmake:77 (find_package_handle_standard_args)
  D:/Projects/build-QWar-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/_deps/azmq-src/CMakeLists.txt:43 (find_package)

-- Configuring incomplete, errors occurred!
See also "D:/Projects/build-QWar-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/CMakeFiles/CMakeOutput.log".
See also "D:/Projects/build-QWar-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/CMakeFiles/CMakeError.log".
CMake process exited with exit code 1.

```

I was reading here [1] and the example shown was this, which seems like just what I’m doing.

```auto
# CORRECT: All details declared first, so they will take priority
FetchContent_Declare(uses_other ...)
FetchContent_Declare(other ...)
FetchContent_MakeAvailable(uses_other other)

```

Any tips to allow azmq to find zeromq when they’re both fetched dependencies with FetchContent? Or is there something obvious I’ve got wrong.  
p.s. I believe I’ve tried all permutations of the ordering of the Declare statements and the ordering within the MakeAvailable statement.

EDIT: I can see now I misread the example from the CMake FetchContent documentation. It assumes the `uses_other` project internally uses FetchContent to get `other`. So now I’m back to questioning if I can do what I’m trying to do. I certainly don’t think I can use CMAKE\_PREFIX\_PATH to add in some build folder path to help azmq find zeromq.

MORE EDIT: Yeah I think I’m completely off on this. There’s no way for a project fetched as source to find at configure time an already-built library from a 2nd project that was fetched as source. I’ll leave this comment up for a bit longer in case there are helpful comments but I suspect I need to find an alternate approach. My goal was to allow a person to grab my project and automatically get the external dependencies.

[1] [https://cmake.org/cmake/help/latest/module/FetchContent.html](https://cmake.org/cmake/help/latest/module/FetchContent.html)

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [August 8, 2022, 4:57am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/2 "2022-08-08T04:57:56Z")

</div>

Maybe the changes in CMake 3.24 can help you:

> The “FetchContent” module and the  
> “find\_package()” command now  
> support integration capabilities.

---

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [August 8, 2022, 1:41pm UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/3 "2022-08-08T13:41:06Z")

</div>

I had looked at the new options and hoped they would help, but I don’t think they do in my case.

---

<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:** [August 10, 2022, 1:35am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/4 "2022-08-10T01:35:10Z")

</div>

> [@Rich\_von\_Lehe](#):
>
> There’s no way for a project fetched as source to find at configure time an already-built library from a 2nd project that was fetched as source. I’ll leave this comment up for a bit longer in case there are helpful comments but I suspect I need to find an alternate approach. My goal was to allow a person to grab my project and automatically get the external dependencies.

As @hsattler mentioned, the new `FetchContent` / `find_package()` integration in CMake 3.24 might help you here. A key observation that may be tripping you up at the moment is that the dependency name is case-sensitive. You are specifying `zeromq` in your `FetchContent` calls, but the `find_package()` calls inside `azmq` will be looking for `ZeroMQ`. Since `ZeroMQ` is the canonical name for the dependency, your `FetchContent` calls should use exactly the same thing. If you do that, you can add the `OVERRIDE_FIND_PACKAGE` keyword to your `FetchContent_Declare(ZeroMQ)` call and I think you’ll end up with the behavior you’re after. This assumes that building `ZeroMQ` from source as part of the main build provides all the things that `azmq` expects. If `azmq` uses any variables that `find_package(ZeroMQ`) would normally provide, you may need to do some extra work to handle that. Creating a `zeromq-extra.cmake` or `ZeroMQExtra.cmake` file in the [CMAKE\_FIND\_PACKAGE\_REDIRECTS\_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_PACKAGE_REDIRECTS_DIR.html) which sets those variables would be the way to do that.

---

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [August 12, 2022, 2:30am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/5 "2022-08-12T02:30:49Z")

</div>

Hi Craig,

Thanks for the clarifications. I had tried using the canonical package name of ‘ZeroMQ’ earlier as well. I didn’t try the new OVERRIDE\_FIND\_PACKAGE and I’ll admit I didn’t fully understand it until now.

I would definitely need to do the extra work you describe because azmq is looking for these variables to be set: `ZeroMQ_INCLUDE_DIRS ZeroMQ_LIBRARIES`. That extra work is what I’m experimenting with now and I just need to get it to work.

My only question would be: is this an intended use case for FetchContent or would I be better off switching to ExternalProject\_Add? I thought I read in a blog somewhere recently that FetchContent is geared towards projects that you control and ExternalProject is better for those you don’t control.

---

<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:** [August 12, 2022, 6:11am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/6 "2022-08-12T06:11:23Z")

</div>

I wouldn’t say ExternalProject is better for projects you don’t control. The advice I would normally give is to avoid mixing ExternalProject with non-ExternalProject things. Put another way, either go a full superbuild where everything is brought in via ExternalProject (so your main project is just acting as a layer that co-ordinates the different external projects), or avoid using ExternalProject. Otherwise, you end up having to manually specify a bunch of platform-dependent stuff. For me personally, I tend to look at using FetchContent first, and only fall back to ExternalProject for those cases where FetchContent isn’t appropriate (e.g. uses a different toolchain, has targets with names that clash with other things, sets or uses cache variables that have side effects on the rest of the build, etc.).

For FetchContent, it is certainly well-suited to dependencies you are in control of. However, you can also use it for other dependencies too, as long as they are well-behaved. The new features around integration with `find_package()` give you more flexibility, opening up opportunities for using FetchContent where it wasn’t really possible before. Keep an eye on [this post](https://discourse.cmake.org/t/fetchcontent-in-dependency-management/6038), where I intend to provide some clearer guidance on this area once I get some other tasks out of the way.

---

<div class="post-metadata">

**Author:** ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)\
**Post date:** [September 6, 2022, 2:59am UTC](https://discourse.cmake.org/t/configuration-error-when-fetching-two-dependencies-when-there-is-a-dependency-between-them/6225/7 "2022-09-06T02:59:59Z")

</div>

Just following up on this thread to say that FetchContent did essentially work with the addition of Craig’s OVERRIDE\_FIND\_PACKAGE. My issue turned out to be a fairly finicky FindZeroMQ.cmake file in azmq that I ended up updating to allow it to find the copy I built and installed. It was written to expect some visual studio naming convention for the library file on Windows but I had built it outside that IDE. Anyway - it is working like a champ for me and even worked with recursive fetching.
