# How to completely ignore BUILD\_INTERFACE libraries in installation?

**URL:** <https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806>\
**Category:** Code\
**Created:** [April 1, 2023, 4:12pm UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806 "2023-04-01T16:12:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gccore](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gccore/32/3299_2.png) [@gccore](https://discourse.cmake.org/u/gccore)\
**Post date:** [April 1, 2023, 4:12pm UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806/1 "2023-04-01T16:12:44Z")

</div>

Through that, I link private libraries with BUILD\_INTERFACE genexpr and they wouldn’t be in the exported targets, but the libraries’ linked libraries will be and unfortunately when we run the install rule they will be installed. And i don’t have access to those libraries’ code to change. How can I remove those targets from being installed?

For testing:

**TestingExports.text**

```cmake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(TestinExports CXX)

add_subdirectory(ThatThing)

file(WRITE main.cc "int main() { }")
add_executable(${PROJECT_NAME} main.cc)
target_link_libraries(${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:ThatThing>)

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config)
install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake)

```

**ThatThing/CMakeLists.txt**

```cmake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(ThatThing CXX)

add_subdirectory(ThoseLibraries)

file(WRITE that_thing.cc "void Function() { }")
add_library(${PROJECT_NAME} STATIC that_thing.cc)
target_link_libraries(${PROJECT_NAME} PRIVATE ThoseLibraries)

```

**ThatThing/ThoseLibraries/CMakeLists.txt**

```cmake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(ThoseLibraries CXX)

file(WRITE those_libraries.cc "void AnotherFunction() { }")
add_library(${PROJECT_NAME} STATIC those_libraries.cc)

install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config)
install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake)

```

After we build and install we can see that `ThoseLibraries` is also installed:

```bash
$ cmake -B build -DCMAKE_INSTALL_PREFIX=$PWD/install
$ cmake --build build
$ cmake --install build
-- Install configuration: ""
-- Installing: /tmp/export_set/install/lib/libThoseLibraries.a
-- Installing: /tmp/export_set/install/lib/cmake/ThoseLibrariesConfig.cmake
-- Installing: /tmp/export_set/install/lib/cmake/ThoseLibrariesConfig-noconfig.cmake
-- Installing: /tmp/export_set/install/bin/TestinExports
-- Installing: /tmp/export_set/install/lib/cmake/TestinExportsConfig.cmake
-- Installing: /tmp/export_set/install/lib/cmake/TestinExportsConfig-noconfig.cmake

```

---

<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:** [April 3, 2023, 11:43am UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806/2 "2023-04-03T11:43:35Z")

</div>

> [@gccore](#):
>
> ```auto
> project(ThoseLibraries CXX)
> # …
> install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config)
> install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake)
> 
> ```

You’ll need to mask these `install()` commands somehow.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [April 4, 2023, 6:49am UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806/3 "2023-04-04T06:49:06Z")

</div>

For me the most successful strategy has been to always use components for my install commands, then set CPack variables so that only my components would get installed.

---

<div class="post-metadata">

**Author:** ![amaarten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@amaarten](https://discourse.cmake.org/u/amaarten)\
**Post date:** [April 20, 2023, 12:45am UTC](https://discourse.cmake.org/t/how-to-completely-ignore-build-interface-libraries-in-installation/7806/4 "2023-04-20T00:45:08Z")

</div>

I handle this case by adding `EXCLUDE_FROM_ALL` to `add_subdirectory()`.

```cmake
add_subdirectory(ThoseLibraries EXCLUDE_FROM_ALL)

```
