1include(CheckCXXSymbolExists) 2 3set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) 4set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source") 5set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include") 6 7set(LLDB_LINKER_SUPPORTS_GROUPS OFF) 8if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") 9 # The Darwin linker doesn't understand --start-group/--end-group. 10 set(LLDB_LINKER_SUPPORTS_GROUPS ON) 11endif() 12 13if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) 14 set(LLDB_DEFAULT_DISABLE_PYTHON 0) 15 set(LLDB_DEFAULT_DISABLE_CURSES 1) 16elseif (CMAKE_SYSTEM_NAME MATCHES "Android" ) 17 set(LLDB_DEFAULT_DISABLE_PYTHON 1) 18 set(LLDB_DEFAULT_DISABLE_CURSES 1) 19else() 20 set(LLDB_DEFAULT_DISABLE_PYTHON 0) 21 set(LLDB_DEFAULT_DISABLE_CURSES 0) 22endif() 23 24set(LLDB_DISABLE_PYTHON ${LLDB_DEFAULT_DISABLE_PYTHON} CACHE BOOL 25 "Disables the Python scripting integration.") 26set(LLDB_DISABLE_CURSES ${LLDB_DEFAULT_DISABLE_CURSES} CACHE BOOL 27 "Disables the Curses integration.") 28 29set(LLDB_RELOCATABLE_PYTHON 0 CACHE BOOL 30 "Causes LLDB to use the PYTHONHOME environment variable to locate Python.") 31 32set(LLDB_USE_SYSTEM_SIX 0 CACHE BOOL 33 "Use six.py shipped with system and do not install a copy of it") 34 35if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") 36 set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL 37 "Causes lldb to export all symbols when building liblldb.") 38else() 39 # Windows doesn't support toggling this, so don't bother making it a 40 # cache variable. 41 set(LLDB_EXPORT_ALL_SYMBOLS 0) 42endif() 43 44if ((NOT MSVC) OR MSVC12) 45 add_definitions( -DHAVE_ROUND ) 46endif() 47 48if (LLDB_DISABLE_CURSES) 49 add_definitions( -DLLDB_DISABLE_CURSES ) 50endif() 51 52# On Windows, we can't use the normal FindPythonLibs module that comes with CMake, 53# for a number of reasons. 54# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself was 55# compiled with an identical version (and build configuration) of MSVC as LLDB. 56# The standard algorithm does not take into account the differences between 57# a binary release distribution of python and a custom built distribution. 58# 2) From MSVC 2015 and onwards, it is only possible to use Python 3.5 or later. 59# 3) FindPythonLibs queries the registry to locate Python, and when looking for a 60# 64-bit version of Python, since cmake.exe is a 32-bit executable, it will see 61# a 32-bit view of the registry. As such, it is impossible for FindPythonLibs to 62# locate 64-bit Python libraries. 63# This function is designed to address those limitations. Currently it only partially 64# addresses them, but it can be improved and extended on an as-needed basis. 65function(find_python_libs_windows) 66 if ("${PYTHON_HOME}" STREQUAL "") 67 message("LLDB embedded Python on Windows requires specifying a value for PYTHON_HOME. Python support disabled.") 68 set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) 69 return() 70 endif() 71 72 file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIRS) 73 74 if(EXISTS "${PYTHON_INCLUDE_DIRS}/patchlevel.h") 75 file(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h" python_version_str 76 REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"") 77 string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"+]+)[+]?\".*" "\\1" 78 PYTHONLIBS_VERSION_STRING "${python_version_str}") 79 message("-- Found Python version ${PYTHONLIBS_VERSION_STRING}") 80 string(REGEX REPLACE "([0-9]+)[.]([0-9]+)[.][0-9]+" "python\\1\\2" PYTHONLIBS_BASE_NAME "${PYTHONLIBS_VERSION_STRING}") 81 unset(python_version_str) 82 else() 83 message("Unable to find ${PYTHON_INCLUDE_DIRS}/patchlevel.h, Python installation is corrupt.") 84 message("Python support will be disabled for this build.") 85 set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) 86 return() 87 endif() 88 89 file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME) 90 file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE) 91 file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}_d.lib" PYTHON_DEBUG_LIB) 92 file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}_d.dll" PYTHON_DEBUG_DLL) 93 94 file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE) 95 file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}.lib" PYTHON_RELEASE_LIB) 96 file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}.dll" PYTHON_RELEASE_DLL) 97 98 if (NOT EXISTS ${PYTHON_DEBUG_EXE}) 99 message("Unable to find ${PYTHON_DEBUG_EXE}") 100 unset(PYTHON_DEBUG_EXE) 101 endif() 102 103 if (NOT EXISTS ${PYTHON_RELEASE_EXE}) 104 message("Unable to find ${PYTHON_RELEASE_EXE}") 105 unset(PYTHON_RELEASE_EXE) 106 endif() 107 108 if (NOT EXISTS ${PYTHON_DEBUG_LIB}) 109 message("Unable to find ${PYTHON_DEBUG_LIB}") 110 unset(PYTHON_DEBUG_LIB) 111 endif() 112 113 if (NOT EXISTS ${PYTHON_RELEASE_LIB}) 114 message("Unable to find ${PYTHON_RELEASE_LIB}") 115 unset(PYTHON_RELEASE_LIB) 116 endif() 117 118 if (NOT EXISTS ${PYTHON_DEBUG_DLL}) 119 message("Unable to find ${PYTHON_DEBUG_DLL}") 120 unset(PYTHON_DEBUG_DLL) 121 endif() 122 123 if (NOT EXISTS ${PYTHON_RELEASE_DLL}) 124 message("Unable to find ${PYTHON_RELEASE_DLL}") 125 unset(PYTHON_RELEASE_DLL) 126 endif() 127 128 if (NOT (PYTHON_DEBUG_EXE AND PYTHON_RELEASE_EXE AND PYTHON_DEBUG_LIB AND PYTHON_RELEASE_LIB AND PYTHON_DEBUG_DLL AND PYTHON_RELEASE_DLL)) 129 message("Python installation is corrupt. Python support will be disabled for this build.") 130 set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE) 131 return() 132 endif() 133 134 # Generator expressions are evaluated in the context of each build configuration generated 135 # by CMake. Here we use the $<CONFIG:Debug>:VALUE logical generator expression to ensure 136 # that the debug Python library, DLL, and executable are used in the Debug build configuration. 137 # 138 # Generator expressions can be difficult to grok at first so here's a breakdown of the one 139 # used for PYTHON_LIBRARY: 140 # 141 # 1. $<CONFIG:Debug> evaluates to 1 when the Debug configuration is being generated, 142 # or 0 in all other cases. 143 # 2. $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug 144 # configuration is being generated, or nothing (literally) in all other cases. 145 # 3. $<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when 146 # any configuration other than Debug is being generated, or nothing in all other cases. 147 # 4. The conditionals in 2 & 3 are mutually exclusive. 148 # 5. A logical expression with a conditional that evaluates to 0 yields no value at all. 149 # 150 # Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each 151 # build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the 152 # Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration. 153 # Note that it's imperative that there is no whitespace between the two expressions, otherwise 154 # CMake will insert a semicolon between the two. 155 set (PYTHON_EXECUTABLE $<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>) 156 set (PYTHON_LIBRARY $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}>) 157 set (PYTHON_DLL $<$<CONFIG:Debug>:${PYTHON_DEBUG_DLL}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_DLL}>) 158 159 set (PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE) 160 set (PYTHON_LIBRARY ${PYTHON_LIBRARY} PARENT_SCOPE) 161 set (PYTHON_DLL ${PYTHON_DLL} PARENT_SCOPE) 162 set (PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} PARENT_SCOPE) 163 164 message("-- LLDB Found PythonExecutable: ${PYTHON_RELEASE_EXE} and ${PYTHON_DEBUG_EXE}") 165 message("-- LLDB Found PythonLibs: ${PYTHON_RELEASE_LIB} and ${PYTHON_DEBUG_LIB}") 166 message("-- LLDB Found PythonDLL: ${PYTHON_RELEASE_DLL} and ${PYTHON_DEBUG_DLL}") 167 message("-- LLDB Found PythonIncludeDirs: ${PYTHON_INCLUDE_DIRS}") 168endfunction(find_python_libs_windows) 169 170if (NOT LLDB_DISABLE_PYTHON) 171 172 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") 173 find_python_libs_windows() 174 175 if (NOT LLDB_RELOCATABLE_PYTHON) 176 file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME) 177 add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" ) 178 endif() 179 else() 180 find_package(PythonLibs REQUIRED) 181 endif() 182 183 if (PYTHON_INCLUDE_DIRS) 184 include_directories(${PYTHON_INCLUDE_DIRS}) 185 endif() 186endif() 187 188if (LLDB_DISABLE_PYTHON) 189 unset(PYTHON_INCLUDE_DIRS) 190 unset(PYTHON_LIBRARY) 191 add_definitions( -DLLDB_DISABLE_PYTHON ) 192endif() 193 194if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) 195 include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include) 196else () 197 include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include) 198endif () 199include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include") 200 201# Disable GCC warnings 202check_cxx_compiler_flag("-Wno-deprecated-declarations" 203 CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS) 204if (CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS) 205 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") 206endif () 207 208check_cxx_compiler_flag("-Wno-unknown-pragmas" 209 CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS) 210if (CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS) 211 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") 212endif () 213 214check_cxx_compiler_flag("-Wno-strict-aliasing" 215 CXX_SUPPORTS_NO_STRICT_ALIASING) 216if (CXX_SUPPORTS_NO_STRICT_ALIASING) 217 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing") 218endif () 219 220# Disable Clang warnings 221check_cxx_compiler_flag("-Wno-deprecated-register" 222 CXX_SUPPORTS_NO_DEPRECATED_REGISTER) 223if (CXX_SUPPORTS_NO_DEPRECATED_REGISTER) 224 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register") 225endif () 226 227check_cxx_compiler_flag("-Wno-vla-extension" 228 CXX_SUPPORTS_NO_VLA_EXTENSION) 229if (CXX_SUPPORTS_NO_VLA_EXTENSION) 230 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla-extension") 231endif () 232 233# Disable MSVC warnings 234if( MSVC ) 235 add_definitions( 236 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch' 237 -wd4068 # Suppress 'warning C4068: unknown pragma' 238 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type' 239 -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.' 240 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified' 241 -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' 242 ) 243endif() 244 245# Use the Unicode (UTF-16) APIs by default on Win32 246if (CMAKE_SYSTEM_NAME MATCHES "Windows") 247 add_definitions( -D_UNICODE -DUNICODE ) 248endif() 249 250set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 251set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 252 253if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) 254 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " 255"the makefiles distributed with LLDB. Please create a directory and run cmake " 256"from there, passing the path to this source directory as the last argument. " 257"This process created the file `CMakeCache.txt' and the directory " 258"`CMakeFiles'. Please delete them.") 259endif() 260 261# Compute the LLDB version from the LLVM version. 262string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLDB_VERSION 263 ${PACKAGE_VERSION}) 264message(STATUS "LLDB version: ${LLDB_VERSION}") 265 266include_directories(BEFORE 267 ${CMAKE_CURRENT_SOURCE_DIR}/include 268 ${CMAKE_CURRENT_BINARY_DIR}/include 269 ) 270 271if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 272 install(DIRECTORY include/ 273 COMPONENT lldb_headers 274 DESTINATION include 275 FILES_MATCHING 276 PATTERN "*.h" 277 PATTERN ".svn" EXCLUDE 278 PATTERN ".cmake" EXCLUDE 279 PATTERN "Config.h" EXCLUDE 280 ) 281 282 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ 283 COMPONENT lldb_headers 284 DESTINATION include 285 FILES_MATCHING 286 PATTERN "*.h" 287 PATTERN ".svn" EXCLUDE 288 PATTERN ".cmake" EXCLUDE 289 ) 290endif() 291 292if (NOT LIBXML2_FOUND AND NOT (CMAKE_SYSTEM_NAME MATCHES "Windows")) 293 # Skip Libxml2 on Windows. In CMake 3.4 and higher, the algorithm for 294 # finding libxml2 got "smarter", and it can now locate the version which is 295 # in gnuwin32, even though that version does not contain the headers that 296 # LLDB uses. 297 find_package(LibXml2) 298endif() 299 300# Find libraries or frameworks that may be needed 301if (CMAKE_SYSTEM_NAME MATCHES "Darwin") 302 find_library(CARBON_LIBRARY Carbon) 303 find_library(FOUNDATION_LIBRARY Foundation) 304 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) 305 find_library(CORE_SERVICES_LIBRARY CoreServices) 306 find_library(SECURITY_LIBRARY Security) 307 find_library(DEBUG_SYMBOLS_LIBRARY DebugSymbols PATHS "/System/Library/PrivateFrameworks") 308 309 set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Output directory for LLDB.framework") 310 set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)") 311 set(LLDB_FRAMEWORK_RESOURCE_DIR 312 LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources) 313 314 add_definitions( -DLIBXML2_DEFINED ) 315 list(APPEND system_libs xml2 ${CURSES_LIBRARIES}) 316 list(APPEND system_libs ${CARBON_LIBRARY} ${FOUNDATION_LIBRARY} 317 ${CORE_FOUNDATION_LIBRARY} ${CORE_SERVICES_LIBRARY} ${SECURITY_LIBRARY} 318 ${DEBUG_SYMBOLS_LIBRARY}) 319 320else() 321 if (LIBXML2_FOUND) 322 add_definitions( -DLIBXML2_DEFINED ) 323 list(APPEND system_libs ${LIBXML2_LIBRARIES}) 324 include_directories(${LIBXML2_INCLUDE_DIR}) 325 endif() 326 327endif() 328 329if (HAVE_LIBPTHREAD) 330 list(APPEND system_libs pthread) 331endif(HAVE_LIBPTHREAD) 332 333if (HAVE_LIBDL) 334 list(APPEND system_libs ${CMAKE_DL_LIBS}) 335endif() 336 337# Figure out if lldb could use lldb-server. If so, then we'll 338# ensure we build lldb-server when an lldb target is being built. 339if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD") 340 set(LLDB_CAN_USE_LLDB_SERVER 1) 341else() 342 set(LLDB_CAN_USE_LLDB_SERVER 0) 343endif() 344 345# Figure out if lldb could use debugserver. If so, then we'll 346# ensure we build debugserver when we build lldb. 347if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) 348 set(LLDB_CAN_USE_DEBUGSERVER 1) 349else() 350 set(LLDB_CAN_USE_DEBUGSERVER 0) 351endif() 352 353if (NOT LLDB_DISABLE_CURSES) 354 find_package(Curses REQUIRED) 355 356 find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library") 357 if (NOT CURSES_PANEL_LIBRARY) 358 message(FATAL_ERROR "A required curses' panel library not found.") 359 endif () 360 361 # Add panels to the library path 362 set (CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_PANEL_LIBRARY}) 363 364 list(APPEND system_libs ${CURSES_LIBRARIES}) 365 include_directories(${CURSES_INCLUDE_DIR}) 366endif () 367 368check_cxx_symbol_exists("__GLIBCXX__" "string" LLDB_USING_LIBSTDCXX) 369if(LLDB_USING_LIBSTDCXX) 370 # There doesn't seem to be an easy way to check the library version. Instead, we rely on the 371 # fact that std::set did not have the allocator constructor available until version 4.9 372 check_cxx_source_compiles(" 373 #include <set> 374 std::set<int> s = std::set<int>(std::allocator<int>()); 375 int main() { return 0; }" 376 LLDB_USING_LIBSTDCXX_4_9) 377 if (NOT LLDB_USING_LIBSTDCXX_4_9 AND NOT LLVM_ENABLE_EH) 378 message(WARNING 379 "You appear to be linking to libstdc++ version lesser than 4.9 without exceptions " 380 "enabled. These versions of the library have an issue, which causes occasional " 381 "lldb crashes. See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59656> for " 382 "details. Possible courses of action are:\n" 383 "- use libstdc++ version 4.9 or newer\n" 384 "- use libc++ (via LLVM_ENABLE_LIBCXX)\n" 385 "- enable exceptions (via LLVM_ENABLE_EH)\n" 386 "- ignore this warning and accept occasional instability") 387 endif() 388endif() 389 390if(MSVC) 391 set(LLDB_USE_BUILTIN_DEMANGLER ON) 392else() 393 option(LLDB_USE_BUILTIN_DEMANGLER "Use lldb's builtin demangler instead of the system one" ON) 394endif() 395if(LLDB_USE_BUILTIN_DEMANGLER) 396 add_definitions(-DLLDB_USE_BUILTIN_DEMANGLER) 397endif() 398 399if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND 400 ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips"))) 401 add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND) 402endif() 403 404find_package(Backtrace) 405include(LLDBGenerateConfig) 406