Skip to content

Commit 42595d3

Browse files
authored
[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`.
1 parent 2cb32e2 commit 42595d3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/cmake/modules/FindFFI.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
# Additionally, the following import target will be defined:
2424
# FFI::ffi
2525

26-
find_path(FFI_INCLUDE_DIRS ffi.h PATHS ${FFI_INCLUDE_DIR})
26+
find_package(PkgConfig QUIET)
27+
pkg_check_modules(PC_LIBFFI QUIET libffi)
28+
29+
find_path(FFI_INCLUDE_DIRS ffi.h PATHS ${FFI_INCLUDE_DIR} ${PC_LIBFFI_INCLUDE_DIRS})
2730
if( EXISTS "${FFI_INCLUDE_DIRS}/ffi.h" )
2831
set(FFI_HEADER ffi.h CACHE INTERNAL "")
2932
set(HAVE_FFI_H 1 CACHE INTERNAL "")
@@ -35,8 +38,8 @@ else()
3538
endif()
3639
endif()
3740

38-
find_library(FFI_LIBRARIES NAMES ffi PATHS ${FFI_LIBRARY_DIR})
39-
find_library(FFI_STATIC_LIBRARIES NAMES libffi.a PATHS ${FFI_LIBRARY_DIR})
41+
find_library(FFI_LIBRARIES NAMES ffi PATHS ${FFI_LIBRARY_DIR} ${PC_LIBFFI_LIBRARY_DIRS})
42+
find_library(FFI_STATIC_LIBRARIES NAMES libffi.a PATHS ${FFI_LIBRARY_DIR} ${PC_LIBFFI_LIBRARY_DIRS})
4043

4144
if(FFI_LIBRARIES)
4245
include(CMakePushCheckState)

0 commit comments

Comments
 (0)