简体   繁体   中英

CMake dependencies between libraries and programs

I'm a beginner with CMake and since yesterday I try something without result :-(

I explain my goal... I've a C++ project with dynamic libraries and programs using these libraries.

Here is the structure of my project:

  • libA
  • libB
  • program1
  • program2
  • program3

Inside each directory, I've an include and a src directory.

libB uses libA, program1 program2 and program3 use libA and libB.

I've a CMakeLists.txt in each directory (even in the root directory). I'm able to build each lib and program individually (without dependencies) but I don't know how to define dependencies between them.

For example, I would like the include files of the libraries to be known by the programs, the same for the link of .dll

Could someone help me on this topic? Thanks for your answers :-)

Regards.

how to define dependencies between them.

Just, in respective CMakeLists:

target_link_libraries(program1 PRIVATE libA libB)
target_link_libraries(program2 PRIVATE libA libB)
target_link_libraries(program3 PRIVATE libA libB)
target_link_libraries(libB PUBLIC LIBA)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM