forked from microsoft/Detours
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
305 lines (259 loc) · 9.58 KB
/
Copy pathCMakeLists.txt
File metadata and controls
305 lines (259 loc) · 9.58 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# ##############################################################################
#
# CMakeLists.txt for Microsoft Detours Library
#
# Microsoft Research Detours Package, Version 4.0.1
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# ##############################################################################
cmake_minimum_required(VERSION 3.15)
project(Detours
VERSION 4.0.1
DESCRIPTION "Microsoft Detours - Binary instrumentation library for Windows"
LANGUAGES CXX
)
# ##############################################################################
# Options
# ##############################################################################
option(BUILD_SHARED_LIBS "Build shared library (DLL)" ON)
option(DETOURS_BUILD_STATIC_LIB "Also build static library" OFF)
option(DETOURS_INSTALL "Generate installation targets" OFF)
# ##############################################################################
# Configuration
# ##############################################################################
set(DETOURS_VERSION_STRING "4.0.1")
# Determine target architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETOURS_BITS 64)
else()
set(DETOURS_BITS 32)
endif()
# Identify processor architecture
if(MSVC)
if(CMAKE_GENERATOR_PLATFORM MATCHES "ARM64EC")
set(DETOURS_TARGET_PROCESSOR "ARM64EC")
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "ARM64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
set(DETOURS_TARGET_PROCESSOR "ARM64")
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "ARM" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ARM")
set(DETOURS_TARGET_PROCESSOR "ARM")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETOURS_TARGET_PROCESSOR "X64")
else()
set(DETOURS_TARGET_PROCESSOR "X86")
endif()
else()
# For non-MSVC compilers, use system processor
set(DETOURS_TARGET_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
endif()
message(STATUS "Detours: Building for ${DETOURS_TARGET_PROCESSOR} (${DETOURS_BITS}-bit)")
# ##############################################################################
# Source Files
# ##############################################################################
set(DETOURS_SOURCES
src/detours.cpp
src/modules.cpp
src/disasm.cpp
src/image.cpp
src/creatwth.cpp
src/disolx86.cpp
src/disolx64.cpp
src/disolarm.cpp
src/disolarm64.cpp
src/disolia64.cpp
)
set(DETOURS_HEADERS
src/detours.h
src/detver.h
)
# ##############################################################################
# Shared Library (DLL)
# ##############################################################################
add_library(detours SHARED ${DETOURS_SOURCES} ${DETOURS_HEADERS})
target_include_directories(detours
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
# Define compile definitions
target_compile_definitions(detours
PRIVATE
WIN32_LEAN_AND_MEAN
_WIN32_WINNT=0x0501
DETOURS_BITS=${DETOURS_BITS}
)
# Set output names with architecture suffix
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETOURS_OUTPUT_NAME "Detours.X64")
else()
set(DETOURS_OUTPUT_NAME "Detours.X86")
endif()
set_target_properties(detours PROPERTIES
OUTPUT_NAME "${DETOURS_OUTPUT_NAME}"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
PDB_NAME "${DETOURS_OUTPUT_NAME}"
COMPILE_PDB_NAME "${DETOURS_OUTPUT_NAME}"
)
# ##############################################################################
# Compiler-specific Settings
# ##############################################################################
if(MSVC)
# Match original Makefile settings (adapted for DLL)
target_compile_options(detours PRIVATE
/W4 # Warning level 4
/WX # Warnings as errors
/we4777 # Treat specific warnings as errors
/we4800 # Treat specific warnings as errors
/Zi # Debug information
/Gy # Function-level linking
/Gm- # Disable minimal rebuild
)
# Maximum performance optimizations for Release builds
target_compile_options(detours PRIVATE
$<$<CONFIG:Release>:
/O2 # Maximum speed optimization
/Oi # Enable intrinsic functions
/Ot # Favor fast code
/GL # Whole program optimization
/GF # String pooling
/GS- # Disable security checks for performance
>
)
# Link-time code generation for Release
set_target_properties(detours PROPERTIES
LINK_FLAGS_RELEASE "/LTCG /OPT:REF /OPT:ICF"
)
# Use DLL CRT linkage for shared library
set_property(TARGET detours PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
# Link with kernel32 and user32
target_link_libraries(detours PRIVATE kernel32 user32)
else()
# GCC/Clang settings for potential alternative compilers
target_compile_options(detours PRIVATE
-Wall
-Wextra
-Werror
)
endif()
# ##############################################################################
# Static Library (Optional)
# ##############################################################################
if(DETOURS_BUILD_STATIC_LIB)
add_library(detours_static STATIC ${DETOURS_SOURCES} ${DETOURS_HEADERS})
target_include_directories(detours_static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(detours_static
PRIVATE
WIN32_LEAN_AND_MEAN
_WIN32_WINNT=0x0501
DETOURS_BITS=${DETOURS_BITS}
)
set_target_properties(detours_static PROPERTIES
OUTPUT_NAME "detours-static"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
if(MSVC)
target_compile_options(detours_static PRIVATE
/W4
/WX
/we4777
/we4800
/Zi
/Gy
/Gm-
/Zl
)
# Maximum performance optimizations for Release builds
target_compile_options(detours_static PRIVATE
$<$<CONFIG:Release>:
/O2 # Maximum speed optimization
/Oi # Enable intrinsic functions
/Ot # Favor fast code
/GL # Whole program optimization
/GF # String pooling
/GS- # Disable security checks for performance
>
)
# Link-time code generation for Release
set_target_properties(detours_static PROPERTIES
STATIC_LIBRARY_FLAGS_RELEASE "/LTCG"
)
set_property(TARGET detours_static PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_link_libraries(detours_static PRIVATE kernel32 user32)
else()
target_compile_options(detours_static PRIVATE
-Wall
-Wextra
-Werror
)
endif()
endif()
# ##############################################################################
# Installation
# ##############################################################################
include(GNUInstallDirs)
if(DETOURS_INSTALL)
install(TARGETS detours
EXPORT detours-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${DETOURS_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(DETOURS_BUILD_STATIC_LIB)
install(TARGETS detours_static
EXPORT detours-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
# Export targets
install(EXPORT detours-targets
FILE detours-targets.cmake
NAMESPACE Detours::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/detours
)
# Package configuration
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/DetoursConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/DetoursConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/detours
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DetoursConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/DetoursConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DetoursConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/detours
)
endif()
# ##############################################################################
# Summary
# ##############################################################################
message(STATUS "")
message(STATUS "Detours Configuration Summary:")
message(STATUS " Version: ${DETOURS_VERSION_STRING}")
message(STATUS " Target Processor: ${DETOURS_TARGET_PROCESSOR}")
message(STATUS " Bits: ${DETOURS_BITS}")
message(STATUS " Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS " Shared Library: ${BUILD_SHARED_LIBS}")
message(STATUS " Static Library: ${DETOURS_BUILD_STATIC_LIB}")
message(STATUS " Installation: ${DETOURS_INSTALL}")
message(STATUS "")
# ##############################################################################
# End of File
# ##############################################################################