Why is that the case? Why does it need to be in the root CMakeLists.txt?
find_package()
creates variables and targets in the scope from which it is called. The imported targets it creates are non-global by default, so those won’t be visible to sibling scopes. Similarly, variables created by the call are also not visible to sibling scopes because subdirectories create a new variable scope. So if you need to reference something defined by find_package()
, then you need to ensure that find_package()
call is in the same directory or a parent directory.