1 cmake_minimum_required(VERSION 3.13.4)
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 "")
22 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
24 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
25 "minimum version of CMake required to build LLVM will become 3.20.0, and "
26 "using an older CMake will become an error. Please upgrade your CMake to "
27 "at least 3.20.0 now to avoid issues in the future!")
31 # Must go below project(..)
32 include(GNUInstallDirs)
34 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
36 if(LLDB_BUILT_STANDALONE)
37 include(LLDBStandalone)
39 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
40 set(CMAKE_CXX_STANDARD_REQUIRED YES)
41 set(CMAKE_CXX_EXTENSIONS NO)
47 # Define the LLDB_CONFIGURATION_xxx matching the build type.
48 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
49 add_definitions(-DLLDB_CONFIGURATION_DEBUG)
53 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
56 if (LLDB_ENABLE_PYTHON)
57 set(cachestring_LLDB_PYTHON_RELATIVE_PATH
58 "Path where Python modules are installed, relative to LLDB's install prefix")
59 set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
60 "Path to python interpreter exectuable, relative to python's install prefix")
61 set(cachestring_LLDB_PYTHON_EXT_SUFFIX
62 "Filename extension for native code python modules")
64 foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
65 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
67 COMMAND ${Python3_EXECUTABLE}
68 ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
71 OUTPUT_STRIP_TRAILING_WHITESPACE)
72 file(TO_CMAKE_PATH "${value}" value)
73 set(${var} ${value} CACHE STRING ${cachestring_${var}})
75 if ("${${var}}" STREQUAL "")
77 "Crosscompiling LLDB with Python requires manually setting ${var}.")
84 find_program(Lua_EXECUTABLE lua5.3)
85 set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
86 set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
87 CACHE STRING "Path where Lua modules are installed, relative to install prefix")
90 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
91 add_subdirectory(bindings)
94 # We need the headers generated by instrinsics_gen before we can compile
95 # any source file in LLDB as the imported Clang modules might include
96 # some of these generated headers. This approach is copied from Clang's main
97 # CMakeLists.txt, so it should kept in sync the code in Clang which was added
99 if(LLVM_ENABLE_MODULES)
100 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
103 if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE AND NOT LLDB_TABLEGEN_EXE)
104 set(LLVM_USE_HOST_TOOLS ON)
105 include(CrossCompile)
106 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)
108 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR
109 for building the native lldb-tblgen used during the build process.")
111 llvm_create_cross_target(lldb NATIVE "" Release
112 -DLLVM_DIR=${NATIVE_LLVM_DIR}
113 -DClang_DIR=${NATIVE_Clang_DIR})
117 add_subdirectory(utils/TableGen)
119 add_subdirectory(source)
120 add_subdirectory(tools)
121 add_subdirectory(docs)
123 if (LLDB_ENABLE_PYTHON)
124 if(LLDB_BUILD_FRAMEWORK)
125 set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
127 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
129 get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
130 finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
134 if(LLDB_BUILD_FRAMEWORK)
135 set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
137 set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
139 get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
140 finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
143 set(LLDB_INCLUDE_UNITTESTS ON)
144 if (NOT TARGET llvm_gtest)
145 set(LLDB_INCLUDE_UNITTESTS OFF)
148 if(LLDB_INCLUDE_TESTS)
149 add_subdirectory(test)
150 if (LLDB_INCLUDE_UNITTESTS)
151 add_subdirectory(unittests)
153 add_subdirectory(utils)
156 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
157 llvm_distribution_add_targets()