Skip to content

cmake: detect more dependencies from curl-config.cmake - #14930

Closed
vszakats wants to merge 11 commits into
curl:masterfrom
vszakats:cm-config-finds
Closed

vszakats wants to merge 11 commits into
curl:masterfrom
vszakats:cm-config-finds

Conversation

@vszakats

@vszakats vszakats commented Sep 16, 2024 •

Copy link
Copy Markdown
Member

Detect more dependencies that provide a CMake config script.

Also:

  • delete CURL_USE_PKGCONFIG logic, that unnecessary and will not be
    used, because using curl-specific Find modules make no sense here.
  • add missing macros passed to curl-config.cmake to comment.

@vszakats vszakats added the cmake label Sep 16, 2024
@github-actions github-actions Bot added the build label Sep 16, 2024
@vszakats
vszakats marked this pull request as draft September 16, 2024 12:12
@dfandrich

This comment was marked as resolved.

@vszakats
vszakats force-pushed the cm-config-finds branch 2 times, most recently from 9fad9a2 to c8d6f9f Compare September 19, 2024 14:44
@vszakats vszakats changed the title cmake: find more dependencies from config.cmake cmake: detect more dependencies from config.cmake Sep 20, 2024
@vszakats vszakats changed the title cmake: detect more dependencies from config.cmake cmake: detect more dependencies from curl-config.cmake Sep 22, 2024
@vszakats
vszakats marked this pull request as ready for review September 22, 2024 17:22
@vszakats vszakats added the feature-window A merge of this requires an open feature window label Sep 22, 2024
@vszakats
vszakats marked this pull request as draft October 23, 2024 15:19
@talregev

talregev commented Jan 16, 2025 •

Copy link
Copy Markdown
Contributor

This PR is plan to merge in the next release window?

@vszakats

vszakats commented Jan 16, 2025 •

Copy link
Copy Markdown
Member Author

Ideally yes. The blocker is to have some CI tests for this. And for that, the blocker is a breakage in the ExternalProject_Add build method: libssh2/libssh2#1510 https://github.com/libssh2/libssh2/blob/master/tests/cmake/CMakeLists.txt

The breakage came in CI after bumping a version in the above PR, but the conditions are fuzzy and couldn't fix it.

Edit: + as the PR message says, it'd be nice to give some testing to the newly added Find modules first.

@talregev

Copy link
Copy Markdown
Contributor

Ideally yes. The blocker is to have some CI tests for this. And for that, the blocker is a breakage in the ExternalProject_Add build method: libssh2/libssh2#1510 https://github.com/libssh2/libssh2/blob/master/tests/cmake/CMakeLists.txt

The breakage came in CI after bumping a version in the above PR, but the conditions are fuzzy and couldn't fix it.

Edit: + as the PR message says, it'd be nice to give some testing to the newly added Find modules first.

I think you can do manual usage test without ExternalProject_Add.
Just compile it with cmake --instal then create another cmake with the test that consume curl. it can be with test.cpp with just hello world main, then if it compile and run, then it mean it consume correctly the libs.

@vszakats

Copy link
Copy Markdown
Member Author

Ideally yes. The blocker is to have some CI tests for this. And for that, the blocker is a breakage in the ExternalProject_Add build method: libssh2/libssh2#1510 https://github.com/libssh2/libssh2/blob/master/tests/cmake/CMakeLists.txt
The breakage came in CI after bumping a version in the above PR, but the conditions are fuzzy and couldn't fix it.
Edit: + as the PR message says, it'd be nice to give some testing to the newly added Find modules first.

I think you can do manual usage test without ExternalProject_Add. Just compile it with cmake --instal then create another cmake with the test that consume curl. it can be with test.cpp with just hello world main, then if it compile and run, then it mean it consume correctly the libs.

I use those scripts for manual local tests. There are 3 usage tests, and
certainly the other two are also useful to test this, but it's annoying that
that one broke and I can't bring over all 3 of them to curl.

Locally it fails regardless of CMake version (It might have worked
before because of the preceding two other tests, hard to say):

