-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: Allow using BUILD_SHARED_LIBS to choose static/shared libs #655
Conversation
923d02e
to
b60b613
Compare
I have just pushed an update which modifies the |
For some more context (and an example), I am trying to address building for an Linux uCLibc target which uses only static libraries, like in this Buildroot build — and in general making it easier for getting only static libraries as a result of the build, with the same base names as the shared libraries. |
Can't remember the full motivation, but we moved to static+shared build in #599. |
@eustas: I saw the But then distributors need to trust that renaming libraries ( Do you think it would be more acceptable to leave both targets for static and shared libraries, then when
Once again, thank you for your time, and let me be clear that I just want to try to make it easier for packagers to adopt the library, and that I don't have anything against building both version by default 😉 |
Perhaps the change was done to fix #542. Going to dig in further. Conceptually, there are no "contra" against this shared/static switch, while all parties (developers/distros) are happy =) |
In case it helps: I have been looking a bit at the woff2 CMake build definitions, and it does use |
Here is a commit that would allow disabling shared/static libraries build (or both =). WDYT? |
I think the reason to have both shared and static is that brotli tool is build "static" (for grab-and-go scenario), but libraries are "shared", because it is what they are created for... |
b60b613
to
7289e5a
Compare
✅ Build brotli 1.0.0#1398 completed (commit 86e54fca39 by @aperezdc) |
@eustas Coming back to this topic... The solution proposed in fb139e4 works fine with
But using I think the approach in fb139e4 would do if the |
I would be interested in reactivating this PR. @eustas Would you be open to this approach or prefer to use your commit as stated in fb139e4 ? My motivation is that in conda-forge, we as a distribution prefer dynamic linkage as this is manageable by our toolchain and static libraries aren't used but consume unnecessary space in the packages. |
7289e5a
to
3ae04cd
Compare
I have updated the patch to work with the current state of the tree, which also works for version 1.0.9—something like this is still desired for packaging in Buildroot so for now it will continue carrying this patch to be applied after unpacking the sources. Please let me know if there is some other way in which I could improve these changes to have them merged, I would be more than happy to iterate over the patch and have it included in Brotli 😸 |
The CIFuzz failure is caused by the projects/brotli/build.sh script in the |
✅ Build brotli 1.0.0#1531 completed (commit 2dad627000 by @aperezdc) |
3ae04cd
to
6cb1632
Compare
✅ Build brotli 1.0.0#1532 completed (commit e29904ab22 by @aperezdc) |
I see #766 was merged and released in 1.0.8. Is this PR now obsolete? |
@delroth It's not the same, note that #766 only allows to disable building shared libraries, but does not remove the |
Hello. Are the old ( |
Yes, the
|
6cb1632
to
9243cfa
Compare
Patch rebased, and |
✅ Build brotli 1.0.0#1611 completed (commit 8b5919313a by @aperezdc) |
Is it currently possible to build both shared and static libraries? This would be the ideal use case for me: Being able to control their existence independently, so that you can also build both (with the same name, e.g. Some Linux distributions aim to build both flavours where possible, so that the end developer can choose between static and dynamic linking easily. |
9243cfa
to
592cd48
Compare
Thanks! I had to apply this patch as well: --- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -221,14 +221,12 @@ if(NOT BROTLI_BUNDLED_MODE)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
- if(NOT BROTLI_EMSCRIPTEN)
- install(
- TARGETS ${BROTLI_LIBRARIES_CORE}
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
- )
- endif() # BROTLI_EMSCRIPTEN
+ install(
+ TARGETS ${BROTLI_LIBRARIES_CORE}
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ )
install(
DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli To ensure that the libraries are still installed when compiling with Emscripten. |
LGTM modulo comments |
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.
592cd48
to
f83cb49
Compare
This PR does not change the existing logic for installation (which is: when targeting Emscripten, an install target for the libraries is not configured); if you want to suggest a change in that regard, that would be a separate issue/PR instead. |
@eustas I have submitted an update with your suggestions, PTAL. Also the Bazel CI build is failing, but this patch only touches the CMake build—likely the Bazel build failure is caused by something completely different. |
FWIW, commit ce222e3 fixes that and this PR would cause a regression in that regard (i.e. it causes static libraries not to be installed when
Sure, that comment was more FYI. I'll open a separate PR for that after this lands. |
Thanks! |
…ogle#655) 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.
By convention projects using CMake which can build either static or shared libraries use a
BUILD_SHARED_LIBS
flag to allow selecting between both: theadd_library()
command automatically switches between both using this variable when the library kind is not passed toadd_library()
. It is also usual to expose theBUILD_SHARED_LIBS
as an user-facing setting with theoption()
command.This way, the following will both work as expected:
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 usingpkg-config
) will find the static libraries.