cmke: add *_USE_STATIC_LIBS options for 9 dependencies#20015
cmke: add *_USE_STATIC_LIBS options for 9 dependencies#20015vszakats wants to merge 17 commits intocurl:masterfrom
*_USE_STATIC_LIBS options for 9 dependencies#20015Conversation
|
I don't think this is our responsibility and (like anything else) it adds to maintenance. Something like below may? work, at least on Windows. I don't think you can or would want static glibc CPPFLAGS="-DNGHTTP2_STATICLIB" LDFLAGS="-static" PKG_CONFIG="pkg-config --static" ./configure ... |
In this case my doubt is if this would actually help people trying edit: after extending it to pkg-config and more deps, the maintenance Hence marked experimental, so if it causes more problems, or [ An aside I find insteresting is that some libs do not require the annoying
How to choose static with the pkg-config integrated to CMake, (enclosing each lib in edit: it's On a quick look, even the oldest CMake version supported now, loads The issue remains that it's ultimately the linker what decides what gets |
There was a problem hiding this comment.
Pull request overview
This PR adds *_USE_STATIC_LIBS options for several CMake Find modules (brotli, c-ares, libssh, libssh2, mbedtls, nghttp2, nghttp3, ngtcp2, zstd) to enable "best effort" detection and configuration of static libraries. The implementation attempts to find static library variants by checking for static-suffixed library names first, and sets appropriate compile-time macros when required by the dependency (similar to existing OPENSSL_USE_STATIC_LIBS and ZLIB_USE_STATIC_LIBS options).
- Adds new
*_USE_STATIC_LIBSCMake input variables for 9 dependencies - Modifies each Find module to prioritize static library variants when the option is set
- Sets required
*_STATICLIBcompile definitions for libraries that need them (c-ares, libssh, nghttp2, nghttp3, ngtcp2) - Updates pkg-config integration to use
STATIC_*variables when static libs are requested
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/INSTALL-CMAKE.md | Documents the new *_USE_STATIC_LIBS options for each affected dependency |
| CMake/FindZstd.cmake | Adds ZSTD_USE_STATIC_LIBS option with static library name variants and pkg-config static variable support |
| CMake/FindNGTCP2.cmake | Adds NGTCP2_USE_STATIC_LIBS option, sets -DNGTCP2_STATICLIB macro, searches for static library variants |
| CMake/FindNGHTTP3.cmake | Adds NGHTTP3_USE_STATIC_LIBS option, sets -DNGHTTP3_STATICLIB macro, searches for static library variants |
| CMake/FindNGHTTP2.cmake | Adds NGHTTP2_USE_STATIC_LIBS option, sets -DNGHTTP2_STATICLIB macro, reorders library search to prioritize static variants |
| CMake/FindMbedTLS.cmake | Adds MBEDTLS_USE_STATIC_LIBS option with static library name variants for all three mbedTLS libraries |
| CMake/FindLibssh2.cmake | Adds LIBSSH2_USE_STATIC_LIBS option with static library name variants |
| CMake/FindLibssh.cmake | Adds LIBSSH_USE_STATIC_LIBS option, sets -DLIBSSH_STATIC macro, searches for static library variants |
| CMake/FindCares.cmake | Adds CARES_USE_STATIC_LIBS option, sets -DCARES_STATICLIB macro, searches for static library variants |
| CMake/FindBrotli.cmake | Adds BROTLI_USE_STATIC_LIBS option with static library name variants for both brotli libraries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ngtcp2 crypto lib name does not honor it yet
- [ ] make pkg-config also somehow detect static lib?
|
I'm still on the fence with this one. The maintenance burden is IMO We've seen requests, reports and PRs to this intended effect, but My impression during the last few decades is that the In other cases, not so much. I can't assess if this scenario is common enough to justify this PR, Feel free to comment what you think. (edit: the PR is ready to merge as-is, in case it's useful.) |
*_USE_STATIC_LIBS option for some dependencies*_USE_STATIC_LIBS option for 9 dependencies
*_USE_STATIC_LIBS option for 9 dependencies*_USE_STATIC_LIBS options for 9 dependencies
|
Merged as experimental. |
Replacing manual `CPPFLAGS` with curl 8.19.0+. They are no-ops for dependencies that do not need a macro to enable static mode. I've added them there anyway for consistency. These settings also affect how the dependency is searched, but in case of these builds, all dependencies are explicitly set with absolute paths, skipping any search. curl/curl@26c39d8 curl/curl#20015
Via options:
BROTLI_USE_STATIC_LIBSCARES_USE_STATIC_LIBSLIBSSH_USE_STATIC_LIBSLIBSSH2_USE_STATIC_LIBSMBEDTLS_USE_STATIC_LIBSNGHTTP2_USE_STATIC_LIBSNGHTTP3_USE_STATIC_LIBSNGTCP2_USE_STATIC_LIBSZSTD_USE_STATIC_LIBSWhen enabled, make a "best effort" finding static libs first and set
the "build static" macro (on Windows) as required by the dependency.
When doing
pkg-config-based detections, make curl select the staticconfiguration, which shall set the "build static" macro also.
These options resemble CMake's
OPENSSL_USE_STATIC_LIBSandZLIB_USE_STATIC_LIBS(the latter does not supportpkg-configas ofCMake v4.2.2).
Shared/static library selection based on loose filename conventions is
fragile and prone to break if the non-static-suffixed library is found
and happens to be a shared library, or, if the linker decides to pick up
a shared copy (e.g.
.a.dll) that shadows the static one. It may helpto provide either static or shared, but not both, on the disk, and match
that with this setting.
Experimental.
Ref: #20013
https://github.com/curl/curl/pull/20015/files?w=1
have static-suffix lib names, but have no (AFAIK) macro to set.
*_USE_STATIC_LIBSoption.This may potentially be breaking, though technically the accurate thing to do. (in c-ares, libssh, wolfSSL, Rustls, librtmp)
[SKIP, let's rather overlink than underlink]
INSTALL-CMAKE.md.Skip for now. Not all dependencies have this. (Those that have no clear
distinct name for static libs (or I couldn't spot it), don't.)
-D*_USE_STATIC_LIBS=_mystatic? (some deps support it out of the box) → Looks like a lot of complication to address niche cases. For customization it's simpler to just point to the exact library name via<name>_LIBRARY. Skip this.<name>_STATIC_<var>variables returned by pkg-configwhen this option is set.
CURL_to stay within thenamespace. (that ship had sailed? maybe fix it in future for all, otherwise
these new vars would confusingly be misaligned with the existing ones.)