-- TEST_INTEGRATION_MODE: ExternalProject
CMake Error at CMakeLists.txt:23 (find_package):
  Could not find a package configuration file provided by "libssh2" with any
  of the following names:

    libssh2Config.cmake
    libssh2-config.cmake

  Add the installation prefix of "libssh2" to CMAKE_PREFIX_PATH or set
  "libssh2_DIR" to a directory containing one of the above files.  If
  "libssh2" provides a separate development package or SDK, be sure it has
  been installed.

-- Configuring incomplete, errors occurred!

I'd expect it to build the project, but it doesn't.

In CI, it started failing after a minor patch to the cmake_minimum_required() lines:
libssh2/libssh2#1510
OK: https://github.com/libssh2/libssh2/actions/runs/12657757762/job/35273209831
Fail: https://github.com/libssh2/libssh2/actions/runs/12820256530/job/35749512251#step:3:1882
(same runner, same CMake version)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0eee9467..8a5eeb29 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,7 +36,7 @@
 #
 # SPDX-License-Identifier: BSD-3-Clause
 
-cmake_minimum_required(VERSION 3.7)
+cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
 message(STATUS "Using CMake version ${CMAKE_VERSION}")
 
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
diff --git a/tests/cmake/CMakeLists.txt b/tests/cmake/CMakeLists.txt
index 97317595..ce3a7470 100644
--- a/tests/cmake/CMakeLists.txt
+++ b/tests/cmake/CMakeLists.txt
@@ -1,7 +1,7 @@
 # Copyright (C) Viktor Szakats
 # SPDX-License-Identifier: BSD-3-Clause
 
-cmake_minimum_required(VERSION 3.7)
+cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
 message(STATUS "Using CMake version ${CMAKE_VERSION}")
 
 project(test-dependent C)

@talregev

talregev commented Jan 22, 2025 •

Copy link
Copy Markdown
Contributor

@vszakats I understand now the complexity of this PR.
When package is detected by pkg-conf, it should add to cmake curl-config.cmake.in:

  find_dependency(PkgConfig)
  pkg_check_modules(<lib name>)

instead of:

find_dependency(<lib name>)

For each package that have 2 option of detection: one with find_package and the other is with pkg-conf, it needed to add the correct to curl-config.cmake.in according to what it been detected. (even when it can detect by both).

@vszakats

Copy link
Copy Markdown
Member Author

@vszakats I understand now the complexity of this PR. When package is detected by pkg-conf, it should add to cmake curl-config.cmake.in:

  find_dependency(PkgConfig)
  pkg_check_modules(<lib name>)

instead of:

find_dependency(<lib name>)

For each package that have 2 option of detection: one with find_package and the other is with pkg-conf, it needed to add the correct to curl-config.cmake.in according to what it been detected. (even when it can detect by both).

find_dependency() is documented CMake as a preferred variant of find_package() to be used in CMake config scripts.
Wouldn't find_package() supposed to use curl's own, distributed Find modules to find the dependencies? Those Find modules already implement the logic you mention. Is it really necessary to repeat that manually in the config module? It would imply a lot of duplicated logic.

@talregev

Copy link
Copy Markdown
Contributor

find_dependency() is documented CMake as a preferred variant of find_package() to be used in CMake config scripts.
Wouldn't find_package() supposed to use curl's own, distributed Find modules to find the dependencies? Those Find modules already implement the logic you mention. Is it really necessary to repeat that manually in the config module? It would imply a lot of duplicated logic.

I understand what you say. That find_dependency() will call curl custom find_package for each curl package, then inside it will be detected by find_package or by pkg-conf.

Did you tested that find_dependency() call curl custom find_package?

@vszakats

Copy link
Copy Markdown
Member Author

find_dependency() is documented CMake as a preferred variant of find_package() to be used in CMake config scripts.
Wouldn't find_package() supposed to use curl's own, distributed Find modules to find the dependencies? Those Find modules already implement the logic you mention. Is it really necessary to repeat that manually in the config module? It would imply a lot of duplicated logic.

I understand what you say. That find_dependency() will call curl custom find_package for each curl package, then inside it will be detected by find_package or by pkg-conf.

Did you tested that find_dependency() call curl custom find_package?

No, I have not, yet.

Just assuming that's the point of having and distributing Find modules. This was done last year in libssh2, but I haven't tested it myself:

