180 lines · plain
1cmake_minimum_required(VERSION 3.20.0)2set(LLVM_SUBPROJECT_TITLE "LLDB")3 4if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)5 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)6endif()7include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake8 NO_POLICY_SCOPE)9 10# Add path for custom modules.11set(CMAKE_MODULE_PATH12 ${CMAKE_MODULE_PATH}13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"15 )16 17# If we are not building as part of LLVM, build LLDB as a standalone project,18# using LLVM as an external library.19if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)20 project(lldb)21 set(LLDB_BUILT_STANDALONE TRUE)22 set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "")23endif()24 25# Must go below project(..)26include(GNUInstallDirs)27 28option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})29 30if(LLDB_BUILT_STANDALONE)31 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")32 set(CMAKE_CXX_STANDARD_REQUIRED YES)33 set(CMAKE_CXX_EXTENSIONS NO)34 35 include(LLDBStandalone)36endif()37 38include(LLDBConfig)39include(AddLLDB)40include(LLDBLayeringCheck)41 42set(LLDB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)43 44# Define the LLDB_CONFIGURATION_xxx matching the build type.45if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )46 add_definitions(-DLLDB_CONFIGURATION_DEBUG)47endif()48 49if (WIN32)50 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)51 if (NOT MSVC)52 # _BSD_SOURCE is required for MinGW's getopt.h to define optreset53 add_definitions(-D_BSD_SOURCE)54 endif()55endif()56 57if (LLDB_ENABLE_PYTHON)58 set(cachestring_LLDB_PYTHON_RELATIVE_PATH59 "Path where Python modules are installed, relative to LLDB's install prefix")60 set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH61 "Path to python interpreter exectuable, relative to python's install prefix")62 set(cachestring_LLDB_PYTHON_EXT_SUFFIX63 "Filename extension for native code python modules")64 65 if (LLDB_ENABLE_PYTHON_LIMITED_API)66 set(stable_abi "--stable-abi")67 endif()68 69 foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)70 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)71 execute_process(72 COMMAND ${Python3_EXECUTABLE}73 ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py74 ${stable_abi}75 ${var}76 OUTPUT_VARIABLE value77 OUTPUT_STRIP_TRAILING_WHITESPACE)78 file(TO_CMAKE_PATH "${value}" value)79 set(${var} ${value} CACHE STRING ${cachestring_${var}})80 else()81 if ("${${var}}" STREQUAL "")82 message(FATAL_ERROR83 "Crosscompiling LLDB with Python requires manually setting ${var}.")84 endif()85 endif()86 endforeach()87 # Make sure lldb extension has "_d" suffix on Windows in Debug mode.88 if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL Debug)89 string(SUBSTRING ${LLDB_PYTHON_EXT_SUFFIX} 0 2 FIRST_2_CHARS)90 # Add "_d" manually if LLDB_PYTHON_EXT_SUFFIX lacks it due to release Python configuration.91 if(NOT FIRST_2_CHARS STREQUAL "_d")92 set(LLDB_PYTHON_EXT_SUFFIX "_d${LLDB_PYTHON_EXT_SUFFIX}")93 endif()94 endif()95 if(TARGET Python3::Python)96 get_target_property(_Python3_LIB_PATH Python3::Python IMPORTED_LIBRARY_LOCATION)97 if(_Python3_LIB_PATH)98 get_filename_component(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME "${_Python3_LIB_PATH}" NAME)99 endif()100 endif()101endif ()102 103if (LLDB_ENABLE_LUA)104 set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")105 set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}106 CACHE STRING "Path where Lua modules are installed, relative to install prefix")107endif ()108 109if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)110 add_subdirectory(bindings)111endif ()112 113# We need the headers generated by intrinsics_gen before we can compile114# any source file in LLDB as the imported Clang modules might include115# some of these generated headers. This approach is copied from Clang's main116# CMakeLists.txt, so it should kept in sync the code in Clang which was added117# in llvm-svn 308844.118if(LLVM_ENABLE_MODULES)119 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)120endif()121 122if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE AND NOT LLDB_TABLEGEN_EXE)123 set(LLVM_USE_HOST_TOOLS ON)124 include(CrossCompile)125 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)126 message(FATAL_ERROR127 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR128 for building the native lldb-tblgen used during the build process.")129 endif()130 llvm_create_cross_target(lldb NATIVE "" Release131 -DLLVM_DIR=${NATIVE_LLVM_DIR}132 -DClang_DIR=${NATIVE_Clang_DIR})133endif()134 135# TableGen136add_subdirectory(utils/TableGen)137 138add_subdirectory(source)139add_subdirectory(tools)140add_subdirectory(docs)141 142check_lldb_plugin_layering()143 144if (LLDB_ENABLE_PYTHON)145 if(LLDB_BUILD_FRAMEWORK)146 set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")147 else()148 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")149 endif()150 get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)151 finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")152endif()153 154if (LLDB_ENABLE_LUA)155 if(LLDB_BUILD_FRAMEWORK)156 set(LLDB_LUA_CPATH "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")157 else()158 set(LLDB_LUA_CPATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")159 endif()160 get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)161 finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${LLDB_LUA_CPATH}")162endif()163 164set(LLDB_INCLUDE_UNITTESTS ON)165if (NOT TARGET llvm_gtest)166 set(LLDB_INCLUDE_UNITTESTS OFF)167endif()168 169if(LLDB_INCLUDE_TESTS)170 add_subdirectory(test)171 if (LLDB_INCLUDE_UNITTESTS)172 add_subdirectory(unittests)173 endif()174 add_subdirectory(utils)175endif()176 177if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)178 llvm_distribution_add_targets()179endif()180