1if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
2  add_definitions( -DEXPORT_LIBLLDB )
3endif()
4
5# Include this so that add_lldb_library() has the list of dependencies
6# for liblldb to link against
7include(${LLDB_PROJECT_ROOT}/cmake/LLDBDependencies.cmake)
8
9option(LLDB_BUILD_FRAMEWORK "Build the Darwin LLDB.framework" Off)
10
11if(LLDB_BUILD_FRAMEWORK AND CMAKE_VERSION VERSION_LESS 3.7)
12  message(FATAL_ERROR "LLDB_BUILD_FRAMEWORK is not supported on CMake < 3.7")
13endif()
14
15if (LLDB_BUILD_FRAMEWORK AND NOT APPLE)
16  message(FATAL_ERROR "LLDB.framework cannot be generated unless targeting Apple platforms.")
17endif()
18
19add_lldb_library(liblldb SHARED
20  SBAddress.cpp
21  SBAttachInfo.cpp
22  SBBlock.cpp
23  SBBreakpoint.cpp
24  SBBreakpointLocation.cpp
25  SBBroadcaster.cpp
26  SBCommandInterpreter.cpp
27  SBCommandReturnObject.cpp
28  SBCommunication.cpp
29  SBCompileUnit.cpp
30  SBData.cpp
31  SBDebugger.cpp
32  SBDeclaration.cpp
33  SBError.cpp
34  SBEvent.cpp
35  SBExecutionContext.cpp
36  SBExpressionOptions.cpp
37  SBFileSpec.cpp
38  SBFileSpecList.cpp
39  SBFrame.cpp
40  SBFunction.cpp
41  SBHostOS.cpp
42  SBInstruction.cpp
43  SBInstructionList.cpp
44  SBLanguageRuntime.cpp
45  SBLaunchInfo.cpp
46  SBLineEntry.cpp
47  SBListener.cpp
48  SBMemoryRegionInfo.cpp
49  SBMemoryRegionInfoList.cpp
50  SBModule.cpp
51  SBModuleSpec.cpp
52  SBPlatform.cpp
53  SBProcess.cpp
54  SBQueue.cpp
55  SBQueueItem.cpp
56  SBSection.cpp
57  SBSourceManager.cpp
58  SBStream.cpp
59  SBStringList.cpp
60  SBStructuredData.cpp
61  SBSymbol.cpp
62  SBSymbolContext.cpp
63  SBSymbolContextList.cpp
64  SBTarget.cpp
65  SBThread.cpp
66  SBThreadCollection.cpp
67  SBThreadPlan.cpp
68  SBType.cpp
69  SBTypeCategory.cpp
70  SBTypeEnumMember.cpp
71  SBTypeFilter.cpp
72  SBTypeFormat.cpp
73  SBTypeNameSpecifier.cpp
74  SBTypeSummary.cpp
75  SBTypeSynthetic.cpp
76  SBValue.cpp
77  SBValueList.cpp
78  SBVariablesOptions.cpp
79  SBWatchpoint.cpp
80  SBUnixSignals.cpp
81  SystemInitializerFull.cpp
82  ${LLDB_WRAP_PYTHON}
83  )
84
85if (LLVM_ENABLE_WERROR)
86  if (MSVC)
87    set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
88  else()
89    set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
90  endif()
91endif()
92
93# This should not be part of LLDBDependencies.cmake, because we don't
94# want every single library taking a dependency on the script interpreters.
95target_link_libraries(liblldb PRIVATE
96  lldbPluginScriptInterpreterNone
97  lldbPluginScriptInterpreterPython
98  )
99
100set_target_properties(liblldb
101  PROPERTIES
102  VERSION ${LLDB_VERSION}
103  )
104
105if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
106  if (NOT LLDB_EXPORT_ALL_SYMBOLS)
107    # If we're not exporting all symbols, we'll want to explicitly set
108    # the exported symbols here.  This prevents 'log enable --stack ...'
109    # from working on some systems but limits the liblldb size.
110    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace")
111    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
112  else()
113    # Don't use an explicit export.  Instead, tell the linker to
114    # export all symbols.
115    MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
116    add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
117  endif()
118endif()
119
120if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
121  # Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs,
122  # so only it needs to explicitly link against ${PYTHON_LIBRARY}
123  if (MSVC AND NOT LLDB_DISABLE_PYTHON)
124    target_link_libraries(liblldb PRIVATE ${PYTHON_LIBRARY})
125  endif()
126else()
127  set_target_properties(liblldb
128    PROPERTIES
129    OUTPUT_NAME lldb
130    )
131endif()
132
133if (LLDB_WRAP_PYTHON)
134  add_dependencies(liblldb swig_wrapper)
135endif()
136target_link_libraries(liblldb PRIVATE ${LLDB_SYSTEM_LIBS})
137
138if(LLDB_BUILD_FRAMEWORK)
139  file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h)
140  set_target_properties(liblldb PROPERTIES
141    OUTPUT_NAME LLDB
142    FRAMEWORK On
143    FRAMEWORK_VERSION ${LLDB_FRAMEWORK_VERSION}
144    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}
145    PUBLIC_HEADER "${public_headers}")
146
147  add_custom_command(TARGET liblldb POST_BUILD
148    COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:liblldb>/Versions/${LLDB_FRAMEWORK_VERSION}
149    COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLDB_SOURCE_DIR}/include/lldb/API $<TARGET_FILE_DIR:liblldb>/Headers
150    COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Headers
151    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLDB_VERSION} $<TARGET_FILE_DIR:liblldb>/Resources/Clang
152    )
153endif()
154
155