FetchContent_Declare and find_package confusion

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:

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

Cc: @craig.scott

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.

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

Please close this for now.