Skip to content

Commit 1a8ffa0

Browse files
Dan Deesjcfr
authored andcommitted
On Linux, uses external libffi for python >= 3.7
Since python/cpython@f40d4ddff (Closes python/cpython#27979: Remove bundled copy of libffi), external version of libffi is required on linux.
1 parent 511d7a9 commit 1a8ffa0

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

cmake/extensions/CMakeLists.txt

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -330,47 +330,60 @@ else()
330330
DEFINITIONS MACOSX
331331
)
332332
else()
333-
set(_libffi_sources)
334-
set(_libffi_include_dirs)
335333
if(PY_VERSION VERSION_LESS "3.7")
336-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
337-
set(_libffi_system_extra_src
338-
_ctypes/libffi/src/${_libffi_system_dir}/ffi64.c
339-
_ctypes/libffi/src/${_libffi_system_dir}/unix64.S
334+
set(_libffi_sources)
335+
set(_libffi_include_dirs)
336+
if(PY_VERSION VERSION_LESS "3.7")
337+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
338+
set(_libffi_system_extra_src
339+
_ctypes/libffi/src/${_libffi_system_dir}/ffi64.c
340+
_ctypes/libffi/src/${_libffi_system_dir}/unix64.S
341+
)
342+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
343+
set(_libffi_system_extra_src
344+
_ctypes/libffi/src/${_libffi_system_dir}/win32.S
345+
)
346+
endif()
347+
# To facilitate an eventual contribution of the configuration
348+
# of fficonfig.h to the upstream project, corresponding tests
349+
# in ConfigureChecks.cmake are labeled using this convention:
350+
# * "libffi specific"
351+
# * "libffi and cpython"
352+
set(LIBFFI_VERSION "3.1")
353+
configure_file(
354+
${PROJECT_SOURCE_DIR}/cmake/fficonfig.h.in
355+
${INCLUDE_BUILD_DIR}/fficonfig.h
340356
)
341-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
342-
set(_libffi_system_extra_src
343-
_ctypes/libffi/src/${_libffi_system_dir}/win32.S
357+
set(_libffi_sources
358+
_ctypes/libffi/src/closures.c
359+
_ctypes/libffi/src/prep_cif.c
360+
_ctypes/libffi/src/${_libffi_system_dir}/ffi.c
361+
_ctypes/libffi/src/${_libffi_system_dir}/sysv.S
362+
${_libffi_system_extra_src}
363+
)
364+
set(_libffi_include_dirs
365+
INCLUDEDIRS ${SRC_DIR}/Modules/_ctypes/libffi/src/${_libffi_system_dir}
366+
${SRC_DIR}/Modules/_ctypes/libffi/include
367+
${INCLUDE_BUILD_DIR} # For fficonfig.h
368+
${PROJECT_SOURCE_DIR}/cmake # For ffi.h
344369
)
345370
endif()
346-
# To facilitate an eventual contribution of the configuration
347-
# of fficonfig.h to the upstream project, corresponding tests
348-
# in ConfigureChecks.cmake are labeled using this convention:
349-
# * "libffi specific"
350-
# * "libffi and cpython"
351-
set(LIBFFI_VERSION "3.1")
352-
configure_file(
353-
${PROJECT_SOURCE_DIR}/cmake/fficonfig.h.in
354-
${INCLUDE_BUILD_DIR}/fficonfig.h
355-
)
356-
set(_libffi_sources
357-
_ctypes/libffi/src/closures.c
358-
_ctypes/libffi/src/prep_cif.c
359-
_ctypes/libffi/src/${_libffi_system_dir}/ffi.c
360-
_ctypes/libffi/src/${_libffi_system_dir}/sysv.S
361-
${_libffi_system_extra_src}
362-
)
363-
set(_libffi_include_dirs
364-
INCLUDEDIRS ${SRC_DIR}/Modules/_ctypes/libffi/src/${_libffi_system_dir}
365-
${SRC_DIR}/Modules/_ctypes/libffi/include
366-
${INCLUDE_BUILD_DIR} # For fficonfig.h
367-
${PROJECT_SOURCE_DIR}/cmake # For ffi.h
368-
)
371+
add_python_extension(_ctypes
372+
SOURCES ${ctypes_COMMON_SOURCES} ${_libffi_sources}
373+
${_libffi_include_dirs}
374+
)
375+
376+
else()
377+
# get libffi
378+
find_path(FFI_INCLUDE_DIR ffi.h)
379+
find_library(FFI_LIBRARY NAMES ffi libffi)
380+
add_python_extension(_ctypes
381+
REQUIRES FFI_INCLUDE_DIR FFI_LIBRARY
382+
SOURCES ${ctypes_COMMON_SOURCES}
383+
INCLUDEDIRS ${FFI_INCLUDE_DIR}
384+
LIBRARIES ${FFI_LIBRARY}
385+
)
369386
endif()
370-
add_python_extension(_ctypes
371-
SOURCES ${ctypes_COMMON_SOURCES} ${_libffi_sources}
372-
${_libffi_include_dirs}
373-
)
374387
endif()
375388
endif()
376389

0 commit comments

Comments
 (0)