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)
49 if (LLDB_ENABLE_PYTHON)
50 set(cachestring_LLDB_PYTHON_RELATIVE_PATH
51 "Path where Python modules are installed, relative to LLDB's install prefix")
52 set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
53 "Path to python interpreter exectuable, relative to python's install prefix")
54 set(cachestring_LLDB_PYTHON_EXT_SUFFIX
55 "Filename extension for native code python modules")
57 foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
58 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
60 COMMAND ${Python3_EXECUTABLE}
61 ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
64 OUTPUT_STRIP_TRAILING_WHITESPACE)
65 file(TO_CMAKE_PATH "${value}" value)
66 set(${var} ${value} CACHE STRING ${cachestring_${var}})
68 if ("${${var}}" STREQUAL "")
70 "Crosscompiling LLDB with Python requires manually setting ${var}.")
77 find_program(Lua_EXECUTABLE lua5.3)
78 set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
79 set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
80 CACHE STRING "Path where Lua modules are installed, relative to install prefix")
83 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
84 add_subdirectory(bindings)
87 # We need the headers generated by instrinsics_gen before we can compile
88 # any source file in LLDB as the imported Clang modules might include
89 # some of these generated headers. This approach is copied from Clang's main
90 # CMakeLists.txt, so it should kept in sync the code in Clang which was added
92 if(LLVM_ENABLE_MODULES)
93 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
96 if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE AND NOT LLDB_TABLEGEN_EXE)
97 set(LLVM_USE_HOST_TOOLS ON)
99 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)
101 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR
102 for building the native lldb-tblgen used during the build process.")
104 llvm_create_cross_target(lldb NATIVE "" Release
105 -DLLVM_DIR=${NATIVE_LLVM_DIR}
106 -DClang_DIR=${NATIVE_Clang_DIR})
110 add_subdirectory(utils/TableGen)
112 add_subdirectory(source)
113 add_subdirectory(tools)
114 add_subdirectory(docs)
116 if (LLDB_ENABLE_PYTHON)
117 if(LLDB_BUILD_FRAMEWORK)
118 set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
120 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
122 get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
123 finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
127 if(LLDB_BUILD_FRAMEWORK)
128 set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
130 set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
132 get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
133 finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
136 set(LLDB_INCLUDE_UNITTESTS ON)
137 if (NOT TARGET llvm_gtest)
138 set(LLDB_INCLUDE_UNITTESTS OFF)
141 if(LLDB_INCLUDE_TESTS)
142 add_subdirectory(test)
143 if (LLDB_INCLUDE_UNITTESTS)
144 add_subdirectory(unittests)
146 add_subdirectory(utils)
149 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
150 llvm_distribution_add_targets()