libssh2/libssh2@82b09f9
libssh2/libssh2@d9c2e55

Comment thread CMake/curl-config.cmake.in Outdated
find_dependency(NGTCP2)
endif()
if("@USE_GNUTLS@")
if(CURL_USE_PKGCONFIG)

@talregev talregev Jan 22, 2025 •

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.

This is should be like:

"@CURL_USE_PKGCONFIG@"

@vszakats vszakats Jan 22, 2025 •

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.

This is should be like: "@CURL_USE_PKGCONFIG@"?

Isn't this case the same as similar uses within our Find* modules?

Those allow CURL_USE_PKGCONFIG be set by the user of the curl
package to select if they want pkg-config to kick in to find dependencies.
We initialize it at the beginning of the config script.

GnuTLS looks like the same case as the others. Difference is, GnuTLS
does have a CMake built-in Find module, without pkg-config support,
which we tackled on ourselves, then call the built-in module.

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.

You need to remember that this file is load after the curl is compiled, before the generated export cmake is loaded. there is no symbol CURL_USE_PKGCONFIG. that why you need to add as I suggested. also you did it for all other curl variables in this files for the same reason.

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.

I just see that you define it in the beginning of this files. I think we should delete this from here, and have the defintion in one place (in the main cmake, as it already there), and remember that the user decide when it compile it, then set this option permanent for that compilation.

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.

The generated curl-config.cmake does initialize CURL_USE_PKGCONFIG, at the top of the script:

# Keep condition in sync with CMake/curl-config.cmake.in
if((UNIX AND NOT ANDROID AND (NOT APPLE OR CMAKE_SYSTEM_NAME MATCHES "Darwin")) OR
VCPKG_TOOLCHAIN OR
(MINGW AND NOT CMAKE_CROSSCOMPILING))
set(_curl_use_pkgconfig_default ON)
else()
set(_curl_use_pkgconfig_default OFF)
endif()
option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies" ${_curl_use_pkgconfig_default})

It uses the same init logic as curl's build script, but this one is evaluated when building the dependent project. Is there something missing?

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.

Typical Find module trouble:
WolfSSL has CMake config and pkgconfig both export -lm on Linux. Curl uses a find module. This the result:

