@@ -15,29 +15,32 @@ option(ZYDIS_FEATURE_DECODER
15
15
option (ZYDIS_FEATURE_FORMATTER
16
16
"Enable instruction formatting functionality"
17
17
ON )
18
- option (ZYDIS_FEATURE_EVEX
19
- "Enable support for EVEX instructions"
18
+ option (ZYDIS_FEATURE_EVEX
19
+ "Enable support for EVEX instructions"
20
20
ON )
21
- option (ZYDIS_FEATURE_MVEX
22
- "Enable support for MVEX instructions"
21
+ option (ZYDIS_FEATURE_MVEX
22
+ "Enable support for MVEX instructions"
23
23
ON )
24
24
25
25
# Build configuration
26
26
option (BUILD_SHARED_LIBS
27
27
"Build shared libraries"
28
28
OFF )
29
+ option (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION
30
+ "Enable whole program optimization"
31
+ OFF )
29
32
option (ZYDIS_NO_LIBC
30
33
"Don't use any C standard library functions (for exotic build-envs like kernel drivers)"
31
34
OFF )
32
- option (ZYDIS_BUILD_EXAMPLES
33
- "Build examples"
35
+ option (ZYDIS_BUILD_EXAMPLES
36
+ "Build examples"
34
37
ON )
35
- option (ZYDIS_BUILD_TOOLS
36
- "Build tools"
38
+ option (ZYDIS_BUILD_TOOLS
39
+ "Build tools"
37
40
ON )
38
41
option (ZYDIS_FUZZ_AFL_FAST
39
- "Enables AFL persistent mode and reduces prints in ZydisFuzzIn"
40
- OFF )
42
+ "Enables AFL persistent mode and reduces prints in ZydisFuzzIn"
43
+ OFF )
41
44
option (ZYDIS_DEV_MODE
42
45
"Enable developer mode (-Wall, -Werror, ...)"
43
46
OFF )
@@ -66,10 +69,15 @@ endif ()
66
69
67
70
add_library ("Zydis" )
68
71
69
- target_include_directories ("Zydis"
72
+ target_include_directories ("Zydis"
70
73
PUBLIC "include" ${PROJECT_BINARY_DIR}
71
74
PRIVATE "src" )
72
75
target_compile_definitions ("Zydis" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYDIS_EXPORTS" )
76
+ if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC )
77
+ set_target_properties ("Zydis" PROPERTIES COMPILE_FLAGS "/GL" )
78
+ set_target_properties ("Zydis" PROPERTIES LINK_FLAGS_RELEASE "/LTCG" )
79
+ set_target_properties ("Zydis" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG" )
80
+ endif ()
73
81
generate_export_header("Zydis" BASE_NAME "ZYDIS" EXPORT_FILE_NAME "ZydisExportConfig.h" )
74
82
75
83
if (NOT ZYDIS_FEATURE_ENCODER AND NOT ZYDIS_FEATURE_DECODER)
@@ -80,6 +88,13 @@ if (NOT ZYDIS_FEATURE_ENCODER AND NOT ZYDIS_FEATURE_DECODER)
80
88
)
81
89
endif ()
82
90
91
+ if (ZYDIS_FEATURE_FORMATTER AND NOT ZYDIS_FEATURE_DECODER)
92
+ message (
93
+ FATAL_ERROR
94
+ "\n ZYDIS_FEATURE_FORMATTER requires ZYDIS_FEATURE_DECODER to be enabled"
95
+ )
96
+ endif ()
97
+
83
98
if (NOT ZYDIS_FEATURE_DECODER)
84
99
target_compile_definitions ("Zydis" PUBLIC "ZYDIS_DISABLE_DECODER" )
85
100
endif ()
@@ -97,7 +112,7 @@ if (ZYDIS_NO_LIBC)
97
112
endif ()
98
113
99
114
target_sources ("Zydis"
100
- PUBLIC
115
+ PRIVATE
101
116
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/CommonTypes.h"
102
117
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Defines.h"
103
118
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/MetaInfo.h"
@@ -110,7 +125,6 @@ target_sources("Zydis"
110
125
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Zydis.h"
111
126
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Internal/LibC.h"
112
127
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Internal/SharedData.h"
113
- PRIVATE
114
128
"src/MetaInfo.c"
115
129
"src/Mnemonic.c"
116
130
"src/Register.c"
@@ -120,16 +134,19 @@ target_sources("Zydis"
120
134
"src/Zydis.c" )
121
135
122
136
if (ZYDIS_FEATURE_DECODER)
123
- target_sources ("Zydis"
124
- PUBLIC
137
+ target_sources ("Zydis"
138
+ PRIVATE
125
139
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Decoder.h"
126
140
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/DecoderTypes.h"
127
- "${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Formatter.h"
128
141
"${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Internal/DecoderData.h"
129
- PRIVATE
130
142
"src/Decoder.c"
131
- "src/DecoderData.c"
132
- "src/Formatter.c" )
143
+ "src/DecoderData.c" )
144
+ if (ZYDIS_FEATURE_FORMATTER)
145
+ target_sources ("Zydis"
146
+ PRIVATE
147
+ "${CMAKE_CURRENT_LIST_DIR} /include/Zydis/Formatter.h"
148
+ "src/Formatter.c" )
149
+ endif ()
133
150
endif ()
134
151
135
152
if (BUILD_SHARED_LIBS AND WIN32 )
@@ -141,14 +158,17 @@ install(TARGETS "Zydis"
141
158
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
142
159
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
143
160
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
144
- install (DIRECTORY "include" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
161
+ install (FILES
162
+ "${PROJECT_BINARY_DIR} /ZydisExportConfig.h"
163
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} " )
164
+ install (DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
145
165
146
166
# =============================================================================================== #
147
167
# Examples #
148
168
# =============================================================================================== #
149
169
150
170
if (ZYDIS_BUILD_EXAMPLES)
151
- if (ZYDIS_FEATURE_DECODER)
171
+ if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER )
152
172
add_executable ("FormatterHooks" "examples/FormatterHooks.c" )
153
173
target_link_libraries ("FormatterHooks" "Zydis" )
154
174
set_target_properties ("FormatterHooks" PROPERTIES FOLDER "Examples/Formatter" )
@@ -158,14 +178,22 @@ if (ZYDIS_BUILD_EXAMPLES)
158
178
target_link_libraries ("ZydisFuzzIn" "Zydis" )
159
179
set_target_properties ("FormatterHooks" PROPERTIES FOLDER "Examples" )
160
180
target_compile_definitions ("ZydisFuzzIn" PRIVATE "_CRT_SECURE_NO_WARNINGS" )
161
- if (ZYDIS_FUZZ_AFL_FAST)
162
- target_compile_definitions ("ZydisFuzzIn" PRIVATE "ZYDIS_FUZZ_AFL_FAST" )
163
- endif ()
181
+ if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC )
182
+ set_target_properties ("ZydisFuzzIn" PROPERTIES COMPILE_FLAGS "/GL" )
183
+ set_target_properties ("ZydisFuzzIn" PROPERTIES LINK_FLAGS_RELEASE "/LTCG" )
184
+ endif ()
185
+ if (ZYDIS_FUZZ_AFL_FAST)
186
+ target_compile_definitions ("ZydisFuzzIn" PRIVATE "ZYDIS_FUZZ_AFL_FAST" )
187
+ endif ()
164
188
165
189
add_executable ("ZydisPerfTest" "examples/ZydisPerfTest.c" )
166
190
target_link_libraries ("ZydisPerfTest" "Zydis" )
167
191
set_target_properties ("FormatterHooks" PROPERTIES FOLDER "Examples" )
168
192
target_compile_definitions ("ZydisPerfTest" PRIVATE "_CRT_SECURE_NO_WARNINGS" )
193
+ if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC )
194
+ set_target_properties ("ZydisPerfTest" PROPERTIES COMPILE_FLAGS "/GL" )
195
+ set_target_properties ("ZydisPerfTest" PROPERTIES LINK_FLAGS_RELEASE "/LTCG" )
196
+ endif ()
169
197
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
170
198
target_compile_definitions ("ZydisPerfTest" PRIVATE "_GNU_SOURCE" )
171
199
find_package (Threads REQUIRED)
@@ -179,15 +207,23 @@ endif ()
179
207
# =============================================================================================== #
180
208
181
209
if (ZYDIS_BUILD_TOOLS)
182
- if (ZYDIS_FEATURE_DECODER)
210
+ if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER )
183
211
add_executable ("ZydisDisasm" "tools/ZydisDisasm.c" )
184
212
target_link_libraries ("ZydisDisasm" "Zydis" )
185
213
set_target_properties ("ZydisDisasm" PROPERTIES FOLDER "Tools" )
186
214
target_compile_definitions ("ZydisDisasm" PRIVATE "_CRT_SECURE_NO_WARNINGS" )
215
+ if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC )
216
+ set_target_properties ("ZydisDisasm" PROPERTIES COMPILE_FLAGS "/GL" )
217
+ set_target_properties ("ZydisDisasm" PROPERTIES LINK_FLAGS_RELEASE "/LTCG" )
218
+ endif ()
187
219
188
220
add_executable ("ZydisInfo" "tools/ZydisInfo.c" )
189
221
target_link_libraries ("ZydisInfo" "Zydis" )
190
222
set_target_properties ("ZydisInfo" PROPERTIES FOLDER "Tools" )
191
223
target_compile_definitions ("ZydisInfo" PRIVATE "_CRT_SECURE_NO_WARNINGS" )
224
+ if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC )
225
+ set_target_properties ("ZydisInfo" PROPERTIES COMPILE_FLAGS "/GL" )
226
+ set_target_properties ("ZydisInfo" PROPERTIES LINK_FLAGS_RELEASE "/LTCG" )
227
+ endif ()
192
228
endif ()
193
229
endif ()
0 commit comments