[llvm] [llvm] [cmake] Use pkg-config to obtain libffi search hints (PR #144221)

Michał Górny via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 14 06:07:14 PDT 2025


https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/144221

Extend `FindFFI.cmake` to include the paths obtained from pkg-config when searching for libffi.  This is going to help systems where libffi is installed in nonstandard directory such as Gentoo, saving us from having to copy the paths from pkg-config to `FFI_*` variables explicitly.  The logic is inspired by `FindLibEdit.cmake`.

>From 814ac2e3735e52c1162ac495c24158e0ac256520 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sat, 14 Jun 2025 15:03:09 +0200
Subject: [PATCH] [llvm] [cmake] Use pkg-config to obtain libffi search hints

Extend `FindFFI.cmake` to include the paths obtained from pkg-config
when searching for libffi.  This is going to help systems where libffi
is installed in nonstandard directory such as Gentoo, saving us from
having to copy the paths from pkg-config to `FFI_*` variables
explicitly.  The logic is inspired by `FindLibEdit.cmake`.
---
 llvm/cmake/modules/FindFFI.cmake | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/cmake/modules/FindFFI.cmake b/llvm/cmake/modules/FindFFI.cmake
index 8e67c5d8c6d17..b1f64522b2682 100644
--- a/llvm/cmake/modules/FindFFI.cmake
+++ b/llvm/cmake/modules/FindFFI.cmake
@@ -23,7 +23,10 @@
 # Additionally, the following import target will be defined:
 # FFI::ffi
 
-find_path(FFI_INCLUDE_DIRS ffi.h PATHS ${FFI_INCLUDE_DIR})
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_LIBFFI QUIET libffi)
+
+find_path(FFI_INCLUDE_DIRS ffi.h PATHS ${FFI_INCLUDE_DIR} ${PC_LIBFFI_INCLUDE_DIRS})
 if( EXISTS "${FFI_INCLUDE_DIRS}/ffi.h" )
   set(FFI_HEADER ffi.h CACHE INTERNAL "")
   set(HAVE_FFI_H 1 CACHE INTERNAL "")
@@ -35,8 +38,8 @@ else()
   endif()
 endif()
 
-find_library(FFI_LIBRARIES NAMES ffi PATHS ${FFI_LIBRARY_DIR})
-find_library(FFI_STATIC_LIBRARIES NAMES libffi.a PATHS ${FFI_LIBRARY_DIR})
+find_library(FFI_LIBRARIES NAMES ffi PATHS ${FFI_LIBRARY_DIR} ${PC_LIBFFI_LIBRARY_DIRS})
+find_library(FFI_STATIC_LIBRARIES NAMES libffi.a PATHS ${FFI_LIBRARY_DIR} ${PC_LIBFFI_LIBRARY_DIRS})
 
 if(FFI_LIBRARIES)
   include(CMakePushCheckState)



More information about the llvm-commits mailing list