summaryrefslogtreecommitdiff
path: root/cmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules')
-rw-r--r--cmake/modules/AddLLDB.cmake114
-rw-r--r--cmake/modules/LLDBConfig.cmake412
-rw-r--r--cmake/modules/LLDBStandalone.cmake99
3 files changed, 625 insertions, 0 deletions
diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake
new file mode 100644
index 000000000000..672b0a53feaf
--- /dev/null
+++ b/cmake/modules/AddLLDB.cmake
@@ -0,0 +1,114 @@
+function(lldb_link_common_libs name targetkind)
+ if (NOT LLDB_USED_LIBS)
+ return()
+ endif()
+
+ if(${targetkind} MATCHES "SHARED")
+ set(LINK_KEYWORD ${cmake_2_8_12_PUBLIC})
+ endif()
+
+ if(${targetkind} MATCHES "SHARED" OR ${targetkind} MATCHES "EXE")
+ if (LLDB_LINKER_SUPPORTS_GROUPS)
+ target_link_libraries(${name} ${LINK_KEYWORD}
+ -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
+ else()
+ target_link_libraries(${name} ${LINK_KEYWORD} ${LLDB_USED_LIBS})
+ endif()
+ endif()
+endfunction(lldb_link_common_libs)
+
+macro(add_lldb_library name)
+ # only supported parameters to this macro are the optional
+ # MODULE;SHARED;STATIC library type and source files
+ cmake_parse_arguments(PARAM
+ "MODULE;SHARED;STATIC;OBJECT"
+ ""
+ ""
+ ${ARGN})
+ llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS})
+
+ if (MSVC_IDE OR XCODE)
+ string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
+ list(GET split_path -1 dir)
+ file(GLOB_RECURSE headers
+ ../../include/lldb${dir}/*.h)
+ set(srcs ${srcs} ${headers})
+ endif()
+ if (PARAM_MODULE)
+ set(libkind MODULE)
+ elseif (PARAM_SHARED)
+ set(libkind SHARED)
+ elseif (PARAM_OBJECT)
+ set(libkind OBJECT)
+ else ()
+ # PARAM_STATIC or library type unspecified. BUILD_SHARED_LIBS
+ # does not control the kind of libraries created for LLDB,
+ # only whether or not they link to shared/static LLVM/Clang
+ # libraries.
+ set(libkind STATIC)
+ endif()
+
+ #PIC not needed on Win
+ if (NOT MSVC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+ endif()
+
+ if (PARAM_OBJECT)
+ add_library(${name} ${libkind} ${srcs})
+ else()
+ llvm_add_library(${name} ${libkind} ${srcs})
+
+ lldb_link_common_libs(${name} "${libkind}")
+
+ if (PARAM_SHARED)
+ if (LLDB_LINKER_SUPPORTS_GROUPS)
+ target_link_libraries(${name} ${cmake_2_8_12_PUBLIC}
+ -Wl,--start-group ${CLANG_USED_LIBS} -Wl,--end-group)
+ else()
+ target_link_libraries(${name} ${cmake_2_8_12_PUBLIC} ${CLANG_USED_LIBS})
+ endif()
+ endif()
+ llvm_config(${name} ${LLVM_LINK_COMPONENTS})
+
+ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb")
+ if (PARAM_SHARED)
+ install(TARGETS ${name}
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ else()
+ install(TARGETS ${name}
+ LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ endif()
+ endif()
+ endif()
+
+ # Hack: only some LLDB libraries depend on the clang autogenerated headers,
+ # but it is simple enough to make all of LLDB depend on some of those
+ # headers without negatively impacting much of anything.
+ add_dependencies(${name} libclang)
+
+ set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
+endmacro(add_lldb_library)
+
+macro(add_lldb_executable name)
+ add_llvm_executable(${name} ${ARGN})
+ set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
+endmacro(add_lldb_executable)
+
+# Support appending linker flags to an existing target.
+# This will preserve the existing linker flags on the
+# target, if there are any.
+function(lldb_append_link_flags target_name new_link_flags)
+ # Retrieve existing linker flags.
+ get_target_property(current_link_flags ${target_name} LINK_FLAGS)
+
+ # If we had any linker flags, include them first in the new linker flags.
+ if(current_link_flags)
+ set(new_link_flags "${current_link_flags} ${new_link_flags}")
+ endif()
+
+ # Now set them onto the target.
+ set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags})
+endfunction()
diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake
new file mode 100644
index 000000000000..f5247a269822
--- /dev/null
+++ b/cmake/modules/LLDBConfig.cmake
@@ -0,0 +1,412 @@
+set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
+set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source")
+set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include")
+
+set(LLDB_LINKER_SUPPORTS_GROUPS OFF)
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
+ # The Darwin linker doesn't understand --start-group/--end-group.
+ set(LLDB_LINKER_SUPPORTS_GROUPS ON)
+endif()
+
+if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+ set(LLDB_DEFAULT_DISABLE_PYTHON 0)
+ set(LLDB_DEFAULT_DISABLE_CURSES 1)
+else()
+ if ( __ANDROID_NDK__ )
+ set(LLDB_DEFAULT_DISABLE_PYTHON 1)
+ set(LLDB_DEFAULT_DISABLE_CURSES 1)
+ else()
+ set(LLDB_DEFAULT_DISABLE_PYTHON 0)
+ set(LLDB_DEFAULT_DISABLE_CURSES 0)
+ endif()
+endif()
+
+set(LLDB_DISABLE_PYTHON ${LLDB_DEFAULT_DISABLE_PYTHON} CACHE BOOL
+ "Disables the Python scripting integration.")
+set(LLDB_DISABLE_CURSES ${LLDB_DEFAULT_DISABLE_CURSES} CACHE BOOL
+ "Disables the Curses integration.")
+
+set(LLDB_RELOCATABLE_PYTHON 0 CACHE BOOL
+ "Causes LLDB to use the PYTHONHOME environment variable to locate Python.")
+
+if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
+ "Causes lldb to export all symbols when building liblldb.")
+else()
+ # Windows doesn't support toggling this, so don't bother making it a
+ # cache variable.
+ set(LLDB_EXPORT_ALL_SYMBOLS 0)
+endif()
+
+if ((NOT MSVC) OR MSVC12)
+ add_definitions( -DHAVE_ROUND )
+endif()
+
+if (LLDB_DISABLE_CURSES)
+ add_definitions( -DLLDB_DISABLE_CURSES )
+endif()
+
+# On Windows, we can't use the normal FindPythonLibs module that comes with CMake,
+# for a number of reasons.
+# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself was
+# compiled with an identical version (and build configuration) of MSVC as LLDB.
+# The standard algorithm does not take into account the differences between
+# a binary release distribution of python and a custom built distribution.
+# 2) From MSVC 2015 and onwards, it is only possible to use Python 3.5 or later.
+# 3) FindPythonLibs queries the registry to locate Python, and when looking for a
+# 64-bit version of Python, since cmake.exe is a 32-bit executable, it will see
+# a 32-bit view of the registry. As such, it is impossible for FindPythonLibs to
+# locate 64-bit Python libraries.
+# This function is designed to address those limitations. Currently it only partially
+# addresses them, but it can be improved and extended on an as-needed basis.
+function(find_python_libs_windows)
+ if ("${PYTHON_HOME}" STREQUAL "")
+ message("LLDB embedded Python on Windows requires specifying a value for PYTHON_HOME. Python support disabled.")
+ set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE)
+ return()
+ endif()
+
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIRS)
+
+ if(EXISTS "${PYTHON_INCLUDE_DIRS}/patchlevel.h")
+ file(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h" python_version_str
+ REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
+ string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"+]+)[+]?\".*" "\\1"
+ PYTHONLIBS_VERSION_STRING "${python_version_str}")
+ message("-- Found Python version ${PYTHONLIBS_VERSION_STRING}")
+ string(REGEX REPLACE "([0-9]+)[.]([0-9]+)[.][0-9]+" "python\\1\\2" PYTHONLIBS_BASE_NAME "${PYTHONLIBS_VERSION_STRING}")
+ unset(python_version_str)
+ else()
+ message("Unable to find ${PYTHON_INCLUDE_DIRS}/patchlevel.h, Python installation is corrupt.")
+ message("Python support will be disabled for this build.")
+ set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE)
+ return()
+ endif()
+
+ file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}_d.lib" PYTHON_DEBUG_LIB)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}_d.dll" PYTHON_DEBUG_DLL)
+
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}.lib" PYTHON_RELEASE_LIB)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}.dll" PYTHON_RELEASE_DLL)
+
+ if (NOT EXISTS ${PYTHON_DEBUG_EXE})
+ message("Unable to find ${PYTHON_DEBUG_EXE}")
+ unset(PYTHON_DEBUG_EXE)
+ endif()
+
+ if (NOT EXISTS ${PYTHON_RELEASE_EXE})
+ message("Unable to find ${PYTHON_RELEASE_EXE}")
+ unset(PYTHON_RELEASE_EXE)
+ endif()
+
+ if (NOT EXISTS ${PYTHON_DEBUG_LIB})
+ message("Unable to find ${PYTHON_DEBUG_LIB}")
+ unset(PYTHON_DEBUG_LIB)
+ endif()
+
+ if (NOT EXISTS ${PYTHON_RELEASE_LIB})
+ message("Unable to find ${PYTHON_RELEASE_LIB}")
+ unset(PYTHON_RELEASE_LIB)
+ endif()
+
+ if (NOT EXISTS ${PYTHON_DEBUG_DLL})
+ message("Unable to find ${PYTHON_DEBUG_DLL}")
+ unset(PYTHON_DEBUG_DLL)
+ endif()
+
+ if (NOT EXISTS ${PYTHON_RELEASE_DLL})
+ message("Unable to find ${PYTHON_RELEASE_DLL}")
+ unset(PYTHON_RELEASE_DLL)
+ endif()
+
+ 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))
+ message("Python installation is corrupt. Python support will be disabled for this build.")
+ set(LLDB_DISABLE_PYTHON 1 PARENT_SCOPE)
+ return()
+ endif()
+
+ # Generator expressions are evaluated in the context of each build configuration generated
+ # by CMake. Here we use the $<CONFIG:Debug>:VALUE logical generator expression to ensure
+ # that the debug Python library, DLL, and executable are used in the Debug build configuration.
+ #
+ # Generator expressions can be difficult to grok at first so here's a breakdown of the one
+ # used for PYTHON_LIBRARY:
+ #
+ # 1. $<CONFIG:Debug> evaluates to 1 when the Debug configuration is being generated,
+ # or 0 in all other cases.
+ # 2. $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug
+ # configuration is being generated, or nothing (literally) in all other cases.
+ # 3. $<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when
+ # any configuration other than Debug is being generated, or nothing in all other cases.
+ # 4. The conditionals in 2 & 3 are mutually exclusive.
+ # 5. A logical expression with a conditional that evaluates to 0 yields no value at all.
+ #
+ # Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each
+ # build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the
+ # Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration.
+ # Note that it's imperative that there is no whitespace between the two expressions, otherwise
+ # CMake will insert a semicolon between the two.
+ set (PYTHON_EXECUTABLE $<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>)
+ set (PYTHON_LIBRARY $<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}>)
+ set (PYTHON_DLL $<$<CONFIG:Debug>:${PYTHON_DEBUG_DLL}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_DLL}>)
+
+ set (PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE)
+ set (PYTHON_LIBRARY ${PYTHON_LIBRARY} PARENT_SCOPE)
+ set (PYTHON_DLL ${PYTHON_DLL} PARENT_SCOPE)
+ set (PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} PARENT_SCOPE)
+
+ message("-- LLDB Found PythonExecutable: ${PYTHON_RELEASE_EXE} and ${PYTHON_DEBUG_EXE}")
+ message("-- LLDB Found PythonLibs: ${PYTHON_RELEASE_LIB} and ${PYTHON_DEBUG_LIB}")
+ message("-- LLDB Found PythonDLL: ${PYTHON_RELEASE_DLL} and ${PYTHON_DEBUG_DLL}")
+ message("-- LLDB Found PythonIncludeDirs: ${PYTHON_INCLUDE_DIRS}")
+endfunction(find_python_libs_windows)
+
+if (NOT LLDB_DISABLE_PYTHON)
+ if(UNIX)
+ # This is necessary for crosscompile on Ubuntu 14.04 64bit. Need a proper fix.
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
+ endif()
+ endif()
+
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+ find_python_libs_windows()
+
+ if (NOT LLDB_RELOCATABLE_PYTHON)
+ file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
+ add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" )
+ endif()
+ else()
+ find_package(PythonLibs REQUIRED)
+ endif()
+
+ if (PYTHON_INCLUDE_DIRS)
+ include_directories(${PYTHON_INCLUDE_DIRS})
+ endif()
+endif()
+
+if (LLDB_DISABLE_PYTHON)
+ unset(PYTHON_INCLUDE_DIRS)
+ unset(PYTHON_LIBRARY)
+ add_definitions( -DLLDB_DISABLE_PYTHON )
+endif()
+
+if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
+ include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
+else ()
+ include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)
+endif ()
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
+
+# Disable GCC warnings
+check_cxx_compiler_flag("-Wno-deprecated-declarations"
+ CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS)
+if (CXX_SUPPORTS_NO_DEPRECATED_DECLARATIONS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
+endif ()
+
+check_cxx_compiler_flag("-Wno-unknown-pragmas"
+ CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS)
+if (CXX_SUPPORTS_NO_UNKNOWN_PRAGMAS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
+endif ()
+
+check_cxx_compiler_flag("-Wno-strict-aliasing"
+ CXX_SUPPORTS_NO_STRICT_ALIASING)
+if (CXX_SUPPORTS_NO_STRICT_ALIASING)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
+endif ()
+
+# Disable Clang warnings
+check_cxx_compiler_flag("-Wno-deprecated-register"
+ CXX_SUPPORTS_NO_DEPRECATED_REGISTER)
+if (CXX_SUPPORTS_NO_DEPRECATED_REGISTER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
+endif ()
+
+check_cxx_compiler_flag("-Wno-vla-extension"
+ CXX_SUPPORTS_NO_VLA_EXTENSION)
+if (CXX_SUPPORTS_NO_VLA_EXTENSION)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla-extension")
+endif ()
+
+# Disable MSVC warnings
+if( MSVC )
+ add_definitions(
+ -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
+ -wd4068 # Suppress 'warning C4068: unknown pragma'
+ -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
+ -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'
+ -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
+ -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
+ )
+endif()
+
+set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
+# If building on a 32-bit system, make sure off_t can store offsets > 2GB
+if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
+ add_definitions( -D_LARGEFILE_SOURCE )
+ add_definitions( -D_FILE_OFFSET_BITS=64 )
+endif()
+
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+ message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
+"the makefiles distributed with LLDB. Please create a directory and run cmake "
+"from there, passing the path to this source directory as the last argument. "
+"This process created the file `CMakeCache.txt' and the directory "
+"`CMakeFiles'. Please delete them.")
+endif()
+
+# Compute the LLDB version from the LLVM version.
+string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLDB_VERSION
+ ${PACKAGE_VERSION})
+message(STATUS "LLDB version: ${LLDB_VERSION}")
+
+if (CMAKE_VERSION VERSION_LESS 2.8.12)
+ set(cmake_2_8_12_INTERFACE)
+ set(cmake_2_8_12_PRIVATE)
+ set(cmake_2_8_12_PUBLIC)
+else ()
+ set(cmake_2_8_12_INTERFACE INTERFACE)
+ set(cmake_2_8_12_PRIVATE PRIVATE)
+ set(cmake_2_8_12_PUBLIC PUBLIC)
+endif ()
+
+include_directories(BEFORE
+ ${CMAKE_CURRENT_BINARY_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ )
+
+if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+ install(DIRECTORY include/
+ DESTINATION include
+ FILES_MATCHING
+ PATTERN "*.h"
+ PATTERN ".svn" EXCLUDE
+ )
+endif()
+
+if (NOT LIBXML2_FOUND AND NOT (CMAKE_SYSTEM_NAME MATCHES "Windows"))
+ # Skip Libxml2 on Windows. In CMake 3.4 and higher, the algorithm for
+ # finding libxml2 got "smarter", and it can now locate the version which is
+ # in gnuwin32, even though that version does not contain the headers that
+ # LLDB uses.
+ find_package(LibXml2)
+endif()
+
+# Find libraries or frameworks that may be needed
+if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ find_library(CARBON_LIBRARY Carbon)
+ find_library(FOUNDATION_LIBRARY Foundation)
+ find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
+ find_library(CORE_SERVICES_LIBRARY CoreServices)
+ find_library(SECURITY_LIBRARY Security)
+ find_library(DEBUG_SYMBOLS_LIBRARY DebugSymbols PATHS "/System/Library/PrivateFrameworks")
+
+ add_definitions( -DLIBXML2_DEFINED )
+ list(APPEND system_libs xml2 ${CURSES_LIBRARIES})
+ list(APPEND system_libs ${CARBON_LIBRARY} ${FOUNDATION_LIBRARY}
+ ${CORE_FOUNDATION_LIBRARY} ${CORE_SERVICES_LIBRARY} ${SECURITY_LIBRARY}
+ ${DEBUG_SYMBOLS_LIBRARY})
+
+else()
+ if (LIBXML2_FOUND)
+ add_definitions( -DLIBXML2_DEFINED )
+ list(APPEND system_libs ${LIBXML2_LIBRARIES})
+ include_directories(${LIBXML2_INCLUDE_DIR})
+ endif()
+
+endif()
+
+if (HAVE_LIBPTHREAD)
+ list(APPEND system_libs pthread)
+endif(HAVE_LIBPTHREAD)
+
+if (HAVE_LIBDL)
+ list(APPEND system_libs ${CMAKE_DL_LIBS})
+endif()
+
+if(LLDB_REQUIRES_EH)
+ set(LLDB_REQUIRES_RTTI ON)
+else()
+ if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
+ set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} -fno-exceptions")
+ elseif(MSVC)
+ add_definitions( -D_HAS_EXCEPTIONS=0 )
+ set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} /EHs-c-")
+ endif()
+endif()
+
+# Disable RTTI by default
+if(NOT LLDB_REQUIRES_RTTI)
+ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
+ set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} -fno-rtti")
+ elseif(MSVC)
+ set(LLDB_COMPILE_FLAGS "${LLDB_COMPILE_FLAGS} /GR-")
+ endif()
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLDB_COMPILE_FLAGS}")
+
+if (CMAKE_SYSTEM_NAME MATCHES "Linux")
+ # Check for syscall used by lldb-server on linux.
+ # If these are not found, it will fall back to ptrace (slow) for memory reads.
+ check_cxx_source_compiles("
+ #include <sys/uio.h>
+ int main() { process_vm_readv(0, nullptr, 0, nullptr, 0, 0); return 0; }"
+ HAVE_PROCESS_VM_READV)
+
+ if (HAVE_PROCESS_VM_READV)
+ add_definitions(-DHAVE_PROCESS_VM_READV)
+ else()
+ # If we don't have the syscall wrapper function, but we know the syscall number, we can
+ # still issue the syscall manually
+ check_cxx_source_compiles("
+ #include <sys/syscall.h>
+ int main() { return __NR_process_vm_readv; }"
+ HAVE_NR_PROCESS_VM_READV)
+
+ if (HAVE_NR_PROCESS_VM_READV)
+ add_definitions(-DHAVE_NR_PROCESS_VM_READV)
+ endif()
+ endif()
+endif()
+
+# Figure out if lldb could use lldb-server. If so, then we'll
+# ensure we build lldb-server when an lldb target is being built.
+if ((CMAKE_SYSTEM_NAME MATCHES "Darwin") OR
+ (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") OR
+ (CMAKE_SYSTEM_NAME MATCHES "Linux") OR
+ (CMAKE_SYSTEM_NAME MATCHES "NetBSD"))
+ set(LLDB_CAN_USE_LLDB_SERVER 1)
+else()
+ set(LLDB_CAN_USE_LLDB_SERVER 0)
+endif()
+
+# Figure out if lldb could use debugserver. If so, then we'll
+# ensure we build debugserver when we build lldb.
+if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
+ set(LLDB_CAN_USE_DEBUGSERVER 1)
+else()
+ set(LLDB_CAN_USE_DEBUGSERVER 0)
+endif()
+
+if (NOT LLDB_DISABLE_CURSES)
+ find_package(Curses REQUIRED)
+
+ find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library")
+ if (NOT CURSES_PANEL_LIBRARY)
+ message(FATAL_ERROR "A required curses' panel library not found.")
+ endif ()
+
+ # Add panels to the library path
+ set (CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_PANEL_LIBRARY})
+
+ list(APPEND system_libs ${CURSES_LIBRARIES})
+ include_directories(${CURSES_INCLUDE_DIR})
+endif ()
diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake
new file mode 100644
index 000000000000..d3955f1cdf6b
--- /dev/null
+++ b/cmake/modules/LLDBStandalone.cmake
@@ -0,0 +1,99 @@
+# If we are not building as a part of LLVM, build LLDB as an
+# standalone project, using LLVM as an external library:
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ project(lldb)
+ cmake_minimum_required(VERSION 2.8)
+
+ option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
+
+ set(LLDB_PATH_TO_LLVM_SOURCE "" CACHE PATH
+ "Path to LLVM source code. Not necessary if using an installed LLVM.")
+ set(LLDB_PATH_TO_LLVM_BUILD "" CACHE PATH
+ "Path to the directory where LLVM was built or installed.")
+
+ set(LLDB_PATH_TO_CLANG_SOURCE "" CACHE PATH
+ "Path to Clang source code. Not necessary if using an installed Clang.")
+ set(LLDB_PATH_TO_CLANG_BUILD "" CACHE PATH
+ "Path to the directory where Clang was built or installed.")
+
+ if (LLDB_PATH_TO_LLVM_SOURCE)
+ if (NOT EXISTS "${LLDB_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake")
+ message(FATAL_ERROR "Please set LLDB_PATH_TO_LLVM_SOURCE to the root "
+ "directory of LLVM source code.")
+ else()
+ get_filename_component(LLVM_MAIN_SRC_DIR ${LLDB_PATH_TO_LLVM_SOURCE}
+ ABSOLUTE)
+ set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
+ list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
+ endif()
+ endif()
+
+ if (LLDB_PATH_TO_CLANG_SOURCE)
+ get_filename_component(CLANG_MAIN_SRC_DIR ${LLDB_PATH_TO_CLANG_SOURCE}
+ ABSOLUTE)
+ set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
+ endif()
+
+ list(APPEND CMAKE_MODULE_PATH "${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
+
+ if (LLDB_PATH_TO_LLVM_BUILD)
+ get_filename_component(PATH_TO_LLVM_BUILD ${LLDB_PATH_TO_LLVM_BUILD}
+ ABSOLUTE)
+ else()
+ message(FATAL_ERROR "Please set LLDB_PATH_TO_LLVM_BUILD to the root "
+ "directory of LLVM build or install site.")
+ endif()
+
+ if (LLDB_PATH_TO_CLANG_BUILD)
+ get_filename_component(PATH_TO_CLANG_BUILD ${LLDB_PATH_TO_CLANG_BUILD}
+ ABSOLUTE)
+ else()
+ message(FATAL_ERROR "Please set LLDB_PATH_TO_CLANG_BUILD to the root "
+ "directory of Clang build or install site.")
+ endif()
+
+
+ # These variables are used by add_llvm_library.
+ set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
+ set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
+ set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+
+ include(AddLLVM)
+ include(HandleLLVMOptions)
+
+ if (PYTHON_EXECUTABLE STREQUAL "")
+ set(Python_ADDITIONAL_VERSIONS 3.5 3.4 3.3 3.2 3.1 3.0 2.7 2.6 2.5)
+ include(FindPythonInterp)
+ if( NOT PYTHONINTERP_FOUND )
+ message(FATAL_ERROR
+ "Unable to find Python interpreter, required for builds and testing.
+ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
+ endif()
+ else()
+ message("-- Found PythonInterp: ${PYTHON_EXECUTABLE}")
+ endif()
+ # Import CMake library targets from LLVM and Clang.
+ include("${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
+ if (EXISTS "${LLDB_PATH_TO_CLANG_BUILD}/share/clang/cmake/ClangConfig.cmake")
+ include("${LLDB_PATH_TO_CLANG_BUILD}/share/clang/cmake/ClangConfig.cmake")
+ endif()
+
+ set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
+
+ set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
+
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+ include_directories("${PATH_TO_LLVM_BUILD}/include"
+ "${LLVM_MAIN_INCLUDE_DIR}"
+ "${PATH_TO_CLANG_BUILD}/include"
+ "${CLANG_MAIN_INCLUDE_DIR}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/source")
+ link_directories("${PATH_TO_LLVM_BUILD}/lib${LLVM_LIBDIR_SUFFIX}"
+ "${PATH_TO_CLANG_BUILD}/lib${LLVM_LIBDIR_SUFFIX}")
+
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
+
+ set(LLDB_BUILT_STANDALONE 1)
+endif()