# BUILD\_INTERFACE or INSTALL\_INTERFACE genex with target\_link\_libraries?

**URL:** <https://discourse.cmake.org/t/build-interface-or-install-interface-genex-with-target-link-libraries/10765>\
**Category:** Code\
**Created:** [April 30, 2024, 3:31pm UTC](https://discourse.cmake.org/t/build-interface-or-install-interface-genex-with-target-link-libraries/10765 "2024-04-30T15:31:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)\
**Post date:** [April 30, 2024, 3:31pm UTC](https://discourse.cmake.org/t/build-interface-or-install-interface-genex-with-target-link-libraries/10765/1 "2024-04-30T15:31:41Z")

</div>

Hi,

While `BUILD_INTERFACE` and `INSTALL_INTERFACE` are explicitely mentioned in  
`target_include_directories` documentation, they don’t appear in `target_link_libraries` documentation. I’m thus wondering if their use is valid beyond `target_include_directories` context.

I’ve found very few questions/examples of `BUILD_INTERFACE` genex with `target_link_libraries` (_e.g._ [[CMake] BUILD\_INTERFACE genex used even in install(EXPORT…](https://cmake.org/pipermail/cmake/2014-November/059190.html) or [How to completely ignore BUILD\_INTERFACE libraries in installation?](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806). And they generally seem to address specific (awkward?) cases.

I nevertheless tried by myself. CMake accept such statements and the produced `tgt-config.cmake` file differs with/without use of genex.

So, taking `opencv_imgproc` imported target from `find_package(OpenCV REQUIRED COMPONENT imgproc)` as an example, `target_link_libraries(tgt PUBLIC opencv_imgproc)` yields to `opencv_imgproc` populating `tgt`’s `INTERFACE_LINK_LIBRARIES` property.

`target_link_libraries(tgt PRIVATE opencv_imgproc)` and `target_link_libraries(tgt PRIVATE $<BUILD_INTERFACE:opencv_imgproc>)` both yields to `opencv_imgproc` populating `tgt`’s `IMPORTED_LINK_DEPENDENT_LIBRARIES`, as if `BUILD_INTERFACE` genex had no effect.

By contrast, `target_link_libraries(tgt PUBLIC $<BUILD_INTERFACE:opencv_imgproc>)` makes `opencv_imgproc` totally disappears from `tgt-config.cmake`.

Regarding use of `INSTALL_INTERFACE` genex, `target_link_libraries(tgt PUBLIC $<INSTALL_INTERFACE:opencv_imgproc>)` yields to `opencv_imgproc` populating `tgt`’s `INTERFACE_LINK_LIBRARIES` property.

And `target_link_libraries(tgt PRIVATE $<INSTALL_INTERFACE:opencv_imgproc>)` makes `opencv_imgproc` totally disappears from `tgt-config.cmake`.

Are the statements with `BUILD_INTERFACE` or `INSTALL_INTERFACE` genex valid and how should they be read/understood?

Thanks.

---

<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:** [March 4, 2025, 9:09am UTC](https://discourse.cmake.org/t/build-interface-or-install-interface-genex-with-target-link-libraries/10765/2 "2025-03-04T09:09:11Z")

</div>

> [@emaschino](#):
>
> I’m thus wondering if their use is valid beyond `target_include_directories` context.

They are valid, but their uses are far more narrow.

> [@emaschino](#):
>
> And `target_link_libraries(tgt PRIVATE $<INSTALL_INTERFACE:opencv_imgproc>)` makes `opencv_imgproc` totally disappears from `tgt-config.cmake`.

If `tgt` is a `SHARED` library, this makes sense as private dependencies of `SHARED` libraries are not exported.

The behaviors here make sense to me. The `*_INTERFACE` genexes _only_ make things disappear from the build (non-`PROJECT_INTERFACE` and non-`BUILD_INTERFACE` iface genexes), `export()` (non-`BUILD_INTERFACE` iface genexes) and `install(EXPORT)` (non-`INSTALL_INTERFACE` iface genexes) information. If some information is not exported anyways (like `PRIVATE` compile options), the genexes have no useful effect (they’re either always expanded or ignored).
