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

**URL:** https://discourse.cmake.org/t/how-to-ensure-the-recursed-package-location-is-in-the-same-as-its-above/2938
**Category:** Usage
**Created:** [March 11, 2021, 7:49am UTC](https://discourse.cmake.org/t/how-to-ensure-the-recursed-package-location-is-in-the-same-as-its-above/2938 "2021-03-11T07:49:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![abd](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abd/32/1256_2.png) [@abd](https://discourse.cmake.org/u/abd)
#### Post date: [March 11, 2021, 7:49am UTC](https://discourse.cmake.org/t/how-to-ensure-the-recursed-package-location-is-in-the-same-as-its-above/2938/1 "2021-03-11T07:49:51Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 11, 2021, 6:09pm UTC](https://discourse.cmake.org/t/how-to-ensure-the-recursed-package-location-is-in-the-same-as-its-above/2938/2 "2021-03-11T18:09:09Z")

</div>

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:

```cmake
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)

```
