Subdirectories dependent on each other?

Hi,

I’m just starting to use CMake, and I’m following the tutorial. 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:

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

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

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

You do something like:

target_link_libraries(MyLibA
    PUBLIC
        MyLibB
    PRIVATE
        fmt
)

Usage of PUBLIC or PRIVATE depends on your needs.

1 Like