# Exposing BUILD\_SHARED\_LIBS via option?

**URL:** <https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595>\
**Category:** Code\
**Created:** [June 19, 2021, 10:28am UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595 "2021-06-19T10:28:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [June 19, 2021, 10:28am UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595/1 "2021-06-19T10:28:14Z")

</div>

I have a best practices question. I read in the documentation regarding `BUILD_SHARED_LIBS`:  
[https://cmake.org/cmake/help/latest/variable/BUILD\_SHARED\_LIBS.html](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html)

This documentation contains the following passage:

> This variable is often added to projects as an `option()` so that each user of a project can decide if they want to build the project using shared or static libraries.

But exposing that variable as an option will affect all dependent cmake projects as well, which might interfere with these projects. Thus, shouldn’t it be considered bad practice to expose the `BUILD_SHARED_LIBS` as an option?

---

<div class="post-metadata">

**Author:** ![eri0](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eri0/32/733_2.png) [@eri0](https://discourse.cmake.org/u/eri0)\
**Post date:** [June 19, 2021, 3:31pm UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595/2 "2021-06-19T15:31:08Z")

</div>

I always use LIBNAME\_BUILD\_SHARED\_LIBS or PROJECTNAME\_BUILD\_SHARED\_LIBS instead to avoid leaking as you mention.

---

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [June 20, 2021, 1:03pm UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595/3 "2021-06-20T13:03:34Z")

</div>

Do you at the same time link your project prefixed version with the global version?

---

<div class="post-metadata">

**Author:** ![eri0](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eri0/32/733_2.png) [@eri0](https://discourse.cmake.org/u/eri0)\
**Post date:** [June 20, 2021, 11:44pm UTC](https://discourse.cmake.org/t/exposing-build-shared-libs-via-option/3595/4 "2021-06-20T23:44:03Z")

</div>

No. But I don’t know what’s best practice either, I just started doing it once I added a project that had BUILD\_SHARED\_LIBS as an option and it turned my statically linked project into a bunch of .dll out of nowhere. 😅
