From d0dd134bdb4763678e405b05d2ba8169cc0a0518 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 26 Mar 2024 08:30:48 -0400 Subject: [PATCH] FindPkgConfig: Avoid finding Strawberry Perl's pkg-config Strawberry Perl may be in the `PATH` to provide `perl`, but it also comes with a `pkg-config` tool that is unrelated to normal MinGW distributions. Since commit c6efbd78d8 (MSVC: Teach find_library to consider the 'libfoo.a' naming convention, 2024-01-19, v3.29.0-rc1~91^2) we need to avoid searching Strawberry Perl's `.../c/lib` directory, so do not let its `pkg-config` point us there. Fixes: #25820 Issue: #23975 --- Modules/FindPkgConfig.cmake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 1b6a72ae88..f3bacc336c 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -56,14 +56,29 @@ endif() set(PKG_CONFIG_NAMES "pkg-config") if(CMAKE_HOST_WIN32) list(PREPEND PKG_CONFIG_NAMES "pkg-config.bat") + set(_PKG_CONFIG_VALIDATOR VALIDATOR __FindPkgConfig_EXECUTABLE_VALIDATOR) + function(__FindPkgConfig_EXECUTABLE_VALIDATOR result_var candidate) + if(candidate MATCHES "\\.[Ee][Xx][Ee]$") + return() + endif() + # Exclude the pkg-config distributed with Strawberry Perl. + execute_process(COMMAND "${candidate}" --help OUTPUT_VARIABLE _output ERROR_VARIABLE _output RESULT_VARIABLE _result) + if(NOT _result EQUAL 0 OR _output MATCHES "Pure-Perl") + set("${result_var}" FALSE PARENT_SCOPE) + endif() + endfunction() +else() + set(_PKG_CONFIG_VALIDATOR "") endif() list(APPEND PKG_CONFIG_NAMES "pkgconf") find_program(PKG_CONFIG_EXECUTABLE NAMES ${PKG_CONFIG_NAMES} NAMES_PER_DIR - DOC "pkg-config executable") + DOC "pkg-config executable" + ${_PKG_CONFIG_VALIDATOR}) mark_as_advanced(PKG_CONFIG_EXECUTABLE) +unset(_PKG_CONFIG_VALIDATOR) set(PKG_CONFIG_ARGN "${PKG_CONFIG_ARGN}" CACHE STRING "Arguments to supply to pkg-config") mark_as_advanced(PKG_CONFIG_ARGN)