How to ensure the recursed package location is in the same as its above

Is it automatically the default that a package location of recursive dependency is in the same as its dependent package above or we have to ensure, i.e. tell/instruct Cmake, to refer the recursed dependency package location?

e.g. the foobar package is to be found

foreach(FOOB   foo  bar)
   find_library(FOO_${FOOB}_LIBRARY   ${FOOB}
        HINTS
          "/usr"
        PATH_SUFFIXES
            lib/
       )
    if(FOO_${FOOB}_LIBRARY)
        list(APPEND FOO_LIBRARIES ${FOO_${FOOB}_LIBRARY})
    endif()
   endforeach()


find_package_handle_standard_args(foobar
    REQUIRED_VARS
        FOO_LIBRARIES
)

and
foo.so depends: baz.so
bar.so depends: baz.so

baz.so will be automatically found under /usr/lib by Cmake rule, or what syntax to ensure and order Cmake to do it?

You shouldn’t need to specify /usr manually; it is searched by default (unless some other cross-compilation-related settings are set). The lib/ suffixes is also unnecessary as it is searched automatically (e.g., it is wrong for Red Hat 64-bit distributions or Debian multi-arch).

CMake doesn’t know that foo and bar searches are related at all. Here is where you would use HINTS to use the directory or prefix of any previously found entries. Something like:

set(hints)
foreach(FOOB   foo  bar)
  find_library(FOO_${FOOB}_LIBRARY   ${FOOB}
    HINTS ${hints})
  if(FOO_${FOOB}_LIBRARY)
    list(APPEND FOO_LIBRARIES ${FOO_${FOOB}_LIBRARY})
    get_filename_component(…) # extract out some path component
    list(APPEND hints …)
  endif()
endforeach()
unset(hints)