• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15#
16# Build libffi for Windows x86_64 using MSVC.
17#
18
19project(libffi LANGUAGES C ASM_MASM)
20cmake_minimum_required(VERSION 3.18.1)
21
22set(src ${CMAKE_CURRENT_SOURCE_DIR})
23set(out ${CMAKE_CURRENT_BINARY_DIR})
24
25set(TARGET X86_WIN64)
26set(HAVE_LONG_DOUBLE 0)
27set(FFI_EXEC_TRAMPOLINE_TABLE 0)
28configure_file(include/ffi.h.in ${out}/ffi.h @ONLY)
29
30add_library(libffi SHARED
31  src/prep_cif.c
32  src/types.c
33  src/raw_api.c
34  src/java_raw_api.c
35  src/closures.c
36  src/x86/ffiw64.c
37  ${out}/win64_intel.asm
38)
39
40configure_file(src/x86/ffitarget.h    ${out}/dist/include/ffitarget.h   COPYONLY)
41configure_file(${out}/ffi.h           ${out}/dist/include/ffi.h         COPYONLY)
42
43set(defines
44  -DHAVE_CONFIG_H=1
45  -DFFI_BUILDING_DLL=1
46)
47
48set(include_dirs
49  ${src}/include
50  ${src}/windows-msvc-x86_64
51  ${src}/src/x86
52  ${out}
53)
54
55target_compile_definitions(libffi PRIVATE ${defines})
56target_include_directories(libffi PUBLIC ${include_dirs})
57
58list(TRANSFORM include_dirs PREPEND -I OUTPUT_VARIABLE include_dir_args)
59
60# Preprocess this .S file before assembling it with ml64. It's not clear to me whether CMake is
61# supposed to support this inherently. The msvc_build/aarch64/Ffi_staticLib.vcxproj project also
62# uses a CustomBuild step. This step won't rebuild if an included file changes, which might be
63# fixable (someday), perhaps using the DEPFILE argument to add_custom_command.
64add_custom_command(
65  OUTPUT ${out}/win64_intel.asm
66  COMMAND cl /EP ${src}/src/x86/win64_intel.S ${defines} ${include_dir_args} >${out}/win64_intel.asm
67  DEPENDS src/x86/win64_intel.S ${out}/ffi.h
68)
69