-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
164 lines (145 loc) · 5.07 KB
/
Copy pathCMakeLists.txt
File metadata and controls
164 lines (145 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
cmake_minimum_required(VERSION 3.15)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(pyvex LANGUAGES C)
# Set the output directory for built libraries
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pyvex/lib)
# Set the C standard to C99
set(CMAKE_C_STANDARD 99)
# Include directories
include_directories(
${CMAKE_SOURCE_DIR}/pyvex/include
${CMAKE_SOURCE_DIR}/pyvex_c
${CMAKE_SOURCE_DIR}/vex/pub
)
# Source files for the pyvex C library
set(PYVEX_SRC
pyvex_c/pyvex.c
pyvex_c/analysis.c
pyvex_c/logging.c
pyvex_c/postprocess.c
)
# Source files for the VEX C library
set(VEX_SRC
vex/priv/ir_defs.c
vex/priv/ir_match.c
vex/priv/ir_opt.c
vex/priv/ir_inject.c
vex/priv/main_globals.c
vex/priv/main_util.c
vex/priv/s390_disasm.c
vex/priv/host_x86_defs.c
vex/priv/host_amd64_defs.c
vex/priv/host_arm_defs.c
vex/priv/host_arm64_defs.c
vex/priv/host_ppc_defs.c
vex/priv/host_riscv64_defs.c
vex/priv/host_s390_defs.c
vex/priv/host_mips_defs.c
vex/priv/host_x86_isel.c
vex/priv/host_amd64_isel.c
vex/priv/host_arm_isel.c
vex/priv/host_arm64_isel.c
vex/priv/host_ppc_isel.c
vex/priv/host_riscv64_isel.c
vex/priv/host_s390_isel.c
vex/priv/host_mips_isel.c
vex/priv/host_generic_maddf.c
vex/priv/host_generic_regs.c
vex/priv/host_generic_simd64.c
vex/priv/host_generic_simd128.c
vex/priv/host_generic_simd256.c
vex/priv/host_generic_reg_alloc2.c
vex/priv/host_generic_reg_alloc3.c
vex/priv/guest_generic_x87.c
vex/priv/guest_generic_bb_to_IR.c
vex/priv/guest_x86_helpers.c
vex/priv/guest_amd64_helpers.c
vex/priv/guest_arm_helpers.c
vex/priv/guest_arm64_helpers.c
vex/priv/guest_ppc_helpers.c
vex/priv/guest_riscv64_helpers.c
vex/priv/guest_s390_helpers.c
vex/priv/guest_mips_helpers.c
vex/priv/guest_x86_toIR.c
vex/priv/guest_amd64_toIR.c
vex/priv/guest_arm_toIR.c
vex/priv/guest_arm64_toIR.c
vex/priv/guest_ppc_toIR.c
vex/priv/guest_riscv64_toIR.c
vex/priv/guest_s390_toIR.c
vex/priv/guest_mips_toIR.c
vex/priv/multiarch_main_main.c
)
# Build the VEX static library
add_library(vex STATIC ${VEX_SRC})
target_compile_definitions(vex PRIVATE PYVEX)
target_include_directories(vex PUBLIC ${CMAKE_SOURCE_DIR}/vex/pub)
# Build the shared library
add_library(pyvex SHARED ${PYVEX_SRC})
set_target_properties(pyvex PROPERTIES OUTPUT_NAME "pyvex")
# Handle .def file for Windows builds
if (WIN32)
set_target_properties(pyvex PROPERTIES LINK_FLAGS "/DEF:${CMAKE_SOURCE_DIR}/pyvex_c/pyvex.def")
endif()
target_include_directories(pyvex PRIVATE pyvex_c)
target_link_libraries(pyvex PRIVATE vex)
# Install the built library to the Python package
# It is installed twice to handle both editable and non-editable installs
install(TARGETS pyvex DESTINATION ${CMAKE_SOURCE_DIR}/pyvex/lib)
install(TARGETS pyvex DESTINATION pyvex/lib)
# --- BEGIN: Generate pub/libvex_guest_offsets.h ---
add_executable(genoffsets vex/auxprogs/genoffsets.c)
set_target_properties(genoffsets PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/vex/auxprogs)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/vex/pub/libvex_guest_offsets.h
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:genoffsets> > ${CMAKE_SOURCE_DIR}/vex/pub/libvex_guest_offsets.h
DEPENDS genoffsets
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating pub/libvex_guest_offsets.h"
)
add_custom_target(generate_offsets_header
DEPENDS ${CMAKE_SOURCE_DIR}/vex/pub/libvex_guest_offsets.h
)
install(
FILES ${CMAKE_SOURCE_DIR}/vex/pub/libvex_guest_offsets.h
DESTINATION pyvex/include
)
add_dependencies(vex generate_offsets_header)
# --- END: Generate pub/libvex_guest_offsets.h ---
# --- BEGIN: Generate pyvex/vex_ffi.py ---
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/pyvex/vex_ffi.py
COMMAND ${CMAKE_COMMAND} -E env
${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/make_ffi.py ${CMAKE_SOURCE_DIR}/vex/pub
DEPENDS ${CMAKE_SOURCE_DIR}/vex/pub/libvex_guest_offsets.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating pyvex/vex_ffi.py using make_ffi.py"
)
add_custom_target(generate_vex_ffi_py
DEPENDS ${CMAKE_SOURCE_DIR}/pyvex/vex_ffi.py
)
install(
FILES ${CMAKE_SOURCE_DIR}/pyvex/vex_ffi.py
DESTINATION pyvex
)
add_dependencies(pyvex generate_vex_ffi_py)
# --- END: Generate pyvex/vex_ffi.py ---
# --- BEGIN: Copy headers to pyvex/include ---
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/pyvex/include/pub
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/vex/pub ${CMAKE_SOURCE_DIR}/pyvex/include/
DEPENDS ${CMAKE_SOURCE_DIR}/vex/pub
COMMENT "Copying vex/pub to pyvex/include/"
)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/pyvex/include/pyvex.h
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/pyvex_c/pyvex.h ${CMAKE_SOURCE_DIR}/pyvex/include/pyvex.h
DEPENDS ${CMAKE_SOURCE_DIR}/pyvex_c/pyvex.h
COMMENT "Copying pyvex_c/pyvex.h to pyvex/include/"
)
add_custom_target(copy_headers ALL
DEPENDS ${CMAKE_SOURCE_DIR}/pyvex/include/pub ${CMAKE_SOURCE_DIR}/pyvex/include/pyvex.h
)
add_dependencies(pyvex copy_headers)
add_dependencies(copy_headers generate_offsets_header)
# --- END: Copy headers to pyvex/include ---