1 include(CheckCXXSymbolExists)
4 set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
5 set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source")
6 set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include")
8 set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10 set(LLDB_OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR})
12 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
14 "In-source builds are not allowed. CMake would overwrite the makefiles "
15 "distributed with LLDB. Please create a directory and run cmake from "
16 "there, passing the path to this source directory as the last argument. "
17 "This process created the file `CMakeCache.txt' and the directory "
18 "`CMakeFiles'. Please delete them.")
21 macro(add_optional_dependency variable description package found)
22 cmake_parse_arguments(ARG
28 set(${variable} "Auto" CACHE STRING "${description} On, Off or Auto (default)")
29 string(TOUPPER "${${variable}}" ${variable})
31 if("${${variable}}" STREQUAL "AUTO")
32 set(find_package TRUE)
34 elseif(${${variable}})
35 set(find_package TRUE)
36 set(maybe_required REQUIRED)
38 set(find_package FALSE)
39 set(${variable} FALSE)
45 set(maybe_quiet QUIET)
47 find_package(${package} ${ARG_VERSION} ${maybe_required} ${maybe_quiet})
48 set(${variable} "${${found}}")
51 message(STATUS "${description}: ${${variable}}")
54 add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 4)
55 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)
56 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
57 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
58 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
59 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
60 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
61 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
63 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
64 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
65 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
66 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
67 option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)
68 option(LLDB_SKIP_DSYM "Whether to skip generating a dSYM when installing lldb." OFF)
69 option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
70 "Fail to configure if certain requirements are not met for testing." OFF)
72 set(LLDB_GLOBAL_INIT_DIRECTORY "" CACHE STRING
73 "Path to the global lldbinit directory. Relative paths are resolved relative to the
74 directory containing the LLDB library.")
76 if (LLDB_USE_SYSTEM_DEBUGSERVER)
77 # The custom target for the system debugserver has no install target, so we
78 # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list.
79 if (LLVM_DISTRIBUTION_COMPONENTS)
80 list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS debugserver)
81 set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)
85 if(LLDB_BUILD_FRAMEWORK)
87 message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")
90 set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
91 set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")
92 set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework")
94 get_filename_component(LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE
95 BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
97 # Essentially, emit the framework's dSYM outside of the framework directory.
98 set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING
99 "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")
101 # Custom target to remove the targets (binaries, directories) that were
102 # copied into LLDB.framework in the build tree.
104 # These targets need to be removed before the install phase because otherwise
105 # because otherwise they may overwrite already installed binaries with the
106 # wrong RPATH (i.e. build RPATH instead of install RPATH).
108 # This target needs to be created here (rather than in API/CMakeLists.txt)
109 # because add_lldb_tool creates the custom rules to copy the binaries before
110 # the framework target exists and that's the only place where this is
112 add_custom_target(lldb-framework-cleanup
113 COMMENT "Cleaning up build-tree frameworks in preparation for install")
116 if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)
117 if(NOT LLDB_EXPLICIT_XCODE_CACHE_USED)
119 "When building with Xcode, we recommend using the corresponding cache script. "
120 "If this was a mistake, clean your build directory and re-run CMake with:\n"
121 " -C ${CMAKE_SOURCE_DIR}/cmake/caches/Apple-lldb-Xcode.cmake\n"
122 "See: https://lldb.llvm.org/resources/build.html#cmakegeneratedxcodeproject\n")
126 set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
127 "Causes lldb to export some private symbols when building liblldb. See lldb/source/API/liblldb-private.exports for the full list of symbols that get exported.")
129 set(LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE "" CACHE PATH
130 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the exports file to use when building liblldb.")
132 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
133 set(LLDB_EXPORT_ALL_SYMBOLS_PLUGINS "" CACHE STRING
134 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the plugins whose symbols should be exported.")
137 if ((NOT MSVC) OR MSVC12)
138 add_definitions( -DHAVE_ROUND )
141 # Check if we libedit capable of handling wide characters (built with
143 if (LLDB_ENABLE_LIBEDIT)
144 set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
145 set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
146 check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
147 set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)
148 check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)
149 if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")
150 set(LLDB_HAVE_EL_RFUNC_T 0)
152 set(LLDB_HAVE_EL_RFUNC_T 1)
154 set(CMAKE_REQUIRED_LIBRARIES)
155 set(CMAKE_REQUIRED_INCLUDES)
156 set(CMAKE_EXTRA_INCLUDE_FILES)
159 if (LLDB_ENABLE_PYTHON)
160 if(CMAKE_SYSTEM_NAME MATCHES "Windows")
161 set(default_embed_python_home ON)
163 set(default_embed_python_home OFF)
165 option(LLDB_EMBED_PYTHON_HOME
166 "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."
167 ${default_embed_python_home})
169 include_directories(${Python3_INCLUDE_DIRS})
170 if (LLDB_EMBED_PYTHON_HOME)
171 get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
172 set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
173 "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")
177 if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
178 include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
180 include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)
182 include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
184 # GCC silently accepts any -Wno-<foo> option, but warns about those options
185 # being unrecognized only if the compilation triggers other warnings to be
186 # printed. Therefore, check for whether the compiler supports options in the
187 # form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
189 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
190 # Disable GCC warnings
191 append("-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
192 append("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
194 check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)
195 append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)
198 # Disable Clang warnings
199 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
200 append("-Wno-vla-extension" CMAKE_CXX_FLAGS)
203 # Disable MSVC warnings
206 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
207 -wd4068 # Suppress 'warning C4068: unknown pragma'
208 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
209 -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union'
210 -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'
211 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
212 -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
213 -wd4589 # Suppress 'warning C4589: Constructor of abstract class 'lldb_private::NativeRegisterContextDBReg_x86' ignores initializer for virtual base class 'lldb_private::NativeRegisterContextRegisterInfo''
217 # Use the Unicode (UTF-16) APIs by default on Win32
218 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
219 add_definitions( -D_UNICODE -DUNICODE )
222 # If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
223 if(NOT DEFINED LLDB_VERSION_MAJOR)
224 set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
226 if(NOT DEFINED LLDB_VERSION_MINOR)
227 set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR})
229 if(NOT DEFINED LLDB_VERSION_PATCH)
230 set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH})
232 if(NOT DEFINED LLDB_VERSION_SUFFIX)
233 set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
235 set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
236 message(STATUS "LLDB version: ${LLDB_VERSION}")
238 if (LLDB_ENABLE_LZMA)
239 include_directories(${LIBLZMA_INCLUDE_DIRS})
242 if (LLDB_ENABLE_LIBXML2)
243 include_directories(${LIBXML2_INCLUDE_DIR})
246 include_directories(BEFORE
247 ${CMAKE_CURRENT_BINARY_DIR}/include
248 ${CMAKE_CURRENT_SOURCE_DIR}/include
251 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
252 install(DIRECTORY include/
253 COMPONENT lldb-headers
254 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
257 PATTERN ".cmake" EXCLUDE
260 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
261 COMPONENT lldb-headers
262 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
265 PATTERN ".cmake" EXCLUDE
268 add_custom_target(lldb-headers)
269 set_target_properties(lldb-headers PROPERTIES FOLDER "LLDB/Resources")
271 if (NOT CMAKE_CONFIGURATION_TYPES)
272 add_llvm_install_targets(install-lldb-headers
273 COMPONENT lldb-headers)
277 # Find Apple-specific libraries or frameworks that may be needed.
279 if(NOT APPLE_EMBEDDED)
280 find_library(CARBON_LIBRARY Carbon)
281 find_library(CORE_SERVICES_LIBRARY CoreServices)
283 find_library(FOUNDATION_LIBRARY Foundation)
284 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
285 find_library(SECURITY_LIBRARY Security)
286 include_directories(${LIBXML2_INCLUDE_DIR})
289 if( WIN32 AND NOT CYGWIN )
294 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
295 find_package(Threads REQUIRED)
298 # Figure out if lldb could use lldb-server. If so, then we'll
299 # ensure we build lldb-server when an lldb target is being built.
300 if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows")
301 set(LLDB_CAN_USE_LLDB_SERVER ON)
303 set(LLDB_CAN_USE_LLDB_SERVER OFF)
306 # Figure out if lldb could use debugserver. If so, then we'll
307 # ensure we build debugserver when we build lldb.
308 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
309 set(LLDB_CAN_USE_DEBUGSERVER ON)
311 set(LLDB_CAN_USE_DEBUGSERVER OFF)
314 if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
315 ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
316 add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)
319 include(LLDBGenerateConfig)