]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake/FindLibpsl: protect against `pkg-config` "half-detection"
authorViktor Szakats <commit@vsz.me>
Tue, 24 Dec 2024 09:12:31 +0000 (10:12 +0100)
committerViktor Szakats <commit@vsz.me>
Wed, 25 Dec 2024 20:46:55 +0000 (21:46 +0100)
Same issue as seen before with libssh2: `libpsl`'s pkg-config module
depends on another module, but that's not found. CMake ends up reporting
`LIBPSL_FOUND=YES`, while leaving `LIBPSL_INCLUDE_DIRS` empty. Then
the build fails to find `psl.h`.

The missing dependency in this case is `icu4c`, which is "keg-only",
meaning it's not exposed in the default Homebrew header, pkg-config,
lib, etc locations. It must be added to the `PKG_CONFIG_PATH` env, as
suggested by the warnings messages of `pkgconf`.

To avoid this fallout, let's ensure that `LIBPSL_INCLUDE_DIRS` is
non-empty when detecting via `pkg-config` and fall back to the CMake
detection method otherwise.

This was an issue till Homebrew libpsl 0.21.5_1, fixed in 0.21.5_2, that
no longer depends on `icu4c`.

Example log:
```
-- Checking for module 'libpsl'
--   Found libpsl, version 0.21.5
Package icu-uc was not found in the pkg-config search path.
Perhaps you should add the directory containing `icu-uc.pc'
to the PKG_CONFIG_PATH environment variable
Package 'icu-uc', required by 'libpsl', not found
[...]
-- Found Libpsl (via pkg-config):  (found version "0.21.5")
[...]
In file included from curl/_bld/lib/CMakeFiles/libcurl_static.dir/Unity/unity_0_c.c:4:
In file included from curl/lib/altsvc.c:32:
In file included from curl/lib/urldata.h:145:
curl/lib/psl.h:28:10: fatal error: 'libpsl.h' file not found
         ^~~~~~~~~~
1 error generated.
```

Follow-up to 39c741b7b008b5959980b29ac721357ff75de3f5 #15408
Closes #15827

CMake/FindLibpsl.cmake

index 2097d09d50af236391a43849a83cd9d3d87e8910..0802174309d8239cea4a0139fa4066b71d7c3127 100644 (file)
@@ -44,7 +44,7 @@ if(CURL_USE_PKGCONFIG AND
   pkg_check_modules(LIBPSL "libpsl")
 endif()
 
-if(LIBPSL_FOUND)
+if(LIBPSL_FOUND AND LIBPSL_INCLUDE_DIRS)
   string(REPLACE ";" " " LIBPSL_CFLAGS "${LIBPSL_CFLAGS}")
   message(STATUS "Found Libpsl (via pkg-config): ${LIBPSL_INCLUDE_DIRS} (found version \"${LIBPSL_VERSION}\")")
 else()