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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 14 07:11:44 PDT 2025


Author: Michał Górny
Date: 2025-06-14T16:11:41+02:00
New Revision: 42595d34bda74e0d6e3b6ec0cf253875330f9c42

URL: https://github.com/llvm/llvm-project/commit/42595d34bda74e0d6e3b6ec0cf253875330f9c42
DIFF: https://github.com/llvm/llvm-project/commit/42595d34bda74e0d6e3b6ec0cf253875330f9c42.diff

LOG: [llvm] [cmake] Use pkg-config to obtain libffi search hints (#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`.

Added: 
    

Modified: 
    llvm/cmake/modules/FindFFI.cmake

Removed: 
    


################################################################################
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