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