1if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
2  add_definitions( -DEXPORT_LIBLLDB )
3endif()
4
5get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
6
7if(LLDB_BUILD_FRAMEWORK)
8  set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
9  set(option_framework FRAMEWORK)
10endif()
11
12if(LLDB_ENABLE_PYTHON)
13  get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR)
14  set(lldb_python_wrapper ${python_bindings_dir}/LLDBWrapPython.cpp)
15endif()
16
17if(LLDB_ENABLE_LUA)
18  get_target_property(lua_bindings_dir swig_wrapper_lua BINARY_DIR)
19  set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
20endif()
21
22add_lldb_library(liblldb SHARED ${option_framework}
23  SBAddress.cpp
24  SBAttachInfo.cpp
25  SBBlock.cpp
26  SBBreakpoint.cpp
27  SBBreakpointLocation.cpp
28  SBBreakpointName.cpp
29  SBBreakpointOptionCommon.cpp
30  SBBroadcaster.cpp
31  SBCommandInterpreter.cpp
32  SBCommandInterpreterRunOptions.cpp
33  SBCommandReturnObject.cpp
34  SBCommunication.cpp
35  SBCompileUnit.cpp
36  SBData.cpp
37  SBDebugger.cpp
38  SBDeclaration.cpp
39  SBEnvironment.cpp
40  SBError.cpp
41  SBEvent.cpp
42  SBExecutionContext.cpp
43  SBExpressionOptions.cpp
44  SBFileSpec.cpp
45  SBFile.cpp
46  SBFileSpecList.cpp
47  SBFrame.cpp
48  SBFunction.cpp
49  SBHostOS.cpp
50  SBInstruction.cpp
51  SBInstructionList.cpp
52  SBLanguageRuntime.cpp
53  SBLaunchInfo.cpp
54  SBLineEntry.cpp
55  SBListener.cpp
56  SBMemoryRegionInfo.cpp
57  SBMemoryRegionInfoList.cpp
58  SBModule.cpp
59  SBModuleSpec.cpp
60  SBPlatform.cpp
61  SBProcess.cpp
62  SBProcessInfo.cpp
63  SBQueue.cpp
64  SBQueueItem.cpp
65  SBReproducer.cpp
66  SBSection.cpp
67  SBSourceManager.cpp
68  SBStream.cpp
69  SBStringList.cpp
70  SBStructuredData.cpp
71  SBSymbol.cpp
72  SBSymbolContext.cpp
73  SBSymbolContextList.cpp
74  SBTarget.cpp
75  SBThread.cpp
76  SBThreadCollection.cpp
77  SBThreadPlan.cpp
78  SBTrace.cpp
79  SBTraceOptions.cpp
80  SBType.cpp
81  SBTypeCategory.cpp
82  SBTypeEnumMember.cpp
83  SBTypeFilter.cpp
84  SBTypeFormat.cpp
85  SBTypeNameSpecifier.cpp
86  SBTypeSummary.cpp
87  SBTypeSynthetic.cpp
88  SBValue.cpp
89  SBValueList.cpp
90  SBVariablesOptions.cpp
91  SBWatchpoint.cpp
92  SBUnixSignals.cpp
93  SystemInitializerFull.cpp
94  ${lldb_python_wrapper}
95  ${lldb_lua_wrapper}
96
97  LINK_LIBS
98    lldbBase
99    lldbBreakpoint
100    lldbCore
101    lldbDataFormatters
102    lldbExpression
103    lldbHost
104    lldbInitialization
105    lldbInterpreter
106    lldbSymbol
107    lldbTarget
108    lldbUtility
109    ${LLDB_ALL_PLUGINS}
110  LINK_COMPONENTS
111    Support
112
113  ${option_install_prefix}
114)
115
116# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
117# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
118# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
119# that _lldb.so can be loaded from Python.
120if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX AND NOT APPLE)
121  set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
122endif()
123
124if(Python3_RPATH)
125  set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
126  set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH   "${Python3_RPATH}")
127endif()
128
129
130if(LLDB_ENABLE_PYTHON)
131  add_dependencies(liblldb swig_wrapper_python)
132
133  if (MSVC)
134    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
135  else()
136    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
137  endif()
138
139  set_source_files_properties(${lldb_python_wrapper} PROPERTIES GENERATED ON)
140  if (CLANG_CL)
141    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
142      PROPERTY COMPILE_FLAGS " -Wno-unused-function")
143  endif()
144  if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND
145      NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
146    set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
147      PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual")
148  endif ()
149endif()
150
151if(LLDB_ENABLE_LUA)
152  add_dependencies(liblldb swig_wrapper_lua)
153  target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR})
154
155  if (MSVC)
156    set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
157  else()
158    set_property(SOURCE ${lldb_lua_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
159  endif()
160
161  set_source_files_properties(${lldb_lua_wrapper} PROPERTIES GENERATED ON)
162endif()
163
164set_target_properties(liblldb
165  PROPERTIES
166  VERSION ${LLDB_VERSION}
167)
168
169if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
170  if (NOT LLDB_EXPORT_ALL_SYMBOLS)
171    # If we're not exporting all symbols, we'll want to explicitly set
172    # the exported symbols here.  This prevents 'log enable --stack ...'
173    # from working on some systems but limits the liblldb size.
174    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace")
175    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
176  else()
177    # Don't use an explicit export.  Instead, tell the linker to
178    # export all symbols.
179    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
180    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
181  endif()
182  set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
183endif()
184
185if (MSVC)
186  # Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs,
187  # so only it needs to explicitly link against ${Python3_LIBRARIES}
188  if (LLDB_ENABLE_PYTHON)
189    target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
190  endif()
191else()
192  set_target_properties(liblldb
193    PROPERTIES
194    OUTPUT_NAME lldb
195  )
196endif()
197
198# The Clang expression parser in LLDB requires the Clang resource directory to function.
199if (TARGET clang-resource-headers)
200  # If building alongside Clang, just add a dependency to ensure it is build together with liblldb.
201  add_dependencies(liblldb clang-resource-headers)
202else()
203  # In a standalone build create a symlink from the LLDB library directory that points to the
204  # resource directory in the Clang library directory. LLDB searches relative to its install path,
205  # and the symlink is created in the same relative path as the resource directory of Clang when
206  # building alongside Clang.
207  # When building the LLDB framework, this isn't necessary as there we copy everything we need into
208  # the framework (including the Clang resourece directory).
209  if(NOT LLDB_BUILD_FRAMEWORK)
210    set(LLDB_CLANG_RESOURCE_DIR_PARENT "$<TARGET_FILE_DIR:liblldb>/clang")
211    file(MAKE_DIRECTORY "${LLDB_CLANG_RESOURCE_DIR_PARENT}")
212    add_custom_command(TARGET liblldb POST_BUILD
213      COMMENT "Linking Clang resource dir into LLDB build directory: ${LLDB_CLANG_RESOURCE_DIR_PARENT}"
214      COMMAND ${CMAKE_COMMAND} -E make_directory "${LLDB_CLANG_RESOURCE_DIR_PARENT}"
215      COMMAND ${CMAKE_COMMAND} -E create_symlink "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}"
216              "${LLDB_CLANG_RESOURCE_DIR_PARENT}/${LLDB_CLANG_RESOURCE_DIR_NAME}"
217    )
218  endif()
219endif()
220
221if(LLDB_BUILD_FRAMEWORK)
222  include(LLDBFramework)
223endif()
224