Skip to content

Using FetchContent with OVERRIDE_FIND_PACKAGE across ExternalProject boundary

I have a case that seems to not be working fully.

I'm pulling in Google test with:

FetchContent_Declare(
    GTest
    GIT_REPOSITORY ...
    GIT_TAG ...
    GIT_SHALLOW TRUE
    OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(GTest)

Then I'm doing a find_package(GTest REQUIRED) and I'm verifying that GTest::gtest exists as a target. That all works as expected within the same project.

However, I then call

ExternalProject_Add(SomeProject
    SOURCE_DIR ...
    BINARY_DIR ...
    BUILD_ALWAYS 0
    CMAKE_CACHE_ARGS ...
    DEPENDS ... GTest::gtest
)

Within SomeProject, I call find_package(GTest REQUIRED) that succeeds. However, there are no targets actually defined.

if(NOT TARGET GTest::gtest)
    message(FATAL_ERROR "Unable to find GTest targets even though GTest is 'found'")
endif()

When I run this, I hit this fatal error.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information