1 cmake_minimum_required(VERSION 3.20.0)
3 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
4 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
6 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
9 # Add path for custom modules.
12 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
16 # If we are not building as part of LLVM, build LLDB as a standalone project,
17 # using LLVM as an external library.
18 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
20 set(LLDB_BUILT_STANDALONE TRUE)
21 set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "")
24 # Must go below project(..)
25 include(GNUInstallDirs)
27 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
29 if(LLDB_BUILT_STANDALONE)
30 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
31 set(CMAKE_CXX_STANDARD_REQUIRED YES)
32 set(CMAKE_CXX_EXTENSIONS NO)
34 include(LLDBStandalone)
40 # Define the LLDB_CONFIGURATION_xxx matching the build type.
41 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
42 add_definitions(-DLLDB_CONFIGURATION_DEBUG)
46 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
48 # _BSD_SOURCE is required for MinGW's getopt.h to define optreset
49 add_definitions(-D_BSD_SOURCE)
53 if (LLDB_ENABLE_PYTHON)
54 set(cachestring_LLDB_PYTHON_RELATIVE_PATH
55 "Path where Python modules are installed, relative to LLDB's install prefix")
56 set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
57 "Path to python interpreter exectuable, relative to python's install prefix")
58 set(cachestring_LLDB_PYTHON_EXT_SUFFIX
59 "Filename extension for native code python modules")
61 foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
62 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
64 COMMAND ${Python3_EXECUTABLE}
65 ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
68 OUTPUT_STRIP_TRAILING_WHITESPACE)
69 file(TO_CMAKE_PATH "${value}" value)
70 set(${var} ${value} CACHE STRING ${cachestring_${var}})
72 if ("${${var}}" STREQUAL "")
74 "Crosscompiling LLDB with Python requires manually setting ${var}.")
81 find_program(Lua_EXECUTABLE lua5.3)
82 set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
83 set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
84 CACHE STRING "Path where Lua modules are installed, relative to install prefix")
87 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
88 add_subdirectory(bindings)
91 # We need the headers generated by instrinsics_gen before we can compile
92 # any source file in LLDB as the imported Clang modules might include
93 # some of these generated headers. This approach is copied from Clang's main
94 # CMakeLists.txt, so it should kept in sync the code in Clang which was added
96 if(LLVM_ENABLE_MODULES)
97 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
100 if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE AND NOT LLDB_TABLEGEN_EXE)
101 set(LLVM_USE_HOST_TOOLS ON)
102 include(CrossCompile)
103 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)
105 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR
106 for building the native lldb-tblgen used during the build process.")
108 llvm_create_cross_target(lldb NATIVE "" Release
109 -DLLVM_DIR=${NATIVE_LLVM_DIR}
110 -DClang_DIR=${NATIVE_Clang_DIR})
114 add_subdirectory(utils/TableGen)
116 add_subdirectory(source)
117 add_subdirectory(tools)
118 add_subdirectory(docs)
120 if (LLDB_ENABLE_PYTHON)
121 if(LLDB_BUILD_FRAMEWORK)
122 set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
124 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
126 get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
127 finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
131 if(LLDB_BUILD_FRAMEWORK)
132 set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
134 set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
136 get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
137 finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
140 set(LLDB_INCLUDE_UNITTESTS ON)
141 if (NOT TARGET llvm_gtest)
142 set(LLDB_INCLUDE_UNITTESTS OFF)
145 if(LLDB_INCLUDE_TESTS)
146 add_subdirectory(test)
147 if (LLDB_INCLUDE_UNITTESTS)
148 add_subdirectory(unittests)
150 add_subdirectory(utils)
153 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
154 llvm_distribution_add_targets()