[PR #655] CMake: Allow using BUILD_SHARED_LIBS to choose static/shared libs #1303

Closed
opened 2026-01-29 20:53:25 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/google/brotli/pull/655

State: closed
Merged: Yes


By convention projects using CMake which can build either static or shared libraries use a BUILD_SHARED_LIBS flag to allow selecting between both: the add_library() command automatically switches between both using this variable when the library kind is not passed to add_library(). It is also usual to expose the BUILD_SHARED_LIBS as an user-facing setting with the option() command.

This way, the following will both work as expected:

   % cmake -DBUILD_SHARED_LIBS=OFF ...
   % cmake -DBUILS_SHARED_LIBS=ON ...

This is helpful for distributions which need (or want) to build only static libraries.


The above being said, I understand that there might be some reason why it is desirable that both kinds of libraries are always built. If that is the case, let me know and I'll try to come up with some other way of allowing to only build static libraries, and installing them in a way that other projects trying to link with -lbrotli* (and/or using pkg-config) will find the static libraries.

**Original Pull Request:** https://github.com/google/brotli/pull/655 **State:** closed **Merged:** Yes --- By convention projects using CMake which can build either static or shared libraries use a `BUILD_SHARED_LIBS` flag to allow selecting between both: the `add_library()` command automatically switches between both using this variable when the library kind is not passed to `add_library()`. It is also usual to expose the `BUILD_SHARED_LIBS` as an user-facing setting with the `option()` command. This way, the following will both work as expected: ``` % cmake -DBUILD_SHARED_LIBS=OFF ... % cmake -DBUILS_SHARED_LIBS=ON ... ``` This is helpful for distributions which need (or want) to build only static libraries. ---- The above being said, I understand that there might be some reason why it is desirable that both kinds of libraries are always built. If that is the case, let me know and I'll try to come up with some other way of allowing to only build static libraries, and installing them in a way that other projects trying to link with `-lbrotli*` (and/or using `pkg-config`) will find the static libraries.
claunia added the pull-request label 2026-01-29 20:53:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#1303