# FetchContent\_Declare and find\_package confusion

**URL:** <https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074>\
**Category:** Code\
**Created:** [February 13, 2024, 9:36am UTC](https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074 "2024-02-13T09:36:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)\
**Post date:** [February 13, 2024, 9:36am UTC](https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074/1 "2024-02-13T09:36:55Z")

</div>

Hi,

I am trying to use FetchContent\_Declare to ‘create’ a package I can later use with find\_package but haven’t had any luck so far. Here’s my little bit of test code:

```auto
FetchContent_Declare(json11-pkg
        GIT_REPOSITORY https://github.com/blitz-research/json11.git
        GIT_TAG master
        GIT_SUBMODULES ""
        GIT_SHALLOW TRUE
        OVERRIDE_FIND_PACKAGE
        )

FetchContent_MakeAvailable(json11-pkg)

message("### CMAKE_FIND_PACKAGE_REDIRECTS_DIR: ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}")

find_package(json11-pkg)

```

CMAKE\_FIND\_PACKAGE\_REDIRECTS\_DIR is always empty, and the find\_package(json11-pkg) always fails.

I haven’t had much experience with either FetchContent or find\_package so I suspect I’ve got entirely the wrong idea of what’s supposed to happen here (json11-pkg needs to be written ‘to be’ a package perhaps?), but I was hoping there was a way to get at the targets in json11-pkg so I could add their own include dirs and libs to my targets, they way I used to with eg: find\_package(OpenGL), OpenGL\_INCLUDE\_DIRS and OpenGL\_LIBRARIES.

Bye,  
Mark

---

<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:** [February 17, 2024, 6:27am UTC](https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074/2 "2024-02-17T06:27:16Z")

</div>

Cc: @craig.scott

---

<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:** [February 24, 2024, 9:03am UTC](https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074/3 "2024-02-24T09:03:43Z")

</div>

Your example works fine for me on macOS, and the redirects directory contains a generated `json11-pkg-config.cmake` and `json11-pkg-config-version.cmake` file as expected. You’ll need to provide more information about your error(s). Start by providing a complete, minimal project rather than just the snippet you included above in case there’s something not shown which is affecting you.

---

<div class="post-metadata">

**Author:** ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)\
**Post date:** [March 2, 2024, 8:02pm UTC](https://discourse.cmake.org/t/fetchcontent-declare-and-find-package-confusion/10074/4 "2024-03-02T20:02:06Z")

</div>

I made a standlone example and it worked first time, must be something else I’m doing!

Please close this for now.
