brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.6 KiB · 0d62c32 Raw
397 lines · plain
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})10set(LLDB_OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR})11 12if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)13  message(FATAL_ERROR14    "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.")19endif()20 21macro(add_optional_dependency variable description package found)22  cmake_parse_arguments(ARG23    "QUIET"24    "VERSION"25    ""26    ${ARGN})27 28  set(${variable} "Auto" CACHE STRING "${description} On, Off or Auto (default)")29  string(TOUPPER "${${variable}}" ${variable})30 31  if("${${variable}}" STREQUAL "AUTO")32    set(find_package TRUE)33    set(maybe_required)34  elseif(${${variable}})35    set(find_package TRUE)36    set(maybe_required REQUIRED)37  else()38    set(find_package FALSE)39    set(${variable} FALSE)40  endif()41 42  if(${find_package})43    set(maybe_quiet)44    if(ARG_QUIET)45      set(maybe_quiet QUIET)46    endif()47    find_package(${package} ${ARG_VERSION} ${maybe_required} ${maybe_quiet})48    set(${variable} "${${found}}")49  endif()50 51  message(STATUS "${description}: ${${variable}}")52endmacro()53 54set(LLDB_LIBXML2_VERSION "2.8" CACHE STRING55  "Specify the version of libxml 2 to use with LLDB. This is only meant to be overridden for local56  static builds of libxml 2. Use at your own risk.")57mark_as_advanced(LLDB_LIBXML2_VERSION)58 59add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 4)60add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)61add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)62add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)63add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)64add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)65add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION ${LLDB_LIBXML2_VERSION})66add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)67 68option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)69option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)70option(LLDB_ENABLE_PROTOCOL_SERVERS "Enable protocol servers (e.g. MCP) in LLDB" ON)71option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)72option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)73option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)74option(LLDB_SKIP_DSYM "Whether to skip generating a dSYM when installing lldb." OFF)75option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS76  "Fail to configure if certain requirements are not met for testing." OFF)77 78set(LLDB_GLOBAL_INIT_DIRECTORY "" CACHE STRING79  "Path to the global lldbinit directory. Relative paths are resolved relative to the80  directory containing the LLDB library.")81 82if (LLDB_USE_SYSTEM_DEBUGSERVER)83  # The custom target for the system debugserver has no install target, so we84  # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list.85  if (LLVM_DISTRIBUTION_COMPONENTS)86    list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS debugserver)87    set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)88  endif()89endif()90 91if(LLDB_BUILD_FRAMEWORK)92  if(NOT APPLE)93    message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")94  endif()95 96  set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")97  set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")98  set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework")99 100  get_filename_component(LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE101    BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})102 103  # Essentially, emit the framework's dSYM outside of the framework directory.104  set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING105      "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")106 107  # Custom target to remove the targets (binaries, directories) that were108  # copied into LLDB.framework in the build tree.109  #110  # These targets need to be removed before the install phase because otherwise111  # because otherwise they may overwrite already installed binaries with the112  # wrong RPATH (i.e. build RPATH instead of install RPATH).113  #114  # This target needs to be created here (rather than in API/CMakeLists.txt)115  # because add_lldb_tool creates the custom rules to copy the binaries before116  # the framework target exists and that's the only place where this is117  # tracked.118  add_custom_target(lldb-framework-cleanup119    COMMENT "Cleaning up build-tree frameworks in preparation for install")120endif()121 122if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)123  if(NOT LLDB_EXPLICIT_XCODE_CACHE_USED)124    message(WARNING125      "When building with Xcode, we recommend using the corresponding cache script. "126      "If this was a mistake, clean your build directory and re-run CMake with:\n"127      "  -C ${CMAKE_SOURCE_DIR}/cmake/caches/Apple-lldb-Xcode.cmake\n"128      "See: https://lldb.llvm.org/resources/build.html#cmakegeneratedxcodeproject\n")129  endif()130endif()131 132set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL133  "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.")134 135set(LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE "" CACHE PATH136  "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the exports file to use when building liblldb.")137 138if (CMAKE_SYSTEM_NAME MATCHES "Windows")139  set(LLDB_EXPORT_ALL_SYMBOLS_PLUGINS "" CACHE STRING140    "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the plugins whose symbols should be exported.")141endif()142 143if ((NOT MSVC) OR MSVC12)144  add_definitions( -DHAVE_ROUND )145endif()146 147# Check if we libedit capable of handling wide characters (built with148# '--enable-widec').149if (LLDB_ENABLE_LIBEDIT)150  set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})151  set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})152  check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)153  set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)154  check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)155  if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")156    set(LLDB_HAVE_EL_RFUNC_T 0)157  else()158    set(LLDB_HAVE_EL_RFUNC_T 1)159  endif()160  set(CMAKE_REQUIRED_LIBRARIES)161  set(CMAKE_REQUIRED_INCLUDES)162  set(CMAKE_EXTRA_INCLUDE_FILES)163endif()164 165if (LLDB_ENABLE_PYTHON)166  if(CMAKE_SYSTEM_NAME MATCHES "Windows")167    set(default_embed_python_home ON)168  else()169    set(default_embed_python_home OFF)170  endif()171  option(LLDB_EMBED_PYTHON_HOME172    "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."173    ${default_embed_python_home})174 175  include_directories(${Python3_INCLUDE_DIRS})176 177  if (LLDB_EMBED_PYTHON_HOME)178    get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)179    set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING180      "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")181  endif()182 183  # Enable targeting the Python Limited C API.184  set(PYTHON_LIMITED_API_MIN_SWIG_VERSION "4.2")185  if (SWIG_VERSION VERSION_EQUAL "4.4.0" AND Python3_VERSION VERSION_GREATER_EQUAL "3.13")186    set(AFFECTED_BY_SWIG_BUG TRUE)187  else()188    set(AFFECTED_BY_SWIG_BUG FALSE)189  endif()190 191  if (SWIG_VERSION VERSION_GREATER_EQUAL PYTHON_LIMITED_API_MIN_SWIG_VERSION192      AND NOT LLDB_EMBED_PYTHON_HOME AND NOT AFFECTED_BY_SWIG_BUG)193    set(default_enable_python_limited_api ON)194  else()195    set(default_enable_python_limited_api OFF)196  endif()197 198  option(LLDB_ENABLE_PYTHON_LIMITED_API "Force LLDB to only use the Python Limited API (requires SWIG 4.2 or later)"199    ${default_enable_python_limited_api})200 201  # Diagnose unsupported configurations.202  if (LLDB_ENABLE_PYTHON_LIMITED_API AND AFFECTED_BY_SWIG_BUG)203    message(SEND_ERROR "LLDB_ENABLE_PYTHON_LIMITED_API is not compatible with SWIG 4.4.0 and Python >= 3.13 due to a bug in SWIG: https://github.com/swig/swig/issues/3283")204  endif()205  if (LLDB_ENABLE_PYTHON_LIMITED_API AND LLDB_EMBED_PYTHON_HOME)206    message(SEND_ERROR "LLDB_ENABLE_PYTHON_LIMITED_API is not compatible with LLDB_EMBED_PYTHON_HOME")207  endif()208  if (LLDB_ENABLE_PYTHON_LIMITED_API AND SWIG_VERSION VERSION_LESS PYTHON_LIMITED_API_MIN_SWIG_VERSION)209    message(SEND_ERROR "LLDB_ENABLE_PYTHON_LIMITED_API is not compatible with SWIG ${SWIG_VERSION} (requires SWIG ${PYTHON_LIMITED_API_MIN_SWIG_VERSION})")210  endif()211 212else()213  # Even if Python scripting is disabled, we still need a Python interpreter to214  # build, for example to generate SBLanguages.h.215  find_package(Python3 COMPONENTS Interpreter REQUIRED)216 217  # Remove lldb-python-scripts from distribution components.218  # LLVM_DISTRIBUTION_COMPONENTS is set in a cache where LLDB_ENABLE_PYTHON does219  # not yet have a value. We have to touch up LLVM_DISTRIBUTION_COMPONENTS after220  # the fact.221  if(LLVM_DISTRIBUTION_COMPONENTS)222    list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS lldb-python-scripts)223    set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)224  endif()225endif()226 227if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)228  include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)229else ()230  include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)231endif ()232include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")233 234if(LLDB_BUILT_STANDALONE)235  if (TARGET clang-resource-headers)236    get_target_property(CLANG_RESOURCE_DIR clang-resource-headers INTERFACE_INCLUDE_DIRECTORIES)237    set(CLANG_RESOURCE_DIR "${CLANG_RESOURCE_DIR}/..")238  else()239    set(CLANG_RESOURCE_DIR "${LLDB_EXTERNAL_CLANG_RESOURCE_DIR}")240  endif()241else()242  get_clang_resource_dir(CLANG_RESOURCE_DIR PREFIX "${CMAKE_BINARY_DIR}")243endif()244 245# GCC silently accepts any -Wno-<foo> option, but warns about those options246# being unrecognized only if the compilation triggers other warnings to be247# printed. Therefore, check for whether the compiler supports options in the248# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.249 250if (LLVM_COMPILER_IS_GCC_COMPATIBLE)251  # Disable GCC warnings252  append("-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)253  append("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)254 255  check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)256  append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)257endif()258 259# Disable Clang warnings260if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")261  append("-Wno-vla-extension" CMAKE_CXX_FLAGS)262endif()263 264# Disable MSVC warnings265if( MSVC )266  add_definitions(267    -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'268    -wd4068 # Suppress 'warning C4068: unknown pragma'269    -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'270    -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union'271    -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'272    -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'273    -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'274    -wd4589 # Suppress 'warning C4589: Constructor of abstract class 'lldb_private::NativeRegisterContextDBReg_x86' ignores initializer for virtual base class 'lldb_private::NativeRegisterContextRegisterInfo''275  )276endif()277 278# Use the Unicode (UTF-16) APIs by default on Win32279if (CMAKE_SYSTEM_NAME MATCHES "Windows")280    add_definitions( -D_UNICODE -DUNICODE )281endif()282 283# If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*.284if(NOT DEFINED LLDB_VERSION_MAJOR)285  set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR})286endif()287if(NOT DEFINED LLDB_VERSION_MINOR)288  set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR})289endif()290if(NOT DEFINED LLDB_VERSION_PATCH)291  set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH})292endif()293if(NOT DEFINED LLDB_VERSION_SUFFIX)294  set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})295endif()296set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")297message(STATUS "LLDB version: ${LLDB_VERSION}")298 299if (LLDB_ENABLE_LZMA)300  include_directories(${LIBLZMA_INCLUDE_DIRS})301endif()302 303include_directories(BEFORE304  ${CMAKE_CURRENT_BINARY_DIR}/include305  ${CMAKE_CURRENT_SOURCE_DIR}/include306  )307 308if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)309  install(DIRECTORY include/310    COMPONENT lldb-headers311    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"312    FILES_MATCHING313    PATTERN "*.h"314    PATTERN ".cmake" EXCLUDE315    )316 317  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/318    COMPONENT lldb-headers319    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"320    FILES_MATCHING321    PATTERN "*.h"322    PATTERN ".cmake" EXCLUDE323    )324 325  add_custom_target(lldb-headers)326  set_target_properties(lldb-headers PROPERTIES FOLDER "LLDB/Resources")327 328  if (NOT CMAKE_CONFIGURATION_TYPES)329    add_llvm_install_targets(install-lldb-headers330                             COMPONENT lldb-headers)331  endif()332endif()333 334# Find Apple-specific libraries or frameworks that may be needed.335if (APPLE)336  if(NOT APPLE_EMBEDDED)337    find_library(CARBON_LIBRARY Carbon)338    find_library(CORE_SERVICES_LIBRARY CoreServices)339  endif()340  find_library(FOUNDATION_LIBRARY Foundation)341  find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)342  find_library(SECURITY_LIBRARY Security)343endif()344 345if( WIN32 AND NOT CYGWIN )346  set(PURE_WINDOWS 1)347endif()348 349if(NOT PURE_WINDOWS)350  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)351  find_package(Threads REQUIRED)352endif()353 354# Figure out if lldb could use lldb-server.  If so, then we'll355# ensure we build lldb-server when an lldb target is being built.356if (CMAKE_SYSTEM_NAME MATCHES "AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")357  set(LLDB_CAN_USE_LLDB_SERVER ON)358else()359  set(LLDB_CAN_USE_LLDB_SERVER OFF)360endif()361 362# Figure out if lldb could use debugserver.  If so, then we'll363# ensure we build debugserver when we build lldb.364if (CMAKE_SYSTEM_NAME MATCHES "Darwin")365    set(LLDB_CAN_USE_DEBUGSERVER ON)366else()367    set(LLDB_CAN_USE_DEBUGSERVER OFF)368endif()369 370# In a cross-compile build, we need to skip building the generated371# lldb-rpc sources in the first phase of host build so that they can372# get built using the just-built Clang toolchain in the second phase.373if (NOT DEFINED LLDB_CAN_USE_LLDB_RPC_SERVER)374  set(LLDB_CAN_USE_LLDB_RPC_SERVER OFF)375else()376  if ((CMAKE_CROSSCOMPILING OR LLVM_HOST_TRIPLE MATCHES "${LLVM_DEFAULT_TARGET_TRIPLE}") AND377      CMAKE_SYSTEM_NAME MATCHES "AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")378    set(LLDB_CAN_USE_LLDB_RPC_SERVER ON)379  else()380    set(LLDB_CAN_USE_LLDB_RPC_SERVER OFF)381  endif()382endif()383 384 385if (NOT DEFINED LLDB_BUILD_LLDBRPC)386  set(LLDB_BUILD_LLDBRPC OFF)387else()388  if (CMAKE_CROSSCOMPILING)389    set(LLDB_BUILD_LLDBRPC OFF CACHE BOOL "")390    get_host_tool_path(lldb-rpc-gen LLDB_RPC_GEN_EXE lldb_rpc_gen_exe lldb_rpc_gen_target)391  else()392    set(LLDB_BUILD_LLDBRPC ON CACHE BOOL "")393  endif()394endif()395 396include(LLDBGenerateConfig)397