This repository has been archived by the owner on Apr 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
/
CMakeLists.txt
260 lines (220 loc) · 9.41 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
cmake_minimum_required(VERSION 3.4.3)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
# Add path for custom modules.
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)
# If we are not building as part of LLVM, build LLDB as a standalone project,
# using LLVM as an external library.
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(lldb)
include(LLDBStandalone)
else()
set(SWIFT_BINARY_DIR ${CMAKE_BINARY_DIR})
set(SWIFT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
set(SWIFT_LIBRARY_DIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
endif()
include(LLDBConfig)
include(AddLLDB)
# BEGIN - Swift Mods
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../swift)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/../swift/cmake/modules")
endif()
# END - Swift Mods
# Define the LLDB_CONFIGURATION_xxx matching the build type.
if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
add_definitions( -DLLDB_CONFIGURATION_DEBUG )
else()
add_definitions( -DLLDB_CONFIGURATION_RELEASE )
endif()
if(APPLE)
add_definitions(-DLLDB_USE_OS_LOG)
endif()
if (WIN32)
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
endif()
if (NOT LLDB_DISABLE_PYTHON)
add_subdirectory(scripts)
endif ()
# We need the headers generated by instrinsics_gen before we can compile
# any source file in LLDB as the imported Clang modules might include
# some of these generated headers. This approach is copied from Clang's main
# CMakeLists.txt, so it should kept in sync the code in Clang which was added
# in llvm-svn 308844.
if(LLVM_ENABLE_MODULES AND NOT LLDB_BUILT_STANDALONE)
list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
endif()
if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE)
set(LLVM_USE_HOST_TOOLS ON)
include(CrossCompile)
if (NOT LLDB_PATH_TO_NATIVE_SWIFT_BUILD OR
NOT NATIVE_LLVM_DIR OR
NOT NATIVE_Clang_DIR)
message(FATAL_ERROR
"Crosscompiling standalone requires the variables LLDB_PATH_TO_NATIVE_{SWIFT,CLANG,LLVM}_BUILD
for building the native lldb-tblgen used during the build process.")
endif()
llvm_create_cross_target(lldb NATIVE "" Release
-DSwift_DIR=${LLDB_PATH_TO_NATIVE_SWIFT_BUILD}
-DLLVM_DIR=${NATIVE_LLVM_DIR}
-DClang_DIR=${NATIVE_Clang_DIR})
endif()
# TableGen
add_subdirectory(utils/TableGen)
add_subdirectory(source)
add_subdirectory(tools)
add_subdirectory(docs)
option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
if(LLDB_INCLUDE_TESTS)
set(LLDB_TEST_BUILD_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
# Set the path to the default lldb test executable.
set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}")
# Set the paths to default llvm tools.
set(LLDB_DEFAULT_TEST_DSYMUTIL "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/dsymutil${CMAKE_EXECUTABLE_SUFFIX}")
set(LLDB_DEFAULT_TEST_FILECHECK "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/FileCheck${CMAKE_EXECUTABLE_SUFFIX}")
# BEGIN - Swift Mods
set(LLDB_DEFAULT_TEST_C_COMPILER "${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}")
set(LLDB_DEFAULT_TEST_CXX_COMPILER "${LLVM_BINARY_DIR}/bin/clang++${CMAKE_EXECUTABLE_SUFFIX}")
# END - Swift Mods
set(LLDB_TEST_EXECUTABLE "${LLDB_DEFAULT_TEST_EXECUTABLE}" CACHE PATH "lldb executable used for testing")
set(LLDB_TEST_C_COMPILER "${LLDB_DEFAULT_TEST_C_COMPILER}" CACHE PATH "C Compiler to use for building LLDB test inferiors")
set(LLDB_TEST_CXX_COMPILER "${LLDB_DEFAULT_TEST_CXX_COMPILER}" CACHE PATH "C++ Compiler to use for building LLDB test inferiors")
set(LLDB_TEST_DSYMUTIL "${LLDB_DEFAULT_TEST_DSYMUTIL}" CACHE PATH "dsymutil used for generating dSYM bundles")
set(LLDB_TEST_FILECHECK "${LLDB_DEFAULT_TEST_FILECHECK}" CACHE PATH "FileCheck used for testing purposes")
if (("${LLDB_TEST_C_COMPILER}" STREQUAL "") OR
("${LLDB_TEST_CXX_COMPILER}" STREQUAL ""))
message(FATAL_ERROR "LLDB test compilers not specified. Tests will not run.")
endif()
set(LLDB_TEST_DEPS lldb)
# darwin-debug is an hard dependency for the testsuite.
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND LLDB_TEST_DEPS darwin-debug)
endif()
# lldb-test is an hard dependency for the testsuite.
list(APPEND LLDB_TEST_DEPS lldb-test)
if(TARGET lldb-server)
list(APPEND LLDB_TEST_DEPS lldb-server)
endif()
if(TARGET lldb-vscode)
list(APPEND LLDB_TEST_DEPS lldb-vscode)
endif()
if(TARGET lldb-instr)
list(APPEND LLDB_TEST_DEPS lldb-instr)
endif()
if(NOT LLDB_BUILT_STANDALONE)
list(APPEND LLDB_TEST_DEPS yaml2obj)
endif()
if(TARGET liblldb)
list(APPEND LLDB_TEST_DEPS liblldb)
endif()
if(TARGET repl_swift)
list(APPEND LLDB_TEST_DEPS repl_swift)
endif()
# Add dependencies if we test with the in-tree clang.
# This works with standalone builds as they import the clang target.
if(TARGET clang)
list(APPEND LLDB_TEST_DEPS clang)
if(APPLE)
# If we build clang, we should build libcxx.
# FIXME: Standalone builds should import the cxx target as well.
if(LLDB_BUILT_STANDALONE)
# For now check that the include directory exists.
set(cxx_dir "${LLVM_BINARY_DIR}/include/c++")
if(NOT EXISTS ${cxx_dir})
message(WARNING "LLDB test suite requires libc++ in llvm/projects/libcxx or an existing build symlinked to ${cxx_dir}")
endif()
else()
# We require libcxx for the test suite, so if we aren't building it,
# try to provide a helpful error about how to resolve the situation.
if(NOT TARGET cxx)
if(LLVM_ENABLE_PROJECTS STREQUAL "")
# If `LLVM_ENABLE_PROJECTS` is not being used (implying that we are
# using the old layout), suggest checking it out.
message(FATAL_ERROR
"LLDB test suite requires libc++, but it is currently disabled. "
"Please checkout `libcxx` in `llvm/projects` or disable tests "
"via `LLDB_INCLUDE_TESTS=OFF`.")
else()
# If `LLVM_ENABLE_PROJECTS` is being used, suggest adding it.
message(FATAL_ERROR
"LLDB test suite requires libc++, but it is currently disabled. "
"Please add `libcxx` to `LLVM_ENABLE_PROJECTS` or disable tests "
"via `LLDB_INCLUDE_TESTS=OFF`.")
endif()
endif()
list(APPEND LLDB_TEST_DEPS cxx)
endif()
endif()
endif()
# BEGIN Swift Mods
if(swift IN_LIST LLVM_EXTERNAL_PROJECTS)
list(APPEND LLDB_TEST_DEPS swift)
endif()
# END Swift Mods
if(TARGET dsymutil)
list(APPEND LLDB_TEST_DEPS dsymutil)
endif()
if(TARGET lldb-framework)
list(APPEND LLDB_TEST_DEPS lldb-framework)
endif()
add_custom_target(lldb-test-deps)
add_dependencies(lldb-test-deps ${LLDB_TEST_DEPS})
set_target_properties(lldb-test-deps PROPERTIES FOLDER "lldb misc")
add_subdirectory(test)
add_subdirectory(unittests)
add_subdirectory(lit)
add_subdirectory(utils/lit-cpuid)
add_subdirectory(utils/lldb-dotest)
endif()
if (NOT LLDB_DISABLE_PYTHON)
if(NOT LLDB_BUILD_FRAMEWORK)
set(use_python_wrapper_from_src_dir -m)
endif()
if(LLDB_USE_SYSTEM_SIX)
set(use_six_py_from_system --useSystemSix)
endif()
get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR)
get_target_property(liblldb_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
# Add a Post-Build Event to copy over Python files and create the symlink
# to liblldb.so for the Python API(hardlink on Windows)
add_custom_target(finish_swig ALL
COMMAND
${PYTHON_EXECUTABLE} ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
--srcRoot=${LLDB_SOURCE_DIR}
--targetDir=${liblldb_build_dir}
--cfgBldDir=${lldb_scripts_dir}
--prefix=${CMAKE_BINARY_DIR}
--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}
--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}
${use_python_wrapper_from_src_dir}
${use_six_py_from_system}
VERBATIM
DEPENDS ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
DEPENDS ${lldb_scripts_dir}/lldb.py
COMMENT "Python script sym-linking LLDB Python API")
add_dependencies(finish_swig swig_wrapper liblldb lldb-argdumper)
set_target_properties(finish_swig swig_wrapper PROPERTIES FOLDER "lldb misc")
# Ensure we do the python post-build step when building lldb.
add_dependencies(lldb finish_swig)
# Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
# lldb.exe or any other executables that were linked with liblldb.
if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "")
# When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc.
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR)
file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH)
add_custom_command(
TARGET finish_swig
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
COMMENT "Copying Python DLL to LLDB binaries directory.")
endif ()
endif ()
if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
llvm_distribution_add_targets()
endif()