Browse Source

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
Brad King 1 year ago
parent
commit
d0dd134bdb
1 changed files with 16 additions and 1 deletions
  1. 16 1
      Modules/FindPkgConfig.cmake

+ 16 - 1
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)