forked from vadimcn/codelldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
313 lines (261 loc) · 11.1 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
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
306
307
308
309
310
311
312
313
cmake_minimum_required(VERSION 3.10)
project(CodeLLDB)
enable_testing()
set(VERSION 1.5.3)
include(cmake/CopyFiles.cmake)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INSTALL_PREFIX $ENV{HOME}/.vscode/extensions/vscode-lldb CACHE PATH "Install location")
set(LLDB_ROOT $ENV{LLDB_ROOT} CACHE PATH "Root of LLDB build directory")
if (LLDB_ROOT)
message("Using LLDB from ${LLDB_ROOT}")
else()
message(FATAL_ERROR "LLDB_ROOT not set." )
endif()
# General OS-specific definitions
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(DylibPrefix lib)
set(DylibSuffix .so)
set(NPM npm)
set(PathSep ":")
set(DefaultTarget x86_64-unknown-linux-gnu)
set(AllowedDependencies linux-vdso.so.1 librt.so.1 libdl.so.2 libpthread.so.0 libgcc_s.so.1
libm.so.6 libc.so.6 /lib64/ld-linux-x86-64.so.2)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(DylibPrefix lib)
set(DylibSuffix .dylib)
set(SymSuffix .dSYM)
set(NPM npm)
set(PathSep ":")
set(DefaultTarget x86_64-apple-darwin)
set(AllowedDependencies Foundation CoreFoundation CoreServices Security
libcompression.dylib libxml2.2.dylib libz.1.dylib libSystem.B.dylib libc...1.dylib
libresolv.9.dylib libpmenergy.dylib libpmsample.dylib libobjc.A.dylib
libcodelldb.dylib liblldb.dylib Python)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(ExeSuffix .exe)
set(DylibSuffix .dll)
set(SymSuffix .pdb)
set(NPM npm.cmd)
set(PathSep "$<SEMICOLON>")
set(DefaultTarget x86_64-pc-windows-msvc)
set(AllowedDependencies api-ms-.* WS2_32.dll KERNEL32.dll ADVAPI32.dll VCRUNTIME140.dll MSVCP140.dll RPCRT4.dll
USER32.dll VERSION.dll DBGHELP.dll PSAPI.DLL OLEAUT32.dll
python3.dll liblldb.dll)
else()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} target is not supported by this build script.")
endif()
string(JOIN "|" AllowedDependencies ${AllowedDependencies}) # Compose a regex
find_package(Python3 COMPONENTS Interpreter Development)
if (NOT LLVM_TRIPLE)
set(LLVM_TRIPLE ${DefaultTarget})
endif()
set(WithEnv ${CMAKE_COMMAND} -E env)
set(UpdateFile ${CMAKE_COMMAND} -E copy_if_different)
# Adapter
add_subdirectory(adapter)
add_subdirectory(lldb)
# Extension package content
set(PLATFORM_PACKAGE_URL "https://github.com/vadimcn/vscode-lldb/releases/download/v\${version}/\${platformPackage}" CACHE STRING "")
configure_file(package.json ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
configure_file(webpack.config.js ${CMAKE_CURRENT_BINARY_DIR}/webpack.config.js @ONLY)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# Run 'npm install'
execute_process(
COMMAND ${NPM} install
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
RESULT_VARIABLE Result
)
if (NOT ${Result} EQUAL 0)
message(FATAL_ERROR "npm intall failed: ${Result}")
endif()
# Copy it back, so we can commit the lock file.
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/package-lock.json DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(update_lockfiles
COMMAND ${UpdateFile} ${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json ${CMAKE_CURRENT_BINARY_DIR}/package-lock.json
COMMAND ${NPM} update
COMMAND ${UpdateFile} ${CMAKE_CURRENT_BINARY_DIR}/package-lock.json ${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json
COMMAND cargo update
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
)
# Extension and tests
if (CMAKE_BUILD_TYPE MATCHES Release|RelWithDebInfo)
set(WebpackMode production)
else()
set(WebpackMode development)
endif()
add_custom_target(extension
COMMAND
COMMAND ${NPM} run webpack -- --display=minimal --mode=${WebpackMode} --output=${CMAKE_CURRENT_BINARY_DIR}/extension.js
${CMAKE_CURRENT_SOURCE_DIR}/extension/main.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
)
add_custom_target(tests
COMMAND ${NPM} run webpack -- --display=minimal --mode=${WebpackMode} --output=${CMAKE_CURRENT_BINARY_DIR}/tests.js
${CMAKE_CURRENT_SOURCE_DIR}/tests/adapter.test.ts
${CMAKE_CURRENT_SOURCE_DIR}/tests/util.test.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
)
# Extension package resources
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_BINARY_DIR}/README.md)
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md ${CMAKE_CURRENT_BINARY_DIR}/CHANGELOG.md)
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/images/lldb.png ${CMAKE_CURRENT_BINARY_DIR}/images/lldb.png)
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/images/user.svg ${CMAKE_CURRENT_BINARY_DIR}/images/user.svg)
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/images/users.svg ${CMAKE_CURRENT_BINARY_DIR}/images/users.svg)
add_copy_file(PackageFiles ${CMAKE_CURRENT_SOURCE_DIR}/syntaxes/disassembly.json ${CMAKE_CURRENT_BINARY_DIR}/syntaxes/disassembly.json)
# For extension debugging
add_custom_target(dev_debugging
DEPENDS codelldb debuggee extension ${PackageFiles}
)
# VSIX packages
set(PackagedFilesBootstrap
README.md
CHANGELOG.md
extension.js
formatters/*
images/*
syntaxes/*
)
set(PackagedFilesFull
${PackagedFilesBootstrap}
platform.ok
adapter/*.py
adapter/codelldb
adapter/libcodelldb.so
adapter/libcodelldb_python.so
adapter/libcodelldb.dylib
adapter/libcodelldb_python.dylib
adapter/codelldb.exe
adapter/codelldb.dll
adapter/codelldb_python.dll
lldb/bin/**/*
lldb/lib/**/*
)
# Indicator file used to determine whether we have the platform package.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/platform.ok "")
set(Content **)
foreach(Line ${PackagedFilesBootstrap})
set(Content ${Content}\n!${Line})
endforeach()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/vscodeignore-bootstrap ${Content})
set(Content **)
foreach(Line ${PackagedFilesFull})
set(Content ${Content}\n!${Line})
endforeach()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/vscodeignore-full ${Content})
set(VsceOptions
--baseContentUrl https://github.com/vadimcn/vscode-lldb/blob/v${VERSION}
--baseImagesUrl https://github.com/vadimcn/vscode-lldb/raw/v${VERSION}
)
add_custom_target(vsix_bootstrap
DEPENDS extension ${PackageFiles}
COMMAND ${UpdateFile} ${CMAKE_CURRENT_BINARY_DIR}/vscodeignore-bootstrap ${CMAKE_CURRENT_BINARY_DIR}/.vscodeignore
COMMAND ${NPM} run vsce -- package ${VsceOptions} -o ${CMAKE_CURRENT_BINARY_DIR}/codelldb-bootstrap.vsix
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
)
add_custom_target(vsix_full
DEPENDS extension lldb codelldb ${PackageFiles}
COMMAND ${UpdateFile} ${CMAKE_CURRENT_BINARY_DIR}/vscodeignore-full ${CMAKE_CURRENT_BINARY_DIR}/.vscodeignore
COMMAND ${NPM} run vsce -- package ${VsceOptions} -o ${CMAKE_CURRENT_BINARY_DIR}/codelldb-full.vsix
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL
)
# Strip native binaries if building vsix_full
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if (NOT CMAKE_STRIP)
set(CMAKE_STRIP strip)
endif()
add_custom_target(strip_binaries
DEPENDS lldb codelldb
COMMAND find ${CMAKE_CURRENT_BINARY_DIR}/adapter -type f "\\(" -executable -o -name "*.so" -o -name "*.so.*" "\\)" -print -exec ${CMAKE_STRIP} --strip-debug "{}" "\;"
COMMAND find ${CMAKE_CURRENT_BINARY_DIR}/lldb -type f "\\(" -executable -o -name "*.so" -o -name "*.so.*" "\\)" -not -name "*.py" -print -exec ${CMAKE_STRIP} --strip-debug "{}" "\;"
COMMENT "Stripping debug info"
USES_TERMINAL
)
add_dependencies(vsix_full strip_binaries)
endif()
# Build both VSIX packages, then extract vsix_bootstrap to build/extracted
add_custom_target(vsix_extracted
DEPENDS vsix_bootstrap vsix_full
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/extracted
COMMAND unzip -o ${CMAKE_CURRENT_BINARY_DIR}/codelldb-full.vsix -d ${CMAKE_CURRENT_BINARY_DIR}/extracted
COMMAND ${UpdateFile} ${CMAKE_CURRENT_BINARY_DIR}/extension/*.map ${CMAKE_CURRENT_BINARY_DIR}/extracted/extension/extension
)
# Debuggee
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee)
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/debuggee -G "${CMAKE_GENERATOR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee
)
add_custom_target(debuggee
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/debuggee
)
else()
# On Windows we want to check both MSVC PDB and GNU DWARF debug info kinds.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee-msvc)
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/debuggee -G "${CMAKE_GENERATOR}" -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee-msvc
)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee-gnu)
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/debuggee -G "${CMAKE_GENERATOR}" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debuggee-gnu
)
add_custom_target(debuggee
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/debuggee-msvc
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/debuggee-gnu
)
endif()
# Tests
set(MochaTest ${NPM} run mocha --
-u tdd --timeout 30000 --exit
--require source-map-support/register
#-g "rust_variables"
${CMAKE_BINARY_DIR}/tests.js
)
# Build everything for testing
add_dependencies(tests codelldb debuggee)
# Tests and test targets
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(TestTriples x86_64-pc-windows-gnu x86_64-pc-windows-msvc)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(TestTriples x86_64-apple-darwin)
else()
set(TestTriples x86_64-unknown-linux-gnu)
endif()
foreach(TestTriple ${TestTriples})
set(TestName adapter:${TestTriple})
add_test(NAME ${TestName}
COMMAND ${WithEnv} TARGET_TRIPLE=${TestTriple} NODE_PATH=${CMAKE_BINARY_DIR} BUILD_DIR=${CMAKE_BINARY_DIR} SOURCE_DIR=${CMAKE_SOURCE_DIR} ${MochaTest}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST ${TestName} PROPERTY RUN_SERIAL TRUE)
endforeach(TestTriple)
add_custom_target(check
DEPENDS tests cargo_test
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
)
# Install
install(CODE "file(REMOVE_RECURSE \"${CMAKE_INSTALL_PREFIX}/codelldb\")")
install(
DIRECTORY ${ExtensionRoot}
DESTINATION .
)
# XtraClean
add_custom_target(xclean
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
COMMAND ${CMAKE_COMMAND} -E remove_directory CMakeFiles
COMMAND ${CMAKE_COMMAND} -E remove_directory adapter
COMMAND ${CMAKE_COMMAND} -E remove_directory debuggee
COMMAND ${CMAKE_COMMAND} -E remove_directory extension
COMMAND ${CMAKE_COMMAND} -E remove_directory lldb
COMMAND ${CMAKE_COMMAND} -E remove_directory node_modules
COMMAND ${CMAKE_COMMAND} -E remove_directory target
COMMAND ${CMAKE_COMMAND} -E remove_directory tests
COMMAND ${CMAKE_COMMAND} -E remove_directory tmp
COMMAND ${CMAKE_COMMAND} ..
)