# Private Linking Public Compile Usage

**URL:** https://discourse.cmake.org/t/private-linking-public-compile-usage/7998
**Category:** Usage
**Created:** [April 27, 2023, 12:56pm UTC](https://discourse.cmake.org/t/private-linking-public-compile-usage/7998 "2023-04-27T12:56:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![abdelmaged](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abdelmaged/32/3176_2.png) [@abdelmaged](https://discourse.cmake.org/u/abdelmaged)
#### Post date: [April 27, 2023, 12:56pm UTC](https://discourse.cmake.org/t/private-linking-public-compile-usage/7998/1 "2023-04-27T12:56:41Z")

</div>

Is there a way when linking with target to link privately and make the compile usage requirements public ?

Example

```auto
add_library(A STATIC a.c)
target_include_directories(A PUBLIC "dir1")
target_compile_definitions(A PUBLIC "A_DEFINE")

add_library(B SHARED b.c)
target_link_libraries(B PRIVATE A)

add_library(C SHARED c.c)
target_link_libraries(C PRIVATE B)

```

I want B library to link with A.  
B includes & compile defs. to have A interface includes and & compile defs as PUBLIC.  
So that, library C is not linking with B, but has includes & compile defs. of A propagated to it through library B.

I know I can set B includes & compile defs as:

```auto
target_include_directories(B PUBLIC "$<TARGET_PROPERTY:A,INTERFACE_INLCUDE_DIRECTORIES>")
target_compile_definitions(B PUBLIC "$<TARGET_PROPERTY:A,INTERFACE_COMPILE_DEFINITIONS>")

```

But I thought this could be too much, and probably there is easier way 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: [May 1, 2023, 3:13pm UTC](https://discourse.cmake.org/t/private-linking-public-compile-usage/7998/2 "2023-05-01T15:13:10Z")

</div>

You’re probably interested in [this MR](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8411) which adds `$<COMPILE_ONLY>`. You could then do:

```cmake
target_link_libraries(B
  PUBLIC
    "$<COMPILE_ONLY:A>"
  PRIVATE
    A)

```
