1include(CheckCXXSymbolExists) 2include(CheckTypeSize) 3 4set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) 5set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source") 6set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include") 7 8set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 9set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 10 11if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) 12 message(FATAL_ERROR 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.") 18endif() 19 20set(LLDB_LINKER_SUPPORTS_GROUPS OFF) 21if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") 22 # The Darwin linker doesn't understand --start-group/--end-group. 23 set(LLDB_LINKER_SUPPORTS_GROUPS ON) 24endif() 25 26macro(add_optional_dependency variable description package found) 27 cmake_parse_arguments(ARG 28 "" 29 "VERSION" 30 "" 31 ${ARGN}) 32 33 set(${variable} "Auto" CACHE STRING "${description} On, Off or Auto (default)") 34 string(TOUPPER "${${variable}}" ${variable}) 35 36 if("${${variable}}" STREQUAL "AUTO") 37 set(find_package TRUE) 38 set(maybe_required) 39 elseif(${${variable}}) 40 set(find_package TRUE) 41 set(maybe_required REQUIRED) 42 else() 43 set(find_package FALSE) 44 set(${variable} FALSE) 45 endif() 46 47 if(${find_package}) 48 find_package(${package} ${ARG_VERSION} ${maybe_required}) 49 set(${variable} "${${found}}") 50 endif() 51 52 message(STATUS "${description}: ${${variable}}") 53endmacro() 54 55add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND) 56add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND) 57add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND) 58add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND) 59add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND) 60add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8) 61 62option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF) 63option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON) 64option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF) 65option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF) 66option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF) 67option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF) 68 69if (LLDB_USE_SYSTEM_DEBUGSERVER) 70 # The custom target for the system debugserver has no install target, so we 71 # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list. 72 if (LLVM_DISTRIBUTION_COMPONENTS) 73 list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS debugserver) 74 set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE) 75 endif() 76endif() 77 78if(LLDB_BUILD_FRAMEWORK) 79 if(NOT APPLE) 80 message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms") 81 endif() 82 83 set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)") 84 set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework") 85 set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework") 86 87 get_filename_component(LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE 88 BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}) 89 90 # Essentially, emit the framework's dSYM outside of the framework directory. 91 set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING 92 "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)") 93endif() 94 95if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode) 96 if(NOT LLDB_EXPLICIT_XCODE_CACHE_USED) 97 message(WARNING 98 "When building with Xcode, we recommend using the corresponding cache script. " 99 "If this was a mistake, clean your build directory and re-run CMake with:\n" 100 " -C ${CMAKE_SOURCE_DIR}/cmake/caches/Apple-lldb-Xcode.cmake\n" 101 "See: https://lldb.llvm.org/resources/build.html#cmakegeneratedxcodeproject\n") 102 endif() 103endif() 104 105if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") 106 set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL 107 "Causes lldb to export all symbols when building liblldb.") 108else() 109 # Windows doesn't support toggling this, so don't bother making it a 110 # cache variable. 111 set(LLDB_EXPORT_ALL_SYMBOLS 0) 112endif() 113 114if ((NOT MSVC) OR MSVC12) 115 add_definitions( -DHAVE_ROUND ) 116endif() 117 118# Check if we libedit capable of handling wide characters (built with 119# '--enable-widec'). 120if (LLDB_ENABLE_LIBEDIT) 121 set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES}) 122 set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS}) 123 check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR) 124 set(CMAKE_EXTRA_INCLUDE_FILES histedit.h) 125 check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE) 126 if (LLDB_EL_RFUNC_T_SIZE STREQUAL "") 127 set(LLDB_HAVE_EL_RFUNC_T 0) 128 else() 129 set(LLDB_HAVE_EL_RFUNC_T 1) 130 endif() 131 set(CMAKE_REQUIRED_LIBRARIES) 132 set(CMAKE_REQUIRED_INCLUDES) 133 set(CMAKE_EXTRA_INCLUDE_FILES) 134endif() 135 136if (LLDB_ENABLE_PYTHON) 137 if(CMAKE_SYSTEM_NAME MATCHES "Windows") 138 set(default_embed_python_home ON) 139 else() 140 set(default_embed_python_home OFF) 141 endif() 142 option(LLDB_EMBED_PYTHON_HOME 143 "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python." 144 ${default_embed_python_home}) 145 146 include_directories(${Python3_INCLUDE_DIRS}) 147 if (LLDB_EMBED_PYTHON_HOME) 148 get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY) 149 set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING 150 "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.") 151 endif() 152endif() 153 154if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) 155 include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include) 156else () 157 include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include) 158endif () 159include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include") 160 161# Disable GCC warnings 162check_cxx_compiler_flag("-Wno-deprecated-declarations" CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS) 163append_if(CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS "-Wno-deprecated-declarations" CMAKE_CXX_FLAGS) 164 165check_cxx_compiler_flag("-Wno-unknown-pragmas" CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS) 166append_if(CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS "-Wno-unknown-pragmas" CMAKE_CXX_FLAGS) 167 168check_cxx_compiler_flag("-Wno-strict-aliasing" CXX_SUPPORTS_NO_STRICT_ALIASING) 169append_if(CXX_SUPPORTS_NO_STRICT_ALIASING "-Wno-strict-aliasing" CMAKE_CXX_FLAGS) 170 171# Disable Clang warnings 172check_cxx_compiler_flag("-Wno-deprecated-register" CXX_SUPPORTS_NO_DEPRECATED_REGISTER) 173append_if(CXX_SUPPORTS_NO_DEPRECATED_REGISTER "-Wno-deprecated-register" CMAKE_CXX_FLAGS) 174 175check_cxx_compiler_flag("-Wno-vla-extension" CXX_SUPPORTS_NO_VLA_EXTENSION) 176append_if(CXX_SUPPORTS_NO_VLA_EXTENSION "-Wno-vla-extension" CMAKE_CXX_FLAGS) 177 178# Disable MSVC warnings 179if( MSVC ) 180 add_definitions( 181 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch' 182 -wd4068 # Suppress 'warning C4068: unknown pragma' 183 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type' 184 -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union' 185 -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.' 186 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified' 187 -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' 188 ) 189endif() 190 191# Use the Unicode (UTF-16) APIs by default on Win32 192if (CMAKE_SYSTEM_NAME MATCHES "Windows") 193 add_definitions( -D_UNICODE -DUNICODE ) 194endif() 195 196# If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*. 197if(NOT DEFINED LLDB_VERSION_MAJOR) 198 set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) 199endif() 200if(NOT DEFINED LLDB_VERSION_MINOR) 201 set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR}) 202endif() 203if(NOT DEFINED LLDB_VERSION_PATCH) 204 set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH}) 205endif() 206if(NOT DEFINED LLDB_VERSION_SUFFIX) 207 set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX}) 208endif() 209set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}") 210message(STATUS "LLDB version: ${LLDB_VERSION}") 211 212if (LLDB_ENABLE_LZMA) 213 include_directories(${LIBLZMA_INCLUDE_DIRS}) 214endif() 215 216if (LLDB_ENABLE_LIBXML2) 217 include_directories(${LIBXML2_INCLUDE_DIR}) 218endif() 219 220include_directories(BEFORE 221 ${CMAKE_CURRENT_BINARY_DIR}/include 222 ${CMAKE_CURRENT_SOURCE_DIR}/include 223 ) 224 225if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 226 install(DIRECTORY include/ 227 COMPONENT lldb-headers 228 DESTINATION include 229 FILES_MATCHING 230 PATTERN "*.h" 231 PATTERN ".cmake" EXCLUDE 232 ) 233 234 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ 235 COMPONENT lldb-headers 236 DESTINATION include 237 FILES_MATCHING 238 PATTERN "*.h" 239 PATTERN ".cmake" EXCLUDE 240 ) 241 242 add_custom_target(lldb-headers) 243 set_target_properties(lldb-headers PROPERTIES FOLDER "lldb misc") 244 245 if (NOT CMAKE_CONFIGURATION_TYPES) 246 add_llvm_install_targets(install-lldb-headers 247 COMPONENT lldb-headers) 248 endif() 249endif() 250 251 252# If LLDB is building against a prebuilt Clang, then the Clang resource 253# directory that LLDB is using for its embedded Clang instance needs to point 254# to the resource directory of the used Clang installation. 255if (NOT TARGET clang-resource-headers) 256 set(LLDB_CLANG_RESOURCE_DIR_NAME "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") 257 # Iterate over the possible places where the external resource directory 258 # could be and pick the first that exists. 259 foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" 260 "${LLVM_BUILD_LIBRARY_DIR}" 261 "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") 262 # Build the resource directory path by appending 'clang/<version number>'. 263 set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") 264 if (IS_DIRECTORY "${CANDIDATE_RESOURCE_DIR}") 265 set(LLDB_EXTERNAL_CLANG_RESOURCE_DIR "${CANDIDATE_RESOURCE_DIR}") 266 break() 267 endif() 268 endforeach() 269 270 if (NOT LLDB_EXTERNAL_CLANG_RESOURCE_DIR) 271 message(FATAL_ERROR "Expected directory for clang-resource headers not found: ${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}") 272 endif() 273endif() 274 275# Find Apple-specific libraries or frameworks that may be needed. 276if (APPLE) 277 if(NOT APPLE_EMBEDDED) 278 find_library(CARBON_LIBRARY Carbon) 279 find_library(CORE_SERVICES_LIBRARY CoreServices) 280 endif() 281 find_library(FOUNDATION_LIBRARY Foundation) 282 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) 283 find_library(SECURITY_LIBRARY Security) 284 include_directories(${LIBXML2_INCLUDE_DIR}) 285endif() 286 287if( WIN32 AND NOT CYGWIN ) 288 set(PURE_WINDOWS 1) 289endif() 290 291if(NOT PURE_WINDOWS) 292 set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 293 find_package(Threads REQUIRED) 294endif() 295 296# Figure out if lldb could use lldb-server. If so, then we'll 297# ensure we build lldb-server when an lldb target is being built. 298if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows") 299 set(LLDB_CAN_USE_LLDB_SERVER ON) 300else() 301 set(LLDB_CAN_USE_LLDB_SERVER OFF) 302endif() 303 304# Figure out if lldb could use debugserver. If so, then we'll 305# ensure we build debugserver when we build lldb. 306if (CMAKE_SYSTEM_NAME MATCHES "Darwin") 307 set(LLDB_CAN_USE_DEBUGSERVER ON) 308else() 309 set(LLDB_CAN_USE_DEBUGSERVER OFF) 310endif() 311 312if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND 313 ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips"))) 314 add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND) 315endif() 316 317include(LLDBGenerateConfig) 318