-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
218 lines (192 loc) · 8.04 KB
/
CMakeLists.txt
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(Zyrex VERSION 1.0.0.0 LANGUAGES C CXX)
include(GenerateExportHeader)
include(GNUInstallDirs)
if (NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
# =============================================================================================== #
# Overridable options #
# =============================================================================================== #
# Build configuration
option(ZYREX_BUILD_SHARED_LIB
"Build shared library"
OFF)
option(ZYREX_BUILD_EXAMPLES
"Build examples"
ON)
# Dependencies
option(ZYAN_SYSTEM_ZYCORE
"Use system Zycore library"
OFF)
set(ZYAN_ZYCORE_PATH
"${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore"
CACHE
PATH
"The path to look for Zydis")
option(ZYAN_SYSTEM_ZYDIS
"Use system Zydis library"
OFF)
set(ZYAN_ZYDIS_PATH
"${CMAKE_CURRENT_LIST_DIR}/dependencies/zydis"
CACHE
PATH
"The path to look for Zycore")
# =============================================================================================== #
# Dependencies #
# =============================================================================================== #
if (ZYAN_SYSTEM_ZYCORE)
find_package(Zycore)
else ()
# Try to initialize the Zycore submodule using Git
if (NOT EXISTS "${ZYAN_ZYCORE_PATH}/CMakeLists.txt" AND
"${ZYAN_ZYCORE_PATH}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/dependencies/zycore")
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
endif ()
if (NOT EXISTS "${ZYAN_ZYCORE_PATH}/CMakeLists.txt")
message(
FATAL_ERROR
"Can't find zycore submodule. Please make sure to clone the repo recursively.\n"
"You can fix this by running\n"
" git submodule update --init\n"
"or by cloning using\n"
" git clone --recursive <url>\n"
"Alternatively, you can manually clone zycore to some path and set ZYDIS_ZYCORE_PATH."
)
endif ()
add_subdirectory(${ZYAN_ZYCORE_PATH} "zycore" EXCLUDE_FROM_ALL)
endif ()
if (ZYAN_SYSTEM_ZYDIS)
find_package(Zydis)
else ()
# Try to initialize the Zydis submodule using Git
if (NOT EXISTS "${ZYAN_ZYDIS_PATH}/CMakeLists.txt" AND
"${ZYAN_ZYDIS_PATH}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}/dependencies/zydis")
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
endif ()
if (NOT EXISTS "${ZYAN_ZYDIS_PATH}/CMakeLists.txt")
message(
FATAL_ERROR
"Can't find zydis submodule. Please make sure to clone the repo recursively.\n"
"You can fix this by running\n"
" git submodule update --init\n"
"or by cloning using\n"
" git clone --recursive <url>\n"
"Alternatively, you can manually clone zycore to some path and set ZYDIS_ZYDIS_PATH."
)
endif ()
add_subdirectory(${ZYAN_ZYDIS_PATH} "zydis" EXCLUDE_FROM_ALL)
endif ()
# =============================================================================================== #
# Library configuration #
# =============================================================================================== #
if (ZYREX_BUILD_SHARED_LIB)
add_library("Zyrex" SHARED)
else ()
add_library("Zyrex" STATIC)
endif ()
option(ZYDIS_MINIMAL_MODE "" ON)
option(ZYDIS_FEATURE_FORMATTER "" OFF)
option(ZYDIS_FEATURE_AVX512 "" OFF)
option(ZYDIS_FEATURE_KNC "" OFF)
option(ZYDIS_FEATURE_ENCODER "" OFF)
option(ZYDIS_BUILD_EXAMPLES "" OFF)
option(ZYDIS_BUILD_TOOLS "" OFF)
target_link_libraries("Zyrex" PUBLIC "Zycore")
target_link_libraries("Zyrex" PUBLIC "Zydis")
target_include_directories("Zyrex"
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE "src")
target_compile_definitions("Zyrex" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYREX_EXPORTS")
set_target_properties("Zyrex" PROPERTIES
VERSION ${Zyrex_VERSION}
SOVERSION ${Zyrex_VERSION_MAJOR}.${Zyrex_VERSION_MINOR})
zyan_set_common_flags("Zyrex")
zyan_maybe_enable_wpo_for_lib("Zyrex")
generate_export_header("Zyrex" BASE_NAME "ZYREX" EXPORT_FILE_NAME "ZyrexExportConfig.h")
target_sources("Zyrex"
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Barrier.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Status.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Transaction.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Zyrex.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Internal/InlineHook.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Internal/Relocation.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Internal/Trampoline.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zyrex/Internal/Utils.h"
"src/Barrier.c"
"src/Relocation.c"
"src/InlineHook.c"
"src/Trampoline.c"
"src/Transaction.c"
"src/Utils.c"
"src/Zyrex.c")
if (ZYREX_BUILD_SHARED_LIB AND WIN32)
target_sources("Zyrex" PRIVATE "resources/VersionInfo.rc")
endif ()
zyan_set_source_group("Zyrex")
configure_package_config_file(cmake/zyrex-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/zyrex-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zyrex"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/zyrex-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/zyrex-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zyrex-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zyrex"
)
install(TARGETS "Zyrex"
EXPORT "zyrex-targets"
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(EXPORT "zyrex-targets"
NAMESPACE "Zydis::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zyrex")
install(FILES
"${PROJECT_BINARY_DIR}/ZyrexExportConfig.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# =============================================================================================== #
# Examples #
# =============================================================================================== #
if (ZYREX_BUILD_EXAMPLES)
add_executable("InlineHook" "examples/InlineHook.c")
target_link_libraries("InlineHook" "Zycore")
target_link_libraries("InlineHook" "Zyrex")
set_target_properties("InlineHook" PROPERTIES FOLDER "Examples/InlineHook")
target_compile_definitions("InlineHook" PRIVATE "_CRT_SECURE_NO_WARNINGS")
zyan_set_common_flags("InlineHook")
zyan_maybe_enable_wpo("InlineHook")
add_executable("Barrier" "examples/Barrier.c")
target_link_libraries("Barrier" "Zycore")
target_link_libraries("Barrier" "Zyrex")
set_target_properties("Barrier" PROPERTIES FOLDER "Examples/Barrier")
target_compile_definitions("Barrier" PRIVATE "_CRT_SECURE_NO_WARNINGS")
zyan_set_common_flags("Barrier")
zyan_maybe_enable_wpo("Barrier")
endif ()