Why does find_package() work when built standalone, but fails when the same project is included via add_subdirectory() in another CMake project? [closed]

15 hours ago 1
ARTICLE AD BOX

Here's my setup:

TopLevel/ -- CMakeLists.txt -- SubLevel/ ------ CMakeLists.txt

SubLevel has find_package(abc CONFIG REQUIRED), which works fine when I call the cmake command on the SubLevel alone, but it fails if I try to call it on TopLevel's CMakeLists.txt which adds SubLevel as a subdirectory.

About the TopLevel CMakeLists.txt:

does add_subdirectory(SubProject)

does not do any target linking as of yet

it is a part of QtProject

About SubLevel CMakeLists.txt:

does find_package(), for multiple 3rd party dependencies

uses vcpkg for its own external dependencies and does : include("blah/......./blah/vcpkg.cmake")

CMake can't find the first package and exits early.

Read Entire Article