[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFT...
[llvm-project.git] / lldb / source / API / CMakeLists.txt
blobd8308841c05dbab36ea8d602fd6ed30f8064b531
1 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
3 if(LLDB_BUILD_FRAMEWORK)
4   set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
5   set(option_framework FRAMEWORK)
6 endif()
8 if(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)
16 endif()
18 if(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)
21 endif()
23 # Generate SBLanguages.h from Dwarf.def.
24 set(sb_languages_file
25   ${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h)
26 set(sb_languages_generator
27   ${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py)
28 add_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}
39 add_custom_target(lldb-sbapi-dwarf-enums
40   DEPENDS ${sb_languages_file})
41 set_target_properties(lldb-sbapi-dwarf-enums PROPERTIES FOLDER "LLDB/Tablegenning")
43 add_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   SBProcess.cpp
87   SBProcessInfo.cpp
88   SBProcessInfoList.cpp
89   SBQueue.cpp
90   SBQueueItem.cpp
91   SBReproducer.cpp
92   SBScriptObject.cpp
93   SBSection.cpp
94   SBSourceManager.cpp
95   SBStatisticsOptions.cpp
96   SBStream.cpp
97   SBStringList.cpp
98   SBStructuredData.cpp
99   SBSymbol.cpp
100   SBSymbolContext.cpp
101   SBSymbolContextList.cpp
102   SBTarget.cpp
103   SBThread.cpp
104   SBThreadCollection.cpp
105   SBThreadPlan.cpp
106   SBTrace.cpp
107   SBTraceCursor.cpp
108   SBType.cpp
109   SBTypeCategory.cpp
110   SBTypeEnumMember.cpp
111   SBTypeFilter.cpp
112   SBTypeFormat.cpp
113   SBTypeNameSpecifier.cpp
114   SBTypeSummary.cpp
115   SBTypeSynthetic.cpp
116   SBValue.cpp
117   SBValueList.cpp
118   SBVariablesOptions.cpp
119   SBWatchpoint.cpp
120   SBWatchpointOptions.cpp
121   SBUnixSignals.cpp
122   SystemInitializerFull.cpp
123   ${lldb_python_wrapper}
124   ${lldb_lua_wrapper}
126   DEPENDS
127     lldb-sbapi-dwarf-enums
129   LINK_LIBS
130     lldbBreakpoint
131     lldbCore
132     lldbDataFormatters
133     lldbExpression
134     lldbHost
135     lldbInitialization
136     lldbInterpreter
137     lldbSymbol
138     lldbTarget
139     lldbUtility
140     lldbValueObject
141     lldbVersion
142     ${LLDB_ALL_PLUGINS}
143   LINK_COMPONENTS
144     Support
146   ${option_install_prefix}
149 # lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
150 # which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
151 # (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
152 # that _lldb.so can be loaded from Python.
153 if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX AND NOT APPLE)
154   set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
155 endif()
157 if(Python3_RPATH)
158   set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
159   set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH   "${Python3_RPATH}")
160 endif()
163 if(LLDB_ENABLE_PYTHON)
164   add_dependencies(liblldb swig_wrapper_python)
166   if (MSVC)
167     set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
168   else()
169     set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
170   endif()
172   set_source_files_properties(${lldb_python_wrapper} PROPERTIES GENERATED ON)
173   if (CLANG_CL)
174     set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
175       PROPERTY COMPILE_FLAGS " -Wno-unused-function")
176   endif()
177   if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND
178       NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
179     set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
180       PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual")
181   endif ()
182 endif()
184 if(LLDB_ENABLE_LUA)
185   add_dependencies(liblldb swig_wrapper_lua)
186   target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR})
188   if (MSVC)
189     set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
190   else()
191     set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
192   endif()
194   set_source_files_properties(${lldb_lua_wrapper} PROPERTIES GENERATED ON)
195 endif()
197 set_target_properties(liblldb
198   PROPERTIES
199   VERSION ${LLDB_VERSION}
202 target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
203 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
204   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
205     # If we're not exporting all symbols, we'll want to explicitly set
206     # the exported symbols here.  This prevents 'log enable --stack ...'
207     # from working on some systems but limits the liblldb size.
208     MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace")
209     add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
210   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
211     # Don't use an explicit export. Instead, tell the linker to export all symbols.
212     MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
213     MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
214                     "Only the SB API is guaranteed to be stable.")
215     add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
216   else ()
217     MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the exports "
218             " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
219     MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
220                     "Only the SB API is guaranteed to be stable.")
221     add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
222   endif()
223 elseif (LLDB_EXPORT_ALL_SYMBOLS)
224   MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
226   # Pull out the various lldb libraries linked into liblldb, these will be used
227   # when looking for symbols to extract. We ignore most plugin libraries here,
228   # because we may expose more symbols than the DLL limit and these symbols
229   # aren't useful to expose.
230   get_target_property(all_liblldb_libs liblldb LINK_LIBRARIES)
231   set(lldb_libs "")
232   foreach(lib ${all_liblldb_libs})
233     if(TARGET ${lib} AND ${lib} MATCHES "^lldb" AND
234        (${lib} IN_LIST LLDB_EXPORT_ALL_SYMBOLS_PLUGINS OR
235         NOT ${lib} MATCHES "^lldbPlugin"))
236       get_target_property(lib_type ${lib} TYPE)
237       if("${lib_type}" STREQUAL "STATIC_LIBRARY")
238         list(APPEND lldb_libs ${lib})
239       endif()
240     endif()
241   endforeach(lib)
242   list(REMOVE_DUPLICATES lldb_libs)
244   # Extract all of the private symbols and produce a single file we can use for
245   # the exports.
246   set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/liblldb_private.symbols)
247   get_host_tool_path(llvm-nm LLVM_NM llvm_nm_exe llvm_nm_target)
248   add_custom_command(
249     OUTPUT ${exported_symbol_file}
250     COMMAND "${Python3_EXECUTABLE}"
251       ${LLDB_SOURCE_DIR}/scripts/msvc_extract_private_symbols.py
252       ${lldb_libs} -o ${exported_symbol_file} --nm=${llvm_nm_exe}
253     WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
254     DEPENDS ${LLDB_SOURCE_DIR}/scripts/msvc_extract_private_symbols.py
255       ${lldb_libs} ${llvm_nm_target}
256     VERBATIM
257     COMMENT "Generating liblldb private export list"
258   )
260   add_llvm_symbol_exports(liblldb ${exported_symbol_file})
261 endif()
263 if (NOT MSVC)
264   set_target_properties(liblldb
265     PROPERTIES
266     OUTPUT_NAME lldb
267   )
268 endif()
270 # The Clang expression parser in LLDB requires the Clang resource directory to function.
271 if (TARGET clang-resource-headers)
272   # If building alongside Clang, just add a dependency to ensure it is build together with liblldb.
273   add_dependencies(liblldb clang-resource-headers)
274 else()
275   # In a standalone build create a symlink from the LLDB library directory that points to the
276   # resource directory in the Clang library directory. LLDB searches relative to its install path,
277   # and the symlink is created in the same relative path as the resource directory of Clang when
278   # building alongside Clang.
279   # When building the LLDB framework, this isn't necessary as there we copy everything we need into
280   # the framework (including the Clang resourece directory).
281   if(NOT LLDB_BUILD_FRAMEWORK)
282     set(LLDB_CLANG_RESOURCE_DIR "$<TARGET_FILE_DIR:liblldb>/clang")
283     add_custom_command(TARGET liblldb POST_BUILD
284       COMMENT "Linking Clang resource dir into LLDB build directory: ${LLDB_CLANG_RESOURCE_DIR}"
285       COMMAND ${CMAKE_COMMAND} -E create_symlink
286       "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}" "${LLDB_CLANG_RESOURCE_DIR}"
287     )
288   endif()
289 endif()
291 if(LLDB_BUILD_FRAMEWORK)
292   include(LLDBFramework)
294   if (TARGET install-liblldb)
295     add_dependencies(install-liblldb
296       lldb-framework-cleanup)
297   endif()
299   if (TARGET install-liblldb-stripped)
300     add_dependencies(install-liblldb-stripped
301       lldb-framework-cleanup)
302   endif()
303 endif()