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})
11 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
13 "In-source builds are not allowed. CMake would overwrite the makefiles "
14 "distributed with LLDB. Please create a directory and run cmake from "
15 "there, passing the path to this source directory as the last argument. "
16 "This process created the file `CMakeCache.txt' and the directory "
17 "`CMakeFiles'. Please delete them.")
20 macro(add_optional_dependency variable description package found)
21 cmake_parse_arguments(ARG
27 set(${variable} "Auto" CACHE STRING "${description} On, Off or Auto (default)")
28 string(TOUPPER "${${variable}}" ${variable})
30 if("${${variable}}" STREQUAL "AUTO")
31 set(find_package TRUE)
33 elseif(${${variable}})
34 set(find_package TRUE)
35 set(maybe_required REQUIRED)
37 set(find_package FALSE)
38 set(${variable} FALSE)
44 set(maybe_quiet QUIET)
46 find_package(${package} ${ARG_VERSION} ${maybe_required} ${maybe_quiet})
47 set(${variable} "${${found}}")
50 message(STATUS "${description}: ${${variable}}")
53 add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 4)
54 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)
55 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
56 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
57 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
58 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
59 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
60 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
62 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
63 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
64 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
65 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
66 option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)
67 option(LLDB_SKIP_DSYM "Whether to skip generating a dSYM when installing lldb." OFF)
68 option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
69 "Fail to configure if certain requirements are not met for testing." OFF)
71 set(LLDB_GLOBAL_INIT_DIRECTORY "" CACHE STRING
72 "Path to the global lldbinit directory. Relative paths are resolved relative to the
73 directory containing the LLDB library.")
75 if (LLDB_USE_SYSTEM_DEBUGSERVER)
76 # The custom target for the system debugserver has no install target, so we
77 # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list.
78 if (LLVM_DISTRIBUTION_COMPONENTS)
79 list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS debugserver)
80 set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)
84 if(LLDB_BUILD_FRAMEWORK)
86 message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")
89 set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
90 set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")
91 set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework")
93 get_filename_component(LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE
94 BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
96 # Essentially, emit the framework's dSYM outside of the framework directory.
97 set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING
98 "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")
100 # Custom target to remove the targets (binaries, directories) that were
101 # copied into LLDB.framework in the build tree.
103 # These targets need to be removed before the install phase because otherwise
104 # because otherwise they may overwrite already installed binaries with the
105 # wrong RPATH (i.e. build RPATH instead of install RPATH).
107 # This target needs to be created here (rather than in API/CMakeLists.txt)
108 # because add_lldb_tool creates the custom rules to copy the binaries before
109 # the framework target exists and that's the only place where this is
111 add_custom_target(lldb-framework-cleanup
112 COMMENT "Cleaning up build-tree frameworks in preparation for install")
115 if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)
116 if(NOT LLDB_EXPLICIT_XCODE_CACHE_USED)
118 "When building with Xcode, we recommend using the corresponding cache script. "
119 "If this was a mistake, clean your build directory and re-run CMake with:\n"
120 " -C ${CMAKE_SOURCE_DIR}/cmake/caches/Apple-lldb-Xcode.cmake\n"
121 "See: https://lldb.llvm.org/resources/build.html#cmakegeneratedxcodeproject\n")
125 set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
126 "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.")
128 set(LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE "" CACHE PATH
129 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the exports file to use when building liblldb.")
131 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
132 set(LLDB_EXPORT_ALL_SYMBOLS_PLUGINS "" CACHE STRING
133 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the plugins whose symbols should be exported.")
136 if ((NOT MSVC) OR MSVC12)
137 add_definitions( -DHAVE_ROUND )
140 # Check if we libedit capable of handling wide characters (built with
142 if (LLDB_ENABLE_LIBEDIT)
143 set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
144 set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
145 check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
146 set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)
147 check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)
148 if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")
149 set(LLDB_HAVE_EL_RFUNC_T 0)
151 set(LLDB_HAVE_EL_RFUNC_T 1)
153 set(CMAKE_REQUIRED_LIBRARIES)
154 set(CMAKE_REQUIRED_INCLUDES)
155 set(CMAKE_EXTRA_INCLUDE_FILES)
158 if (LLDB_ENABLE_PYTHON)
159 if(CMAKE_SYSTEM_NAME MATCHES "Windows")
160 set(default_embed_python_home ON)
162 set(default_embed_python_home OFF)
164 option(LLDB_EMBED_PYTHON_HOME
165 "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."
166 ${default_embed_python_home})
168 include_directories(${Python3_INCLUDE_DIRS})
169 if (LLDB_EMBED_PYTHON_HOME)
170 get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
171 set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
172 "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")
176 if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
177 include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
179 include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)
181 include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
183 # GCC silently accepts any -Wno-<foo> option, but warns about those options
184 # being unrecognized only if the compilation triggers other warnings to be
185 # printed. Therefore, check for whether the compiler supports options in the
186 # form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
188 # Disable GCC warnings
189 check_cxx_compiler_flag("-Wdeprecated-declarations" CXX_SUPPORTS_DEPRECATED_DECLARATIONS)
190 append_if(CXX_SUPPORTS_DEPRECATED_DECLARATIONS "-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
192 check_cxx_compiler_flag("-Wunknown-pragmas" CXX_SUPPORTS_UNKNOWN_PRAGMAS)
193 append_if(CXX_SUPPORTS_UNKNOWN_PRAGMAS "-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
195 check_cxx_compiler_flag("-Wstrict-aliasing" CXX_SUPPORTS_STRICT_ALIASING)
196 append_if(CXX_SUPPORTS_STRICT_ALIASING "-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
198 check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)
199 append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)
201 # Disable Clang warnings
202 check_cxx_compiler_flag("-Wdeprecated-register" CXX_SUPPORTS_DEPRECATED_REGISTER)
203 append_if(CXX_SUPPORTS_DEPRECATED_REGISTER "-Wno-deprecated-register" CMAKE_CXX_FLAGS)
205 check_cxx_compiler_flag("-Wvla-extension" CXX_SUPPORTS_VLA_EXTENSION)
206 append_if(CXX_SUPPORTS_VLA_EXTENSION "-Wno-vla-extension" CMAKE_CXX_FLAGS)
208 # Disable MSVC warnings
211 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
212 -wd4068 # Suppress 'warning C4068: unknown pragma'
213 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
214 -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union'
215 -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'
216 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
217 -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
221 # Use the Unicode (UTF-16) APIs by default on Win32
222 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
223 add_definitions( -D_UNICODE -DUNICODE )
226 # If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
227 if(NOT DEFINED LLDB_VERSION_MAJOR)
228 set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
230 if(NOT DEFINED LLDB_VERSION_MINOR)
231 set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR})
233 if(NOT DEFINED LLDB_VERSION_PATCH)
234 set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH})
236 if(NOT DEFINED LLDB_VERSION_SUFFIX)
237 set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
239 set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
240 message(STATUS "LLDB version: ${LLDB_VERSION}")
242 if (LLDB_ENABLE_LZMA)
243 include_directories(${LIBLZMA_INCLUDE_DIRS})
246 if (LLDB_ENABLE_LIBXML2)
247 include_directories(${LIBXML2_INCLUDE_DIR})
250 include_directories(BEFORE
251 ${CMAKE_CURRENT_BINARY_DIR}/include
252 ${CMAKE_CURRENT_SOURCE_DIR}/include
255 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
256 install(DIRECTORY include/
257 COMPONENT lldb-headers
258 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
261 PATTERN ".cmake" EXCLUDE
264 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
265 COMPONENT lldb-headers
266 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
269 PATTERN ".cmake" EXCLUDE
272 add_custom_target(lldb-headers)
273 set_target_properties(lldb-headers PROPERTIES FOLDER "lldb misc")
275 if (NOT CMAKE_CONFIGURATION_TYPES)
276 add_llvm_install_targets(install-lldb-headers
277 COMPONENT lldb-headers)
281 # Find Apple-specific libraries or frameworks that may be needed.
283 if(NOT APPLE_EMBEDDED)
284 find_library(CARBON_LIBRARY Carbon)
285 find_library(CORE_SERVICES_LIBRARY CoreServices)
287 find_library(FOUNDATION_LIBRARY Foundation)
288 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
289 find_library(SECURITY_LIBRARY Security)
290 include_directories(${LIBXML2_INCLUDE_DIR})
293 if( WIN32 AND NOT CYGWIN )
298 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
299 find_package(Threads REQUIRED)
302 # Figure out if lldb could use lldb-server. If so, then we'll
303 # ensure we build lldb-server when an lldb target is being built.
304 if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows")
305 set(LLDB_CAN_USE_LLDB_SERVER ON)
307 set(LLDB_CAN_USE_LLDB_SERVER OFF)
310 # Figure out if lldb could use debugserver. If so, then we'll
311 # ensure we build debugserver when we build lldb.
312 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
313 set(LLDB_CAN_USE_DEBUGSERVER ON)
315 set(LLDB_CAN_USE_DEBUGSERVER OFF)
318 if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
319 ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
320 add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)
323 include(LLDBGenerateConfig)