forked from KindDragon/vld
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
164 lines (146 loc) · 4.71 KB
/
CMakeLists.txt
File metadata and controls
164 lines (146 loc) · 4.71 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
# VLD - Visual Leak Detector DLL
cmake_minimum_required(VERSION 3.16)
# Source files
set(VLD_SOURCES
callstack.cpp
dllspatches.cpp
ntapi.cpp
stdafx.cpp
utility.cpp
vld.cpp
vldapi.cpp
vldheap.cpp
vld_hooks.cpp
)
set(VLD_HEADERS
callstack.h
criticalsection.h
crtmfcpatch.h
dbghelp.hpp
loaderlock.h
map.h
ntapi.h
resource.h
set.h
stdafx.h
tree.h
utility.h
vld.h
vld_def.h
vldallocator.h
vldheap.h
vldint.h
)
# Resource file
set(VLD_RESOURCES vld.rc)
# Create DLL
add_library(vld SHARED
${VLD_SOURCES}
${VLD_HEADERS}
${VLD_RESOURCES}
)
# Platform-specific output name
if(VLD_PLATFORM STREQUAL "ARM64")
set_target_properties(vld PROPERTIES OUTPUT_NAME "vld_arm64")
set(VLD_MANIFEST vld.dll.dependency.arm64.manifest)
elseif(VLD_PLATFORM STREQUAL "x64")
set_target_properties(vld PROPERTIES OUTPUT_NAME "vld_x64")
set(VLD_MANIFEST vld.dll.dependency.x64.manifest)
else()
set_target_properties(vld PROPERTIES OUTPUT_NAME "vld_x86")
set(VLD_MANIFEST vld.dll.dependency.x86.manifest)
endif()
# Include directories - dbghelp must come first to use our version
target_include_directories(vld PRIVATE
${CMAKE_SOURCE_DIR}/lib/dbghelp/include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/lib/cppformat/include
${CMAKE_SOURCE_DIR}/lib
${CMAKE_SOURCE_DIR}/setup
)
# Link libraries
target_link_libraries(vld PRIVATE fmt)
# DbgHelp library path
if(VLD_PLATFORM STREQUAL "ARM64")
# ARM64: Use Windows SDK dbghelp instead of custom library
message(STATUS "ARM64 build: Using Windows SDK dbghelp")
target_link_libraries(vld PRIVATE dbghelp)
elseif(VLD_PLATFORM STREQUAL "x64")
target_link_directories(vld PRIVATE ${CMAKE_SOURCE_DIR}/lib/dbghelp/lib/x64)
target_link_libraries(vld PRIVATE dbghelp)
else()
target_link_directories(vld PRIVATE ${CMAKE_SOURCE_DIR}/lib/dbghelp/lib/Win32)
target_link_libraries(vld PRIVATE dbghelp)
endif()
# Compile definitions
target_compile_definitions(vld PRIVATE
VLD_EXPORTS
_USRDLL
UNICODE
_UNICODE
${VLD_PLATFORM_DEFINE}
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
)
# MSVC specific settings
if(MSVC)
# VLD core uses static runtime (different from tests which use DLL runtime)
set_property(TARGET vld PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# Precompiled header
target_precompile_headers(vld PRIVATE stdafx.h)
# Compiler options - disable inlining in Release/RelWithDebInfo to avoid issues with
# __forceinline functions that have their body in .cpp files (bug in source)
target_compile_options(vld PRIVATE
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/Ob0> # Disable inlining
)
# Disable C4244 warning for x86 builds (fmt library triggers this with 64-bit to 32-bit conversions)
if(VLD_PLATFORM STREQUAL "Win32")
target_compile_options(vld PRIVATE /wd4244)
endif()
# Linker settings
if(VLD_PLATFORM STREQUAL "ARM64" OR VLD_PLATFORM STREQUAL "x64")
# ARM64 and x64 require base address >= 4GB for ASLR optimization
target_link_options(vld PRIVATE
/SUBSYSTEM:WINDOWS
/BASE:0x100000000
)
else()
# x86 (32-bit) uses lower base address
target_link_options(vld PRIVATE
/SUBSYSTEM:WINDOWS
/BASE:0x03200000
)
endif()
# Additional Windows libraries
target_link_libraries(vld PRIVATE
kernel32
user32
advapi32
onecore
)
endif()
# Copy import library and ini file after build
add_custom_command(TARGET vld POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Copying vld import library"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_LINKER_FILE:vld>"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/"
COMMAND ${CMAKE_COMMAND} -E echo "Copying vld.ini"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/vld.ini"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/vld.ini"
)
# Copy dbghelp.dll based on platform
if(VLD_PLATFORM STREQUAL "ARM64")
set(DBGHELP_ARCH "arm64")
elseif(VLD_PLATFORM STREQUAL "x64")
set(DBGHELP_ARCH "x64")
else()
set(DBGHELP_ARCH "x86")
endif()
add_custom_command(TARGET vld POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Copying dbghelp.dll (${DBGHELP_ARCH})"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/setup/dbghelp/${DBGHELP_ARCH}/dbghelp.dll"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/dbghelp.dll"
)