FAILED: main-pkgconfig 
: && /usr/lib/ccache/cc -fPIC -g -pthread CMakeFiles/main-pkgconfig.dir/main.c.o -o main-pkgconfig  /vcpkg/installed/x64-linux/debug/lib/libcurl-d.a  -latomic  -lm  /vcpkg/installed/x64-linux/debug/lib/libgssapi_krb5.a  /vcpkg/installed/x64-linux/debug/lib/libkrb5.a  /vcpkg/installed/x64-linux/debug/lib/libk5crypto.a  /vcpkg/installed/x64-linux/debug/lib/libcom_err.a  /vcpkg/installed/x64-linux/debug/lib/libkrb5support.a  /usr/lib/x86_64-linux-gnu/libresolv.so  /usr/lib/x86_64-linux-gnu/libdl.so  /usr/lib/x86_64-linux-gnu/libpthread.so  /vcpkg/installed/x64-linux/debug/lib/libldap.a  /vcpkg/installed/x64-linux/debug/lib/liblber.a  /vcpkg/installed/x64-linux/debug/lib/libcares.a  /vcpkg/installed/x64-linux/debug/lib/libmbedtls.a  /vcpkg/installed/x64-linux/debug/lib/libmbedx509.a  /vcpkg/installed/x64-linux/debug/lib/libmbedcrypto.a  /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a  /vcpkg/installed/x64-linux/debug/lib/libgnutls.a  /vcpkg/installed/x64-linux/debug/lib/libhogweed.a  /vcpkg/installed/x64-linux/debug/lib/libgmp.a  /vcpkg/installed/x64-linux/debug/lib/libtasn1.a  /vcpkg/installed/x64-linux/debug/lib/libnettle.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlidec.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlicommon.a  /vcpkg/installed/x64-linux/debug/lib/libzstd.a  /vcpkg/installed/x64-linux/debug/lib/libnghttp2.a  /vcpkg/installed/x64-linux/debug/lib/libpsl.a  /vcpkg/installed/x64-linux/debug/lib/libidn2.a  /vcpkg/installed/x64-linux/debug/lib/libunistring.a  /vcpkg/installed/x64-linux/lib/librtmp.a  /vcpkg/installed/x64-linux/debug/lib/libz.a  /vcpkg/installed/x64-linux/debug/lib/libssl.a  /vcpkg/installed/x64-linux/debug/lib/libcrypto.a  /usr/lib/x86_64-linux-gnu/libresolv.so  /usr/lib/x86_64-linux-gnu/libdl.so  /usr/lib/x86_64-linux-gnu/libpthread.so  /vcpkg/installed/x64-linux/debug/lib/libldap.a  /vcpkg/installed/x64-linux/debug/lib/liblber.a  /vcpkg/installed/x64-linux/debug/lib/libcares.a  /vcpkg/installed/x64-linux/debug/lib/libmbedtls.a  /vcpkg/installed/x64-linux/debug/lib/libmbedx509.a  /vcpkg/installed/x64-linux/debug/lib/libmbedcrypto.a  /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a  /vcpkg/installed/x64-linux/debug/lib/libgnutls.a  /vcpkg/installed/x64-linux/debug/lib/libhogweed.a  /vcpkg/installed/x64-linux/debug/lib/libgmp.a  /vcpkg/installed/x64-linux/debug/lib/libtasn1.a  /vcpkg/installed/x64-linux/debug/lib/libnettle.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlidec.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlicommon.a  /vcpkg/installed/x64-linux/debug/lib/libzstd.a  /vcpkg/installed/x64-linux/debug/lib/libnghttp2.a  /vcpkg/installed/x64-linux/debug/lib/libpsl.a  /vcpkg/installed/x64-linux/debug/lib/libidn2.a  /vcpkg/installed/x64-linux/debug/lib/libunistring.a  /vcpkg/installed/x64-linux/lib/librtmp.a  /vcpkg/installed/x64-linux/debug/lib/libz.a  /vcpkg/installed/x64-linux/debug/lib/libssl.a  /vcpkg/installed/x64-linux/debug/lib/libcrypto.a && :
/usr/bin/ld: /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a(dh.c.o): in function `DiscreteLogWorkFactor':
/vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1031: undefined reference to `pow'
/usr/bin/ld: /vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1032: undefined reference to `log'
/usr/bin/ld: /vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1032: undefined reference to `pow'
collect2: error: ld returned 1 exit status

@vszakats vszakats Jan 25, 2025 •

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.

That's another missing piece of this puzzle, thanks for this.

curl never referenced dependencies like this except for OpenSSL and ZLIB. It's also been CMake version dependent, but that seems clear now (for OpenSSL it required CMake 3.4, for ZLIB it was 3.1). curl never declared INTERFACE_LINK_LIBRARIES, which seems something to be fixed. It's also a question how to use the ::-style references with other dependencies. Those also use custom Find modules. So another question is how to reference them like this AND provide support for pkg-config. I'm assuming we must define those targets manually in such case.

For now it seems safe to just convert this PR to a tidy-up one that deletes the CURL_USE_PKGCONFIG logic from curl-config.cmake. The rest needs somebody who knows how to do it.

@vszakats vszakats Jan 25, 2025 •

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.

Opened #16087 for the tidy-up. This PR also has this, plus converted to add the CONFIG modules, though this might be pointless too without using :: and INTERFACE_LINK_LIBRARIES. So unless there is a better suggestion, I plan to close this shortly without merging.

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.

Typical Find module trouble: WolfSSL has CMake config and pkgconfig both export -lm on Linux. Curl uses a find module. This the result:

