xref: /llvm-project/lldb/source/API/CMakeLists.txt (revision 6b048aeaf837e0e16fece94610f0871d17cefe4c)
1get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
2
3if(LLDB_BUILD_FRAMEWORK)
4  set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
5  set(option_framework FRAMEWORK)
6endif()
7
8if(LLDB_ENABLE_PYTHON)
9  if (APPLE AND LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY)
10    # Work around an issue with the Python headers, which have a modular include
11    # inside an extern "C" block.
12    remove_module_flags()
13  endif()
14  get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR)
15  set(lldb_python_wrapper ${python_bindings_dir}/LLDBWrapPython.cpp)
16endif()
17
18if(LLDB_ENABLE_LUA)
19  get_target_property(lua_bindings_dir swig_wrapper_lua BINARY_DIR)
20  set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
21endif()
22
23# Generate SBLanguages.h from Dwarf.def.
24set(sb_languages_file
25  ${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h)
26set(sb_languages_generator
27  ${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py)
28add_custom_command(
29  COMMENT "Generating SBLanguages.h from Dwarf.def"
30  COMMAND "${Python3_EXECUTABLE}"
31      ${sb_languages_generator}
32      ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
33      -o ${sb_languages_file}
34  OUTPUT ${sb_languages_file}
35  DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
36          ${sb_languages_generator}
37  WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
38)
39add_custom_target(lldb-sbapi-dwarf-enums
40  DEPENDS ${sb_languages_file})
41set_target_properties(lldb-sbapi-dwarf-enums PROPERTIES FOLDER "LLDB/Tablegenning")
42
43add_lldb_library(liblldb SHARED ${option_framework}
44  SBAddress.cpp
45  SBAddressRange.cpp
46  SBAddressRangeList.cpp
47  SBAttachInfo.cpp
48  SBBlock.cpp
49  SBBreakpoint.cpp
50  SBBreakpointLocation.cpp
51  SBBreakpointName.cpp
52  SBBreakpointOptionCommon.cpp
53  SBBroadcaster.cpp
54  SBCommandInterpreter.cpp
55  SBCommandInterpreterRunOptions.cpp
56  SBCommandReturnObject.cpp
57  SBCommunication.cpp
58  SBCompileUnit.cpp
59  SBSaveCoreOptions.cpp
60  SBData.cpp
61  SBDebugger.cpp
62  SBDeclaration.cpp
63  SBEnvironment.cpp
64  SBError.cpp
65  SBEvent.cpp
66  SBExecutionContext.cpp
67  SBExpressionOptions.cpp
68  SBFileSpec.cpp
69  SBFile.cpp
70  SBFileSpecList.cpp
71  SBFormat.cpp
72  SBFrame.cpp
73  SBFunction.cpp
74  SBHostOS.cpp
75  SBInstruction.cpp
76  SBInstructionList.cpp
77  SBLanguageRuntime.cpp
78  SBLaunchInfo.cpp
79  SBLineEntry.cpp
80  SBListener.cpp
81  SBMemoryRegionInfo.cpp
82  SBMemoryRegionInfoList.cpp
83  SBModule.cpp
84  SBModuleSpec.cpp
85  SBPlatform.cpp
86  SBProgress.cpp
87  SBProcess.cpp
88  SBProcessInfo.cpp
89  SBProcessInfoList.cpp
90  SBQueue.cpp
91  SBQueueItem.cpp
92  SBReproducer.cpp
93  SBScriptObject.cpp
94  SBSection.cpp
95  SBSourceManager.cpp
96  SBStatisticsOptions.cpp
97  SBStream.cpp
98  SBStringList.cpp
99  SBStructuredData.cpp
100  SBSymbol.cpp
101  SBSymbolContext.cpp
102  SBSymbolContextList.cpp
103  SBTarget.cpp
104  SBThread.cpp
105  SBThreadCollection.cpp
106  SBThreadPlan.cpp
107  SBTrace.cpp
108  SBTraceCursor.cpp
109  SBType.cpp
110  SBTypeCategory.cpp
111  SBTypeEnumMember.cpp
112  SBTypeFilter.cpp
113  SBTypeFormat.cpp
114  SBTypeNameSpecifier.cpp
115  SBTypeSummary.cpp
116  SBTypeSynthetic.cpp
117  SBValue.cpp
118  SBValueList.cpp
119  SBVariablesOptions.cpp
120  SBWatchpoint.cpp
121  SBWatchpointOptions.cpp
122  SBUnixSignals.cpp
123  SystemInitializerFull.cpp
124  ${lldb_python_wrapper}
125  ${lldb_lua_wrapper}
126
127  DEPENDS
128    lldb-sbapi-dwarf-enums
129
130  LINK_LIBS
131    lldbBreakpoint
132    lldbCore
133    lldbDataFormatters
134    lldbExpression
135    lldbHost
136    lldbInitialization
137    lldbInterpreter
138    lldbSymbol
139    lldbTarget
140    lldbUtility
141    lldbValueObject
142    lldbVersion
143    ${LLDB_ALL_PLUGINS}
144  LINK_COMPONENTS
145    Support
146
147  ${option_install_prefix}
148)
149
150# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
151# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
152# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
153# that _lldb.so can be loaded from Python.
154if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX AND NOT APPLE)
155  set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
156endif()
157
158if(Python3_RPATH)
159  set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
160  set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH   "${Python3_RPATH}")
161endif()
162
163
164if(LLDB_ENABLE_PYTHON)
165  add_dependencies(liblldb swig_wrapper_python)
166
167  if (MSVC)
168    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
169  else()
170    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
171  endif()
172
173  set_source_files_properties(${lldb_python_wrapper} PROPERTIES GENERATED ON)
174  if (CLANG_CL)
175    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
176      PROPERTY COMPILE_FLAGS " -Wno-unused-function")
177  endif()
178  if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND
179      NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
180    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
181      PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual")
182  endif ()
183endif()
184
185if(LLDB_ENABLE_LUA)
186  add_dependencies(liblldb swig_wrapper_lua)
187  target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR})
188
189  if (MSVC)
190    set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
191  else()
192    set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
193  endif()
194
195  set_source_files_properties(${lldb_lua_wrapper} PROPERTIES GENERATED ON)
196endif()
197
198set_target_properties(liblldb
199  PROPERTIES
200  VERSION ${LLDB_VERSION}
201)
202
203target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
204if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
205  if (NOT LLDB_EXPORT_ALL_SYMBOLS)
206    # If we're not exporting all symbols, we'll want to explicitly set
207    # the exported symbols here.  This prevents 'log enable --stack ...'
208    # from working on some systems but limits the liblldb size.
209    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace")
210    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
211  elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
212    # Don't use an explicit export. Instead, tell the linker to export all symbols.
213    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
214    MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
215                    "Only the SB API is guaranteed to be stable.")
216    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
217  else ()
218    MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the exports "
219            " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
220    MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
221                    "Only the SB API is guaranteed to be stable.")
222    add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
223  endif()
224elseif (LLDB_EXPORT_ALL_SYMBOLS)
225  MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
226
227  # Pull out the various lldb libraries linked into liblldb, these will be used
228  # when looking for symbols to extract. We ignore most plugin libraries here,
229  # because we may expose more symbols than the DLL limit and these symbols
230  # aren't useful to expose.
231  get_target_property(all_liblldb_libs liblldb LINK_LIBRARIES)
232  set(lldb_libs "")
233  foreach(lib ${all_liblldb_libs})
234    if(TARGET ${lib} AND ${lib} MATCHES "^lldb" AND
235       (${lib} IN_LIST LLDB_EXPORT_ALL_SYMBOLS_PLUGINS OR
236        NOT ${lib} MATCHES "^lldbPlugin"))
237      get_target_property(lib_type ${lib} TYPE)
238      if("${lib_type}" STREQUAL "STATIC_LIBRARY")
239        list(APPEND lldb_libs ${lib})
240      endif()
241    endif()
242  endforeach(lib)
243  list(REMOVE_DUPLICATES lldb_libs)
244
245  # Extract all of the private symbols and produce a single file we can use for
246  # the exports.
247  set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/liblldb_private.symbols)
248  get_host_tool_path(llvm-nm LLVM_NM llvm_nm_exe llvm_nm_target)
249  add_custom_command(
250    OUTPUT ${exported_symbol_file}
251    COMMAND "${Python3_EXECUTABLE}"
252      ${LLDB_SOURCE_DIR}/scripts/msvc_extract_private_symbols.py
253      ${lldb_libs} -o ${exported_symbol_file} --nm=${llvm_nm_exe}
254    WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
255    DEPENDS ${LLDB_SOURCE_DIR}/scripts/msvc_extract_private_symbols.py
256      ${lldb_libs} ${llvm_nm_target}
257    VERBATIM
258    COMMENT "Generating liblldb private export list"
259  )
260
261  add_llvm_symbol_exports(liblldb ${exported_symbol_file})
262endif()
263
264if (NOT MSVC)
265  set_target_properties(liblldb
266    PROPERTIES
267    OUTPUT_NAME lldb
268  )
269endif()
270
271# The Clang expression parser in LLDB requires the Clang resource directory to function.
272if (TARGET clang-resource-headers)
273  # If building alongside Clang, just add a dependency to ensure it is build together with liblldb.
274  add_dependencies(liblldb clang-resource-headers)
275else()
276  # In a standalone build create a symlink from the LLDB library directory that points to the
277  # resource directory in the Clang library directory. LLDB searches relative to its install path,
278  # and the symlink is created in the same relative path as the resource directory of Clang when
279  # building alongside Clang.
280  # When building the LLDB framework, this isn't necessary as there we copy everything we need into
281  # the framework (including the Clang resourece directory).
282  if(NOT LLDB_BUILD_FRAMEWORK)
283    set(LLDB_CLANG_RESOURCE_DIR "$<TARGET_FILE_DIR:liblldb>/clang")
284    add_custom_command(TARGET liblldb POST_BUILD
285      COMMENT "Linking Clang resource dir into LLDB build directory: ${LLDB_CLANG_RESOURCE_DIR}"
286      COMMAND ${CMAKE_COMMAND} -E create_symlink
287      "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}" "${LLDB_CLANG_RESOURCE_DIR}"
288    )
289  endif()
290endif()
291
292if(LLDB_BUILD_FRAMEWORK)
293  include(LLDBFramework)
294
295  if (TARGET install-liblldb)
296    add_dependencies(install-liblldb
297      lldb-framework-cleanup)
298  endif()
299
300  if (TARGET install-liblldb-stripped)
301    add_dependencies(install-liblldb-stripped
302      lldb-framework-cleanup)
303  endif()
304endif()
305