Skip to content

Commit 52e3a79

Browse files
author
Dan Dees
committed
Added CMakeLists.txt and README.cmake
1 parent 0d0ab67 commit 52e3a79

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

CMakeLists.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(libffi C ASM_MASM)
3+
4+
set(libname "libffi")
5+
6+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
7+
8+
if (BUILD_SHARED_LIBS)
9+
add_library(${libname} SHARED)
10+
else()
11+
add_library(${libname})
12+
endif (BUILD_SHARED_LIBS)
13+
14+
list(APPEND include_dirs
15+
"." # fficonfig.h
16+
"include"
17+
"src/x86"
18+
)
19+
20+
# option version of includes
21+
foreach(dd ${include_dirs})
22+
list(APPEND include_opts "-I" "${CMAKE_SOURCE_DIR}/${dd}")
23+
endforeach()
24+
25+
# select sources by platform
26+
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
27+
# Windows 32
28+
list(APPEND asm_basenames "sysv_intel")
29+
target_sources(${libname} PRIVATE
30+
"src/x86/ffi.c"
31+
"src/x86/internal.h"
32+
)
33+
else()
34+
# Windows 64
35+
list(APPEND asm_basenames "win64_intel")
36+
target_sources(${libname} PRIVATE
37+
"src/x86/ffiw64.c"
38+
"src/x86/internal64.h"
39+
)
40+
endif()
41+
42+
# preprocess assembly files
43+
foreach(ff ${asm_basenames})
44+
# compose assembly file names
45+
set(f_S "${CMAKE_SOURCE_DIR}/src/x86/${ff}.S")
46+
set(f_asm "${CMAKE_CURRENT_BINARY_DIR}/${ff}.asm")
47+
48+
# S -> asm
49+
add_custom_command(
50+
OUTPUT ${f_asm}
51+
COMMAND ${CMAKE_C_COMPILER}
52+
ARGS ${CMAKE_CPP_FLAGS} ${include_opts} -EP ${f_S} > ${f_asm}
53+
DEPENDS "${f_S}"
54+
COMMENT "C preprocessor"
55+
)
56+
57+
# add asm to compile list
58+
set_source_files_properties(${f_asm} PROPERTIES GENERATED TRUE)
59+
target_sources(${libname} PRIVATE ${f_asm})
60+
endforeach()
61+
62+
target_sources(${libname} PRIVATE
63+
# generated from *.in
64+
"fficonfig.h"
65+
"include/ffi.h"
66+
67+
# common source files
68+
"src/closures.c"
69+
"src/prep_cif.c"
70+
"src/raw_api.c"
71+
"src/types.c"
72+
"src/x86/ffitarget.h"
73+
)
74+
target_compile_definitions(${libname} PRIVATE "FFI_BUILDING")
75+
target_include_directories(${libname} PRIVATE ${include_dirs})
76+
77+
if (BUILD_SHARED_LIBS)
78+
# export all funtions for DLL
79+
set_target_properties(${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
80+
endif()
81+
82+
# install the lib
83+
install(TARGETS ${libname}
84+
LIBRARY DESTINATION lib
85+
ARCHIVE DESTINATION lib
86+
RUNTIME DESTINATION bin
87+
)
88+
89+
# install the headers
90+
install(
91+
FILES include/ffi.h src/x86/ffitarget.h
92+
DESTINATION include
93+
)

README.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
supports Windows "VS oriented" generators
3+
4+
# Visual Studio 32/64 projects
5+
cmake -G"Visual Studio 16 2019" -A Win32 -DCMAKE_INSTALL_PREFIX=c:/output c:/libffi
6+
7+
# ninja
8+
cmake -GNinja -A Win32 -DCMAKE_INSTALL_PREFIX=c:/output c:/libffi
9+
10+
SHARED_LIB option to generate dll/import library
11+
12+
Unsupported, but not too difficult...
13+
- Msys/Cygwin
14+
- Processing *.in config files

0 commit comments

Comments
 (0)