FAILED: main-pkgconfig 
: && /usr/lib/ccache/cc -fPIC -g -pthread CMakeFiles/main-pkgconfig.dir/main.c.o -o main-pkgconfig  /vcpkg/installed/x64-linux/debug/lib/libcurl-d.a  -latomic  -lm  /vcpkg/installed/x64-linux/debug/lib/libgssapi_krb5.a  /vcpkg/installed/x64-linux/debug/lib/libkrb5.a  /vcpkg/installed/x64-linux/debug/lib/libk5crypto.a  /vcpkg/installed/x64-linux/debug/lib/libcom_err.a  /vcpkg/installed/x64-linux/debug/lib/libkrb5support.a  /usr/lib/x86_64-linux-gnu/libresolv.so  /usr/lib/x86_64-linux-gnu/libdl.so  /usr/lib/x86_64-linux-gnu/libpthread.so  /vcpkg/installed/x64-linux/debug/lib/libldap.a  /vcpkg/installed/x64-linux/debug/lib/liblber.a  /vcpkg/installed/x64-linux/debug/lib/libcares.a  /vcpkg/installed/x64-linux/debug/lib/libmbedtls.a  /vcpkg/installed/x64-linux/debug/lib/libmbedx509.a  /vcpkg/installed/x64-linux/debug/lib/libmbedcrypto.a  /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a  /vcpkg/installed/x64-linux/debug/lib/libgnutls.a  /vcpkg/installed/x64-linux/debug/lib/libhogweed.a  /vcpkg/installed/x64-linux/debug/lib/libgmp.a  /vcpkg/installed/x64-linux/debug/lib/libtasn1.a  /vcpkg/installed/x64-linux/debug/lib/libnettle.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlidec.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlicommon.a  /vcpkg/installed/x64-linux/debug/lib/libzstd.a  /vcpkg/installed/x64-linux/debug/lib/libnghttp2.a  /vcpkg/installed/x64-linux/debug/lib/libpsl.a  /vcpkg/installed/x64-linux/debug/lib/libidn2.a  /vcpkg/installed/x64-linux/debug/lib/libunistring.a  /vcpkg/installed/x64-linux/lib/librtmp.a  /vcpkg/installed/x64-linux/debug/lib/libz.a  /vcpkg/installed/x64-linux/debug/lib/libssl.a  /vcpkg/installed/x64-linux/debug/lib/libcrypto.a  /usr/lib/x86_64-linux-gnu/libresolv.so  /usr/lib/x86_64-linux-gnu/libdl.so  /usr/lib/x86_64-linux-gnu/libpthread.so  /vcpkg/installed/x64-linux/debug/lib/libldap.a  /vcpkg/installed/x64-linux/debug/lib/liblber.a  /vcpkg/installed/x64-linux/debug/lib/libcares.a  /vcpkg/installed/x64-linux/debug/lib/libmbedtls.a  /vcpkg/installed/x64-linux/debug/lib/libmbedx509.a  /vcpkg/installed/x64-linux/debug/lib/libmbedcrypto.a  /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a  /vcpkg/installed/x64-linux/debug/lib/libgnutls.a  /vcpkg/installed/x64-linux/debug/lib/libhogweed.a  /vcpkg/installed/x64-linux/debug/lib/libgmp.a  /vcpkg/installed/x64-linux/debug/lib/libtasn1.a  /vcpkg/installed/x64-linux/debug/lib/libnettle.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlidec.a  /vcpkg/installed/x64-linux/debug/lib/libbrotlicommon.a  /vcpkg/installed/x64-linux/debug/lib/libzstd.a  /vcpkg/installed/x64-linux/debug/lib/libnghttp2.a  /vcpkg/installed/x64-linux/debug/lib/libpsl.a  /vcpkg/installed/x64-linux/debug/lib/libidn2.a  /vcpkg/installed/x64-linux/debug/lib/libunistring.a  /vcpkg/installed/x64-linux/lib/librtmp.a  /vcpkg/installed/x64-linux/debug/lib/libz.a  /vcpkg/installed/x64-linux/debug/lib/libssl.a  /vcpkg/installed/x64-linux/debug/lib/libcrypto.a && :
/usr/bin/ld: /vcpkg/installed/x64-linux/debug/lib/libwolfssl.a(dh.c.o): in function `DiscreteLogWorkFactor':
/vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1031: undefined reference to `pow'
/usr/bin/ld: /vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1032: undefined reference to `log'
/usr/bin/ld: /vcpkg/buildtrees/wolfssl/src/7.6-stable-6ac16c75a4.clean/wolfcrypt/src/dh.c:1032: undefined reference to `pow'
collect2: error: ld returned 1 exit status

I don't understand. Does this have to do anything with this PR? Is this a bug report for FindWolfSSL?

