CMake target_link_libraries Interface Dependencies

后端 未结 3 494
攒了一身酷
攒了一身酷 2020-12-07 07:46

I am new to CMake and a bit confused with the PUBLIC, PRIVATE and INTERFACE keywords related to target_link_libraries(). Documentation mentions that they can be used to spec

3条回答
  •  借酒劲吻你
    2020-12-07 08:34

    @steveire accepted answer is great. I just wanted to add a table to quickly see the difference:

    .-----------.------------------.----------------.
    |           | Linked by target | Link interface |
    :-----------+------------------+----------------:
    | PUBLIC    |        X         |        X       |
    :-----------+------------------+----------------:
    | PRIVATE   |        X         |                |
    :-----------+------------------+----------------:
    | INTERFACE |                  |        X       |
    '-----------'------------------'----------------'
    
    • Linked by target: libraries included in target sources (not a dependency for projects linking the library).
    • Link interface: libraries included in target public headers (dependencies for projects linking the library).

提交回复
热议问题