# Build a library with different options in one run

**URL:** <https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485>\
**Category:** Code\
**Created:** [November 22, 2023, 4:12pm UTC](https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485 "2023-11-22T16:12:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSergeyP](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/8baadc/32.png) [@KSergeyP](https://discourse.cmake.org/u/KSergeyP)\
**Post date:** [November 22, 2023, 4:12pm UTC](https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485/1 "2023-11-22T16:12:28Z")

</div>

I have several configurations in my main project and each configuration depends on an external library. But for different configurations it is necessary to compile this library with different options. The library is compiled along with the main project. How can I create multiple targets by connecting the same subdirectory several times with different options?

---

<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:** [November 22, 2023, 9:37pm UTC](https://discourse.cmake.org/t/build-a-library-with-different-options-in-one-run/9485/2 "2023-11-22T21:37:25Z")

</div>

```cmake
foreach (variant IN LISTS variants)
  add_subdirectory(src "${CMAKE_CURRENT_BINARY_DIR}/src-${variant}")
endforeach ()

```