There is this code in FindWolfSSL to find -lm, does it not work?

if(NOT WIN32)
find_library(MATH_LIBRARY NAMES "m")
if(MATH_LIBRARY)
list(APPEND WOLFSSL_LIBRARIES ${MATH_LIBRARY}) # for log and pow
endif()
mark_as_advanced(MATH_LIBRARY)
endif()

@vszakats vszakats Jan 25, 2025 •

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.

After working on this incomrehesinble jumble of nonense for more than a year, I feel I can do no more to satisfy the random and often straight contradictory reports, requests and comments just sprinkled in. I'm passing the opportunity to someone who knows it better.

vszakats added a commit to vszakats/curl that referenced this pull request Jan 25, 2025
This variable was meant to be used by curl Find modules, but it turns
out it makes no sense to use those from `curl-config.cmake.in`. Drop it.

Also add missing macros passed to curl-config.cmake to comment.

Ref: curl#14930 (comment)
@vszakats vszakats closed this Jan 25, 2025
@vszakats
vszakats deleted the cm-config-finds branch January 25, 2025 14:18
vszakats added a commit that referenced this pull request Jan 25, 2025
This variable was meant to be used by curl Find modules, but it turns
out it makes no sense to use those from `curl-config.cmake.in`. It means
this variable was not used before and will not be used in the future,
and therefore safe to delete.

Also add missing macros passed to `curl-config.cmake` to comment.

Ref: #14930 (comment)

Closes #16087
@vszakats

vszakats commented Feb 5, 2025

Copy link
Copy Markdown
Member Author

For reference, I try tackling this in libssh2, on a smaller scale:

@talregev

talregev commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

How it goes? Are you thinking to apply it on curl?

@vszakats

vszakats commented Feb 5, 2025 •

Copy link
Copy Markdown
Member Author

How it goes? Are you thinking to apply it on curl?

It's bumpy. CMake misses features necessary for this in versions
we still do support. So they need to be manually worked around.
It means it saves no lines or much complexity. The namespace pollution
problem is so prevalent that I don't think it can be fixed unless
going full oddball, which would then be breaking and surprising
for everyone. But the PR improves the situation reasonably well.

The direction of using target props instead of global variables is
looking good overall.

It's also very suprising that CMake to this day misses a way to
dump target properties. (let alone variables). It makes me wonder
how people were debugging their scripts in the last 2 decades. So,
I've added a function for this, tweaking works found on the internet,
but it's incomplete, kludgy and broken in cases. It's also many lines,
which I think should be better placed in CMake itself, rather than
copy-pasted between projects and files.

I believe CMake would make great service for everyone by offering
debug functions to show its variables, object properties, ideally with
simple commands dumping these to the terminal.

TL;DR: It's probably possible to build on that and implement some (or
all) of those changes in curl. But curl is bigger, so before doing so,
it'd be nice to clear up as much as possible on a smaller scale.

You can find the details here: libssh2/libssh2#1535

@talregev

talregev commented Feb 5, 2025 •

Copy link
Copy Markdown
Contributor

I wanted also you look at this vcpkg PR and it patches:
microsoft/vcpkg#43629

@talregev

talregev commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

I believe CMake would make great service for everyone by offering
debug functions to show its variables, object properties, ideally with
simple commands dumping these to the terminal.

@dg0yt How you debug on cmake? I remember that you told me that there is an option to do so.

@dg0yt

dg0yt commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

The best tools, and the crudest ones at the same time, are --trace and --trace-expand.
And KISS.

@talregev

talregev commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

@vszakats

vszakats commented Feb 5, 2025 •

Copy link
Copy Markdown
Member Author

microsoft/vcpkg#43463

