[libffi] Fix non-windows

This commit is contained in:
Robert Schumacher 2018-04-17 16:18:25 -07:00
parent 6984ef0c2c
commit 24cf00365b
3 changed files with 93 additions and 195 deletions

View File

@ -1,13 +1,40 @@
cmake_minimum_required(VERSION 3.0)
project(libffi)
cmake_minimum_required(VERSION 3.9)
project(libffi C ASM)
set(CMAKE_SHARED_LIBRARY_PREFIX)
set(CMAKE_STATIC_LIBRARY_PREFIX)
if(NOT CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
# config variables for ffi.h.in
set(VERSION 3.1)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TARGET X86_WIN32)
else()
set(TARGET X86_WIN64)
set(KNOWN_PROCESSORS x86 x86_64 AMD64 ARM ARM64 i386)
if(NOT CMAKE_SYSTEM_PROCESSOR IN_LIST KNOWN_PROCESSORS)
message(FATAL_ERROR "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM")
set(TARGET ARM)
elseif(CMAKE_SYSTEM_NAME MATCHES "BSD" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TARGET X86_FREEBSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TARGET X86_WIN32)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TARGET X86_WIN64)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(TARGET X86_DARWIN)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TARGET X86_64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TARGET X86)
else()
message(FATAL_ERROR "Cannot determine target. Please consult ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac and add your platform to this CMake file.")
endif()
set(HAVE_LONG_DOUBLE 0)
set(HAVE_LONG_DOUBLE_VARIANT 0)
set(FFI_EXEC_TRAMPOLINE_TABLE 0)
@ -24,33 +51,13 @@ include_directories(include)
add_definitions(-DHAVE_CONFIG_H)
add_definitions(-DFFI_BUILDING)
if(BUILD_SHARED_LIBS)
add_definitions(-DFFI_EXPORT_DATA)
if(WIN32)
add_definitions(-DFFI_EXPORT_DATA)
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_ASM_NAME win32)
set(ARCH_ASSEMBLER ml /safeseh)
else()
set(ARCH_ASM_NAME win64)
set(ARCH_ASSEMBLER ml64)
endif()
execute_process(
COMMAND cl /nologo /EP /I. /Iinclude ${CMAKE_SOURCE_DIR}/src/x86/${ARCH_ASM_NAME}.S
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_FILE ${ARCH_ASM_NAME}.asm)
# Produced *.asm file could be just added to sources.
# It works in x64 mode, but for some strange reason MASM returns error code when in x86,
# (even though it didn't report any errors and correctly generated object file)
# which in turn causes MSBUILD to stop.
execute_process(
COMMAND ${ARCH_ASSEMBLER} /c /Zi ${ARCH_ASM_NAME}.asm
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set(FFI_SOURCES
${CMAKE_BINARY_DIR}/${ARCH_ASM_NAME}.obj
src/x86/ffi.c
src/closures.c
src/java_raw_api.c
@ -58,6 +65,57 @@ set(FFI_SOURCES
src/raw_api.c
src/types.c)
macro(add_assembly ASMFILE)
get_filename_component(ASMFILE_FULL "${ASMFILE}" ABSOLUTE)
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_ASSEMBLER ml /safeseh)
else()
set(ARCH_ASSEMBLER ml64)
endif()
get_filename_component(ARCH_ASM_NAME "${ASMFILE_FULL}" NAME_WE)
execute_process(
COMMAND ${CMAKE_C_COMPILER} /nologo /EP /I. /Iinclude ${ASMFILE_FULL}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_FILE ${ARCH_ASM_NAME}.asm
)
# Produced *.asm file could be just added to sources.
# It works in x64 mode, but for some strange reason MASM returns error code when in x86,
# (even though it didn't report any errors and correctly generated object file)
# which in turn causes MSBUILD to stop.
execute_process(
COMMAND ${ARCH_ASSEMBLER} /c /Zi ${ARCH_ASM_NAME}.asm
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
list(APPEND FFI_SOURCES ${CMAKE_BINARY_DIR}/${ARCH_ASM_NAME}.obj)
else()
list(APPEND FFI_SOURCES ${ASMFILE})
endif()
endmacro()
if("${TARGET}" STREQUAL "X86")
add_assembly(src/x86/sysv.S)
add_assembly(src/x86/win32.S)
elseif("${TARGET}" STREQUAL "X86_64")
list(APPEND FFI_SOURCES src/x86/ffi64.c)
add_assembly(src/x86/unix64.S)
add_assembly(src/x86/sysv.S)
elseif("${TARGET}" STREQUAL "X86_WIN32")
add_assembly(src/x86/win32.S)
elseif("${TARGET}" STREQUAL "X86_WIN64")
add_assembly(src/x86/win64.S)
elseif("${TARGET}" STREQUAL "X86_DARWIN")
list(APPEND FFI_SOURCES src/x86/ffi64.c)
add_assembly(src/x86/darwin.S)
add_assembly(src/x86/darwin64.S)
else()
message(FATAL_ERROR "Target not implemented")
endif()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND FFI_SOURCES src/debug.c)
add_definitions(-DFFI_DEBUG)

View File

@ -1,209 +1,46 @@
/* fficonfig.h. Generated from fficonfig.h.in by configure. */
/* fficonfig.h.in. Generated from configure.ac by autoheader. */
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
/* #undef CRAY_STACKSEG_END */
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
/* Define to the flags needed for the .section .eh_frame directive. */
/* #undef EH_FRAME_FLAGS */
/* Define this if you want extra debugging. */
/* #undef FFI_DEBUG */
/* Cannot use PROT_EXEC on this target, so, we revert to alternative means */
/* #undef FFI_EXEC_TRAMPOLINE_TABLE */
/* Define this if you want to enable pax emulated trampolines */
/* #undef FFI_MMAP_EXEC_EMUTRAMP_PAX */
/* Cannot use malloc on this target, so, we revert to alternative means */
/* #undef FFI_MMAP_EXEC_WRIT */
/* Define this if you do not want support for the raw API. */
/* #undef FFI_NO_RAW_API */
/* Define this if you do not want support for aggregate types. */
/* #undef FFI_NO_STRUCTS */
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
/* #undef HAVE_ALLOCA_H */
/* Define if your assembler supports .ascii. */
#ifndef _WIN64
#define HAVE_AS_ASCII_PSEUDO_OP 1
#endif
/* Define if your assembler supports .cfi_* directives. */
/* #undef HAVE_AS_CFI_PSEUDO_OP */
/* Define if your assembler supports .register. */
/* #undef HAVE_AS_REGISTER_PSEUDO_OP */
/* Define if your assembler and linker support unaligned PC relative relocs.
*/
/* #undef HAVE_AS_SPARC_UA_PCREL */
/* Define if your assembler supports .string. */
#ifndef _WIN64
#define HAVE_AS_STRING_PSEUDO_OP 1
#endif
/* Define if your assembler supports unwind section type. */
/* #undef HAVE_AS_X86_64_UNWIND_SECTION_TYPE */
/* Define if your assembler supports PC relative relocs. */
#ifndef _WIN64
#define HAVE_AS_X86_PCREL 1
#endif
/* Define to 1 if you have the <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
/* Define if __attribute__((visibility("hidden"))) is supported. */
/* #undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE */
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define if you have the long double type and it is bigger than a double */
/* #undef HAVE_LONG_DOUBLE */
/* Define if you support more than one size of the long double type */
/* #undef HAVE_LONG_DOUBLE_VARIANT */
/* Define to 1 if you have the `memcpy' function. */
/* #undef HAVE_MEMCPY */
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `mmap' function. */
/* #undef HAVE_MMAP */
/* Define if mmap with MAP_ANON(YMOUS) works. */
/* #undef HAVE_MMAP_ANON */
/* Define if mmap of /dev/zero works. */
/* #undef HAVE_MMAP_DEV_ZERO */
/* Define if read-only mmap of a plain file works. */
/* #undef HAVE_MMAP_FILE */
/* Define if .eh_frame sections should be read-only. */
/* #undef HAVE_RO_EH_FRAME */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
/* #undef HAVE_STRINGS_H */
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/mman.h> header file. */
/* #undef HAVE_SYS_MMAN_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
/* #undef HAVE_UNISTD_H */
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"
/* Name of package */
#define PACKAGE "libffi"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "http://github.com/atgreen/libffi/issues"
/* Define to the full name of this package. */
#define PACKAGE_NAME "libffi"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libffi 3.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libffi"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "3.1"
/* The size of `double', as computed by sizeof. */
#define SIZEOF_DOUBLE 8
/* The size of `long double', as computed by sizeof. */
#define SIZEOF_LONG_DOUBLE 8
/* The size of `size_t', as computed by sizeof. */
#ifndef _WIN64
#define SIZEOF_SIZE_T 4
#else
#define SIZEOF_SIZE_T 8
#endif
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if symbols are underscored. */
#ifndef _WIN64
#define SYMBOL_UNDERSCORE 1
#endif
/* Define this if you are using Purify and want to suppress spurious messages.
*/
/* #undef USING_PURIFY */
/* Version number of package */
#define VERSION "3.1"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
#ifdef LIBFFI_ASM
#define FFI_HIDDEN(name) .hidden name

View File

@ -16,14 +16,16 @@ file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/export-global-data.patch)
${CMAKE_CURRENT_LIST_DIR}/export-global-data.patch
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
-DFFI_CONFIG_FILE=${CMAKE_CURRENT_LIST_DIR}/fficonfig.h
OPTIONS_DEBUG
-DFFI_SKIP_HEADERS=ON)
-DFFI_SKIP_HEADERS=ON
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()
@ -32,7 +34,8 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
vcpkg_apply_patches(
SOURCE_PATH ${CURRENT_PACKAGES_DIR}/include
PATCHES
${CMAKE_CURRENT_LIST_DIR}/auto-define-static-macro.patch)
${CMAKE_CURRENT_LIST_DIR}/auto-define-static-macro.patch
)
endif()
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/libffi)