Permalink
da713cb Aug 1, 2012
148 lines (147 sloc) 5.22 KB
# Copyright (C) 2007-2011 LuaDist.
# Created by Peter Drahos
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Please note that the package source code is licensed under its own license.
project ( libffi C )
cmake_minimum_required ( VERSION 2.8 )
include ( cmake/dist.cmake )
# NOTE: For now this only supports x86 systems, mainly OSX, Linux and Windows (32/64bit)
set ( TARGET X86 )
# Check headers
include ( CheckIncludeFiles )
check_include_files ( alloca.h HAVE_ALLOCA_H )
check_include_files ( dlfcn.h HAVE_DLFCN_H )
check_include_files ( inttypes.h HAVE_INTTYPES_H )
check_include_files ( memory.h HAVE_MEMORY_H )
check_include_files ( stdint.h HAVE_STDINT_H )
check_include_files ( stdlib.h HAVE_STDLIB_H )
check_include_files ( strings.h HAVE_STRINGS_H )
check_include_files ( string.h HAVE_STRING_H )
check_include_files ( sys/mman.h HAVE_SYS_MMAN_H )
check_include_files ( sys/stat.h HAVE_SYS_STAT_H )
check_include_files ( sys/types.h HAVE_SYS_TYPES_H )
check_include_files ( unistd.h HAVE_UNISTD_H )
set ( STDC_HEADERS 1 )
# Check functions
include ( CheckFunctionExists )
check_function_exists ( memcpy HAVE_MEMCPY )
check_function_exists ( mmap HAVE_MMAP )
if ( HAVE_MMAP )
set ( HAVE_MMAP_ANON 1 )
set ( HAVE_MMAP_FILE 1 )
endif ( )
check_function_exists ( alloca HAVE_ALLOCA )
# Check types
include ( CheckTypeSize )
check_type_size ( "long double" HAVE_LONG_DOUBLE )
check_type_size ( "double" SIZEOF_DOUBLE )
check_type_size ( "long double" SIZEOF_LONG_DOUBLE )
check_type_size ( "void*" SIZEOF_VOID_P )
# ASM related settings
set ( HAVE_AS_REGISTER_PSEUDO_OP 0 )
set ( HAVE_AS_CFI_PSEUDO_OP 0 )
set ( HAVE_AS_X86_PCREL 0 )
set ( HAVE_AS_ASCII_PSEUDO_OP 1 )
set ( HAVE_AS_STRING_PSEUDO_OP 1 )
# GCC related settings
set ( HAVE_RO_EH_FRAME 1 )
set ( EH_FRAME_FLAGS aw )
set ( HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 0 )
# FFI Options
option ( FFI_CLOSURES "Enable closures" on )
option ( FFI_DEBUG "Compile with debug" off )
option ( FFI_NO_STRUCTS "Define this is you do not want support for aggregate types."
off )
option ( FFI_NO_RAW_API "Define this is you do not want support for the raw API."
off )
option ( USING_PURIFY "Define this if you are using Purify and want to suppress spurious messages."
off )
include_directories ( ${PROJECT_BINARY_DIR} include src src/x86 )
file ( GLOB SRC_C src/*.c )
# Basic architecture detection
if ( SIZEOF_VOID_P MATCHES 8 )
set ( HAVE_64BIT 1 )
set ( HAVE_AS_X86_64_UNWIND_SECTION_TYPE 1 )
else ( )
set ( HAVE_64BIT 0 )
endif ( )
if ( WIN32 )
# MSVC specific
set ( FFI_CLOSURES 1 )
set ( SYMBOL_UNDERSCORE 1 )
set ( SRC_C ${SRC_C} src/x86/ffi.c )
if ( MSVC )
set ( SRC_ASM ${SRC_ASM} src/x86/sysv.S )
endif ( )
if ( HAVE_64BIT )
# This will probably not work on MinGW
set ( TARGET X86_WIN64 )
set ( SRC_ASM ${SRC_ASM} src/x86/win64.S )
else ( )
set ( TARGET X86_WIN32 )
set ( SRC_ASM ${SRC_ASM} src/x86/win32.S )
endif ( )
elseif ( CYGWIN )
set ( FFI_CLOSURES 1 )
set ( SYMBOL_UNDERSCORE 1 )
set ( SRC_C ${SRC_C} src/x86/ffi.c )
if ( HAVE_64BIT )
# This will probably not work yet
set ( TARGET X86_WIN64 )
set ( SRC_ASM ${SRC_ASM} src/x86/win64.S )
else ( )
set ( TARGET X86_WIN32 )
set ( SRC_ASM ${SRC_ASM} src/x86/win32.S )
endif ( )
elseif ( APPLE )
set ( TARGET X86_DARWIN )
set ( FFI_CLOSURES 1 )
set ( FFI_EXEC_TRAMPOLINE_TABLE 1 )
set ( FFI_MMAP_EXEC_WRIT 1 )
set ( SRC_C ${SRC_C} src/x86/ffi.c )
set ( SRC_ASM ${SRC_ASM} src/x86/darwin.S )
set ( SRC_C ${SRC_C} src/x86/ffi64.c )
set ( SRC_ASM ${SRC_ASM} src/x86/darwin64.S )
else ( )
# Other x86 systems
set ( HAVE_AS_X86_PCREL 1 )
set ( SRC_C ${SRC_C} src/x86/ffi.c )
set ( SRC_ASM ${SRC_ASM} src/x86/sysv.S )
if ( HAVE_64BIT )
set ( TARGET X86_64 )
set ( SRC_C ${SRC_C} src/x86/ffi64.c )
set ( SRC_ASM ${SRC_ASM} src/x86/unix64.S )
else ( )
set ( TARGET X86 )
endif ( )
endif ( )
# Generate headers
configure_file ( "${PROJECT_SOURCE_DIR}/include/ffi.h.in" "${PROJECT_BINARY_DIR}/ffi.h" )
configure_file ( "${PROJECT_SOURCE_DIR}/fficonfig.cmake.in" "${PROJECT_BINARY_DIR}/fficonfig.h" )
# Use C to compile the assembly (this way preprocessor is used)
set_source_files_properties ( ${SRC_ASM} PROPERTIES LANGUAGE C )
# Compile libffi
add_library ( ffi ${SRC_C} ${SRC_ASM} )
# Install
install_library ( ffi )
install_doc ( doc/ )
install_header ( ${PROJECT_BINARY_DIR}/ffi.h ${PROJECT_BINARY_DIR}/fficonfig.h src/x86/ffitarget.h )
install_data ( LICENSE README )
# Testing
enable_testing ( )
file ( GLOB TEST_CLS testsuite/libffi.call/cls*.c )
file ( GLOB TEST_RETURN testsuite/libffi.call/return*.c )
file ( GLOB TEST_STRUCT testsuite/libffi.call/struct*.c )
file ( GLOB TEST_CLOSURE testsuite/libffi.call/closure_fn*.c )
file ( GLOB TEST_FLOAT testsuite/libffi.call/float*.c )
file ( GLOB TEST_NESTED testsuite/libffi.call/nested*.c )
file ( GLOB TEST_STRET testsuite/libffi.call/stret*.c )
set ( TESTS ${TEST_CLS} ${TEST_RETURN} ${TEST_STRUCT} ${TEST_CLOSURE} ${TEST_FLOAT}
${TEST_NESTED} ${TEST_STRET} )
foreach ( TEST ${TESTS} )
get_filename_component ( TEST_NAME ${TEST} NAME )
add_executable ( ${TEST_NAME} ${TEST} )
target_link_libraries ( ${TEST_NAME} ffi )
add_test ( ${TEST_NAME} ${TEST_NAME} )
endforeach ( )