Nice! some random feedback:

  • the less patching necessary, the better.
  • about *_LINK_LIBRARIES vs. *_LIBRARIES. I specifically focused on the latter based on a crumble of a hint left by @dg0yt saying that we should prefer libnames + paths, versus full libpaths. This patch contradicts this advice, leaving me confused. Though, using full path surely makes things easier because CMake seems centered around the Windows-specific concept that we address libs with full paths. This isn't true on many platforms, and absent as a concept from pkg-config. CMake seems to endorse the latter more and more in recent versions, but this is new and possibly incomplete. It also raises the question of when and who is deciding to pick up the static vs. shared copy of the lib. With libnames, it's the linker, with full paths, it's the build tool, or whoever advertises the libpath.
  • there are some bits that we may probably merge into curl and libssh2. →
    cmake: respect GNUTLS_LIBRARY_DIRS in libcurl.pc and curl-config #16190
    cmake: normalize before matching paths with syspaths #16191
    cmake: normalize before matching paths with syspaths libssh2/libssh2#1538
  • the linked libssh2 PR may make some of these patches simpler, I think.

@talregev

talregev commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

Also this PR:
microsoft/vcpkg#43629

@vszakats

vszakats commented Feb 6, 2025 •

Copy link
Copy Markdown
Member Author

Thanks for the debug tips! Found some new options I'll be testing (see below).

Most of them are overkill for my use cases. CMAKE_DEBUG_TARGET_PROPERTIES
sounds what I need, but reading its docs left me in the dark. Enabling it doesn't seem
to do anything. I just want to see those props / vars at specific places.

The problem is rarely the control flow, but the values stored by CMake. I prefer the
command-line, message() and text files, and seldom feel the need for a debugger
or IDE. Logs are useful, I find them somewhat (subjectively) noisy in CMake and e.g.
did not help at all to figure out the Android / iOS mis-detections. Perhaps variable_watch()
could help, if you know what to watch, and that's often a or the big if.

Tried --warn-uninitialized, which found a few place to tidy up, plus some hits where
Makefile.inc is spilling into CMake. It also reports unset envs, which feels out of place?
-Wdeprecated didn't report issues. --warn-unused-vars and --check-system-vars
seems to be incompatible with how CMake is expected to work, meaning lots of output,
but nothing obviously actionable.

Fix applied:

pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
This variable was meant to be used by curl Find modules, but it turns
out it makes no sense to use those from `curl-config.cmake.in`. It means
this variable was not used before and will not be used in the future,
and therefore safe to delete.

Also add missing macros passed to `curl-config.cmake` to comment.

Ref: curl#14930 (comment)

Closes curl#16087
vszakats added a commit that referenced this pull request Nov 29, 2025
Rework the way curl's custom Find modules advertise their properties.

Before this patch, Find modules returned detected dependency properties
(header dirs, libs, libdirs, C flags, etc.) via global variables. curl's
main `CMakeLists.txt` copied their values into global lists, which it
later applied to targets. This solution worked internally, but it was
unsuited for the public, distributed `CURLConfig.cmake` and publishing
curl's Find modules with it, due to polluting the namespace of consumer
projects. It's also impractical to apply the many individual variables
to every targets depending on libcurl.

To allow using Find modules in consumer projects, this patch makes them
define as imported interface targets, named `CURL::<dependency>`. Then
store dependency information as target properties. It avoids namespace
pollution and makes the dependency information apply automatically
to all targets using `CURL::libcurl_static`.

Find modules continue to return `*_FOUND` and `*_VERSION` variables.

For dependencies detected via `pkg-config`, CMake 3.16+ is recommended.
Older CMake versions have a varying degree of support for
propagating/handling library directories. This may cause issues in envs
where dependencies reside in non-system locations and detected via
`pkg-config` (e.g. macOS + Homebrew). Use `CURL_USE_PKGCONFIG=OFF`
to fix these issues. Or upgrade to newer CMake, or link libcurl
dynamically.

Also:
- re-enable `pkg-config` for old cmake `find_library()` integration
  tests.
- make `curlinfo` build after these changes.
- distribute local Find modules.
- export the raw list of lib dependencies via `CURL_LIBRARIES_PRIVATE`.
- `CURLconfig.cmake`: use curl's Find modules to detect dependencies in
  the consumer env.
- add custom property to target property debug function.
- the curl build process no longer modifies `CMAKE_C_FLAGS`.
  Follow-up to e865420 #17047

Ref: #14930
Ref: libssh2/libssh2#1535
Ref: libssh2/libssh2#1571
Ref: libssh2/libssh2#1581
Ref: libssh2/libssh2#1623

Closes #16973
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.

4 participants