150
|
1 cmake_minimum_required(VERSION 3.4.3)
|
|
2 if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
|
3 cmake_minimum_required(VERSION 3.13)
|
|
4 endif()
|
|
5
|
|
6 if(POLICY CMP0075)
|
|
7 cmake_policy(SET CMP0075 NEW)
|
|
8 endif()
|
|
9
|
|
10 # Add path for custom modules.
|
|
11 set(CMAKE_MODULE_PATH
|
|
12 ${CMAKE_MODULE_PATH}
|
|
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
|
15 )
|
|
16
|
|
17 # If we are not building as part of LLVM, build LLDB as a standalone project,
|
|
18 # using LLVM as an external library.
|
|
19 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
20 project(lldb)
|
|
21 include(LLDBStandalone)
|
|
22
|
|
23 set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
|
|
24 set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
|
25 set(CMAKE_CXX_EXTENSIONS NO)
|
|
26 endif()
|
|
27
|
|
28 include(LLDBConfig)
|
|
29 include(AddLLDB)
|
|
30
|
|
31 # Define the LLDB_CONFIGURATION_xxx matching the build type.
|
|
32 if( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
|
|
33 add_definitions( -DLLDB_CONFIGURATION_DEBUG )
|
|
34 else()
|
|
35 add_definitions( -DLLDB_CONFIGURATION_RELEASE )
|
|
36 endif()
|
|
37
|
|
38 if(APPLE)
|
|
39 add_definitions(-DLLDB_USE_OS_LOG)
|
|
40 endif()
|
|
41
|
|
42 if (WIN32)
|
|
43 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
|
|
44 endif()
|
|
45
|
|
46 if (LLDB_ENABLE_PYTHON)
|
|
47 execute_process(
|
|
48 COMMAND ${PYTHON_EXECUTABLE}
|
|
49 -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(True, False, ''))"
|
|
50 OUTPUT_VARIABLE LLDB_PYTHON_DEFAULT_RELATIVE_PATH
|
|
51 OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
52
|
|
53 file(TO_CMAKE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH} LLDB_PYTHON_DEFAULT_RELATIVE_PATH)
|
|
54 set(LLDB_PYTHON_RELATIVE_PATH ${LLDB_PYTHON_DEFAULT_RELATIVE_PATH}
|
|
55 CACHE STRING "Path where Python modules are installed, relative to install prefix")
|
|
56 endif ()
|
|
57
|
|
58 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
|
|
59 add_subdirectory(bindings)
|
|
60 endif ()
|
|
61
|
|
62 # We need the headers generated by instrinsics_gen before we can compile
|
|
63 # any source file in LLDB as the imported Clang modules might include
|
|
64 # some of these generated headers. This approach is copied from Clang's main
|
|
65 # CMakeLists.txt, so it should kept in sync the code in Clang which was added
|
|
66 # in llvm-svn 308844.
|
|
67 if(LLVM_ENABLE_MODULES AND NOT LLDB_BUILT_STANDALONE)
|
|
68 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
|
|
69 endif()
|
|
70
|
|
71 if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE)
|
|
72 set(LLVM_USE_HOST_TOOLS ON)
|
|
73 include(CrossCompile)
|
|
74 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)
|
|
75 message(FATAL_ERROR
|
|
76 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR
|
|
77 for building the native lldb-tblgen used during the build process.")
|
|
78 endif()
|
|
79 llvm_create_cross_target(lldb NATIVE "" Release
|
|
80 -DLLVM_DIR=${NATIVE_LLVM_DIR}
|
|
81 -DClang_DIR=${NATIVE_Clang_DIR})
|
|
82 endif()
|
|
83
|
|
84 # TableGen
|
|
85 add_subdirectory(utils/TableGen)
|
|
86
|
|
87 add_subdirectory(source)
|
|
88 add_subdirectory(tools)
|
|
89 add_subdirectory(docs)
|
|
90
|
|
91 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
|
|
92 if(LLDB_INCLUDE_TESTS)
|
|
93 add_subdirectory(test)
|
|
94 add_subdirectory(unittests)
|
|
95 add_subdirectory(utils)
|
|
96 endif()
|
|
97
|
|
98 if (LLDB_ENABLE_PYTHON)
|
|
99 get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
|
|
100
|
|
101 if(LLDB_BUILD_FRAMEWORK)
|
|
102 set(lldb_python_build_path "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
|
|
103 else()
|
|
104 set(lldb_python_build_path "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
|
|
105 endif()
|
|
106
|
|
107 # Add a Post-Build Event to copy over Python files and create the symlink
|
|
108 # to liblldb.so for the Python API(hardlink on Windows).
|
|
109 add_custom_target(finish_swig ALL VERBATIM
|
|
110 COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_build_path}
|
|
111 DEPENDS ${lldb_bindings_dir}/lldb.py
|
|
112 COMMENT "Python script sym-linking LLDB Python API")
|
|
113
|
|
114 if(NOT LLDB_USE_SYSTEM_SIX)
|
|
115 add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
|
|
116 COMMAND ${CMAKE_COMMAND} -E copy
|
|
117 "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py"
|
|
118 "${lldb_python_build_path}/../six.py")
|
|
119 endif()
|
|
120
|
|
121 add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
|
|
122 COMMAND ${CMAKE_COMMAND} -E copy
|
|
123 "${lldb_bindings_dir}/lldb.py"
|
|
124 "${lldb_python_build_path}/__init__.py")
|
|
125
|
|
126 function(create_python_package pkg_dir)
|
|
127 cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
|
|
128 if(ARG_FILES)
|
|
129 set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir})
|
|
130 endif()
|
|
131 if(NOT ARG_NOINIT)
|
|
132 set(init_cmd COMMAND ${PYTHON_EXECUTABLE}
|
|
133 "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py"
|
|
134 "${pkg_dir}" ${ARG_FILES})
|
|
135 endif()
|
|
136 add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
|
|
137 COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir}
|
|
138 ${copy_cmd}
|
|
139 ${init_cmd}
|
|
140 WORKING_DIRECTORY ${lldb_python_build_path})
|
|
141 endfunction()
|
|
142
|
|
143 add_custom_command(TARGET finish_swig POST_BUILD VERBATIM
|
|
144 COMMAND ${CMAKE_COMMAND} -E copy
|
|
145 "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py" ${lldb_python_build_path})
|
|
146
|
|
147 # Distribute the examples as python packages.
|
|
148 create_python_package("formatters/cpp"
|
|
149 FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py"
|
|
150 "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py")
|
|
151
|
|
152 create_python_package("formatters"
|
|
153 FILES "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/cache.py"
|
|
154 "${LLDB_SOURCE_DIR}/examples/summaries/synth.py"
|
|
155 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/metrics.py"
|
|
156 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/attrib_fromdict.py"
|
|
157 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/Logger.py")
|
|
158
|
|
159 create_python_package("utils"
|
|
160 FILES "${LLDB_SOURCE_DIR}/examples/python/in_call_stack.py"
|
|
161 "${LLDB_SOURCE_DIR}/examples/python/symbolication.py")
|
|
162
|
|
163 if(APPLE)
|
|
164 create_python_package("macosx"
|
|
165 FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py"
|
|
166 "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py")
|
|
167
|
|
168 create_python_package("macosx/heap"
|
|
169 FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp"
|
|
170 "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile"
|
|
171 NOINIT)
|
|
172
|
|
173 create_python_package("diagnose"
|
|
174 FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py"
|
|
175 "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py")
|
|
176 endif()
|
|
177
|
|
178 function(create_relative_symlink target dest_file output_dir output_name)
|
|
179 get_filename_component(dest_file ${dest_file} ABSOLUTE)
|
|
180 get_filename_component(output_dir ${output_dir} ABSOLUTE)
|
|
181 file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
|
|
182 if(CMAKE_HOST_UNIX)
|
|
183 set(LLVM_LINK_OR_COPY create_symlink)
|
|
184 else()
|
|
185 set(LLVM_LINK_OR_COPY copy)
|
|
186 endif()
|
|
187 add_custom_command(TARGET ${target} POST_BUILD VERBATIM
|
|
188 COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
|
|
189 WORKING_DIRECTORY ${output_dir})
|
|
190 endfunction()
|
|
191
|
|
192 if(LLDB_BUILD_FRAMEWORK)
|
|
193 set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
|
|
194 else()
|
|
195 set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
196 endif()
|
|
197 if(WIN32)
|
|
198 if(CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
199 set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
|
|
200 else()
|
|
201 set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
|
|
202 endif()
|
|
203 else()
|
|
204 set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
|
|
205 endif()
|
|
206 create_relative_symlink(finish_swig ${LIBLLDB_SYMLINK_DEST}
|
|
207 ${lldb_python_build_path} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
|
|
208
|
|
209 if(NOT LLDB_BUILD_FRAMEWORK)
|
|
210 set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}")
|
|
211 create_relative_symlink(finish_swig "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}"
|
|
212 ${lldb_python_build_path} ${LLDB_ARGDUMPER_FILENAME})
|
|
213 endif()
|
|
214
|
|
215 add_dependencies(finish_swig swig_wrapper liblldb lldb-argdumper)
|
|
216 set_target_properties(finish_swig swig_wrapper PROPERTIES FOLDER "lldb misc")
|
|
217
|
|
218 # Ensure we do the python post-build step when building lldb.
|
|
219 add_dependencies(lldb finish_swig)
|
|
220
|
|
221 # Install the LLDB python module
|
|
222 if(LLDB_BUILD_FRAMEWORK)
|
|
223 set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
|
|
224 else()
|
|
225 set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
|
|
226 endif()
|
|
227 add_custom_target(lldb-python-scripts)
|
|
228 add_dependencies(lldb-python-scripts finish_swig)
|
|
229 install(DIRECTORY ${lldb_python_build_path}/../
|
|
230 DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
|
|
231 COMPONENT lldb-python-scripts)
|
|
232 if (NOT LLVM_ENABLE_IDE)
|
|
233 add_llvm_install_targets(install-lldb-python-scripts
|
|
234 COMPONENT lldb-python-scripts
|
|
235 DEPENDS lldb-python-scripts)
|
|
236 endif()
|
|
237
|
|
238 # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
|
|
239 # lldb.exe or any other executables that were linked with liblldb.
|
|
240 if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "")
|
|
241 # When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc.
|
|
242 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR)
|
|
243 file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH)
|
|
244 add_custom_command(
|
|
245 TARGET finish_swig
|
|
246 POST_BUILD
|
|
247 COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
|
|
248 COMMENT "Copying Python DLL to LLDB binaries directory.")
|
|
249 endif ()
|
|
250 endif ()
|
|
251
|
|
252 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
|
|
253 llvm_distribution_add_targets()
|
|
254 endif()
|