# Subdirectories dependent on each other?

**URL:** https://discourse.cmake.org/t/subdirectories-dependent-on-each-other/6402
**Category:** Usage
**Created:** [September 3, 2022, 9:06pm UTC](https://discourse.cmake.org/t/subdirectories-dependent-on-each-other/6402 "2022-09-03T21:06:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RobN](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@RobN](https://discourse.cmake.org/u/RobN)
#### Post date: [September 3, 2022, 9:06pm UTC](https://discourse.cmake.org/t/subdirectories-dependent-on-each-other/6402/1 "2022-09-03T21:06:28Z")

</div>

Hi,

I’m just starting to use CMake, and I’m following the [tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html). In steps 2 and 3, it shows you how to use `add_subdirectory(...)` to add a library. I tried to apply this to my project, which has a structure like this:

```auto
MyApp/
  MyLibA/
  MyLibB/
  fmt/ (from https://fmt.dev/)

```

Following the tutorial, my library subdirs have a very basic `CMakeLists.txt`, like:

```auto
add_library(MyLibA Foo.cc Bar.cc)
target_include_directories(MyLibA
    INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)

```

This works. `MyApp` can use `MyLibA`, `MyLibB`, and `fmt`.

What is the right way to I say that `MyLibA` uses `fmt` or `MyLibB`?

Rob

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [September 3, 2022, 11:04pm UTC](https://discourse.cmake.org/t/subdirectories-dependent-on-each-other/6402/2 "2022-09-03T23:04:42Z")

</div>

You do something like:

```nohighlight
target_link_libraries(MyLibA
    PUBLIC
        MyLibB
    PRIVATE
        fmt
)

```

Usage of `PUBLIC` or `PRIVATE` depends on your needs.
