Skip to content

cmake: fix three issues generating lib options in config files - #21654

Closed
vszakats wants to merge 3 commits into
curl:masterfrom
vszakats:cm-dash-pthread
Closed

vszakats wants to merge 3 commits into
curl:masterfrom
vszakats:cm-dash-pthread

Conversation

@vszakats

@vszakats vszakats commented May 17, 2026 •

Copy link
Copy Markdown
Member

vszakats added 3 commits May 17, 2026 14:12
Logic copied from libssh2.

For example:
 ```
 -Libs.private: -lssh2 -lz -lz -lldap -llber -lssl -lcrypto -lcrypto -lz -lbrotlidec -lbrotlicommon -lzstd -lnghttp2 -licucore -liconv -lpsl -lbacktrace
 +Libs.private: -lssh2 -lz -lldap -llber -lssl -lcrypto -lz -lbrotlidec -lbrotlicommon -lzstd -lnghttp2 -licucore -liconv -lpsl -lbacktrace
 ```
@vszakats vszakats added the cmake label May 17, 2026
@github-actions github-actions Bot added the build label May 17, 2026
@vszakats
vszakats marked this pull request as draft May 17, 2026 13:25
@vszakats
vszakats marked this pull request as ready for review May 17, 2026 13:35
@vszakats vszakats changed the title [WIP] cmake: fix config file generation issues cmake: fix three config file generation issues May 17, 2026
@vszakats vszakats changed the title cmake: fix three config file generation issues cmake: fix three issues generating lib options in config files May 17, 2026
vszakats added a commit to libssh2/libssh2 that referenced this pull request May 17, 2026
- cmake: fix potential non-lib option prefixed with `-l`, resulting in
  e.g. `-l-pthread`.
  Ref: curl/curl#21654

- omit zlib pkg-config reference for Android.
  Android does not offer a `zlib.pc` pkg-config file.
  Refs:
  curl/curl@7bde6cb
  curl/curl#21648

Closes #1946
@vszakats vszakats closed this in 3c597ce May 17, 2026
@vszakats
vszakats deleted the cm-dash-pthread branch May 17, 2026 20:48
outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
- drop duplicate libs lists next to each other in `libcurl.pc`.
  Logic copied from libssh2.
  Fixing (seen in a local build):
  ```diff
  -Libs.private: -lssh2 -lz -lz -lldap -llber -lssl -lcrypto -lcrypto -lz -lbrotlidec -lbrotlicommon -lzstd -lnghttp2 -licucore -liconv -lpsl -lbacktrace
  +Libs.private: -lssh2 -lz -lldap -llber -lssl -lcrypto -lz -lbrotlidec -lbrotlicommon -lzstd -lnghttp2 -licucore -liconv -lpsl -lbacktrace
  ```
  Refs:
  libssh2/libssh2@e1da7b2
  libssh2/libssh2#1621
  libssh2/libssh2@6464301
  libssh2/libssh2#1131

- handle `$<LINK_ONLY:NAMESPACE::NAME>` references.
  Fixing (seen in a local build using libssh2 v1.11.2-DEV):
  ```diff
  -Libs.private: -lssh2 -l$<LINK_ONLY:OpenSSL::Crypto> -lz -lldap -llber [...]
  +Libs.private: -lssh2 -lcrypto -lz -lldap -llber [...]
  ```

- fix `-l-pthread` sneaking into `libcurl.pc`.
  Fixing (seen with Android):
  ```diff
  -Libs.private:  -lz -l-pthread
  +Libs.private: -pthread -lz
  ```
  Refs:
  https://github.com/microsoft/vcpkg/blob/2b65c20fc66eda893aa15a15a453c3cf09500b19/ports/curl/dependencies.patch#L631-L634
  microsoft/vcpkg@70b941a#diff-7f2c3b2f93cd3478671a603cbd5ef818c7c403a11dc25e1d3539e9b03495a5d3
  Upstream-patch-by: Kai Pastor

Closes curl#21654
Comment thread CMake/Macros.cmake
Comment on lines +270 to +273
# E.g. via libssh2: "$<LINK_ONLY:OpenSSL::Crypto>"
if(_lib MATCHES "LINK_ONLY:")
string(REGEX MATCH "([A-Za-z0-9_-]+::[A-Za-z0-9_-]+)" _lib "${_lib}") # Extract imported target name
endif()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code in vcpkg:

Suggested change
# E.g. via libssh2: "$<LINK_ONLY:OpenSSL::Crypto>"
if(_lib MATCHES "LINK_ONLY:")
string(REGEX MATCH "([A-Za-z0-9_-]+::[A-Za-z0-9_-]+)" _lib "${_lib}") # Extract imported target name
endif()
# E.g. via libssh2: "$<LINK_ONLY:OpenSSL::Crypto>"
string(REGEX REPLACE "^[\$]<LINK_ONLY:(.*)>\$" "\\1" _lib "${_lib}")
  • REPLACE!!!
  • One regex match instead of two.
  • Hardcoding specific generator expressions, not specific target name patterns.

Noticed while refreshing patches for vcpkg.

@vszakats vszakats Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dg0yt one nit out of curiousity, is there a reason for the square brackets around the first $ matcher? Would this work perhaps?:

    string(REGEX REPLACE "^\$<LINK_ONLY:(.*)>\$" "\\1" _lib "${_lib}")

edit: tested, got it, it's to defeat string escaping, \\\\$ also works.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not to defeat string escaping.
The square brackets are a visual clue at regex language level to distinguish $ the character from $ the end-of-line pattern.
(The backslashes in my expression are for the special meaning of $ at cmake language level.)

vszakats added a commit that referenced this pull request Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants