Skip to content

Commit b4af1ac

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

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

CMakeLists.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
set_source_files_properties(${f_asm} PROPERTIES COMPILE_FLAGS -safeseh)
60+
target_sources(${libname} PRIVATE ${f_asm})
61+
endforeach()
62+
63+
target_sources(${libname} PRIVATE
64+
# generated from *.in
65+
"fficonfig.h"
66+
"include/ffi.h"
67+
68+
# common source files
69+
"src/closures.c"
70+
"src/prep_cif.c"
71+
"src/raw_api.c"
72+
"src/types.c"
73+
"src/x86/ffitarget.h"
74+
)
75+
target_compile_definitions(${libname} PRIVATE "FFI_BUILDING")
76+
target_include_directories(${libname} PRIVATE ${include_dirs})
77+
78+
if (BUILD_SHARED_LIBS)
79+
# export all funtions for DLL
80+
set_target_properties(${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
81+
endif()
82+
83+
# install the lib
84+
install(TARGETS ${libname}
85+
LIBRARY DESTINATION lib
86+
ARCHIVE DESTINATION lib
87+
RUNTIME DESTINATION bin
88+
)
89+
90+
# install the headers
91+
install(
92+
FILES include/ffi.h src/x86/ffitarget.h
93+
DESTINATION include
94+
)

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)