1 cmake_minimum_required(VERSION 3.20.0)
2 set(LLVM_SUBPROJECT_TITLE "LLDB")
4 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
5 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
7 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
10 # Add path for custom modules.
13 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
14 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
17 # If we are not building as part of LLVM, build LLDB as a standalone project,
18 # using LLVM as an external library.
19 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
21 set(LLDB_BUILT_STANDALONE TRUE)
22 set(LLVM_INCLUDE_TESTS ON CACHE INTERNAL "")
25 # Must go below project(..)
26 include(GNUInstallDirs)
28 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
30 if(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)
35 include(LLDBStandalone)
41 # Define the LLDB_CONFIGURATION_xxx matching the build type.
42 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
43 add_definitions(-DLLDB_CONFIGURATION_DEBUG)
47 add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
49 # _BSD_SOURCE is required for MinGW's getopt.h to define optreset
50 add_definitions(-D_BSD_SOURCE)
54 if (LLDB_ENABLE_PYTHON)
55 set(cachestring_LLDB_PYTHON_RELATIVE_PATH
56 "Path where Python modules are installed, relative to LLDB's install prefix")
57 set(cachestring_LLDB_PYTHON_EXE_RELATIVE_PATH
58 "Path to python interpreter exectuable, relative to python's install prefix")
59 set(cachestring_LLDB_PYTHON_EXT_SUFFIX
60 "Filename extension for native code python modules")
62 foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
63 if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
65 COMMAND ${Python3_EXECUTABLE}
66 ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
69 OUTPUT_STRIP_TRAILING_WHITESPACE)
70 file(TO_CMAKE_PATH "${value}" value)
71 set(${var} ${value} CACHE STRING ${cachestring_${var}})
73 if ("${${var}}" STREQUAL "")
75 "Crosscompiling LLDB with Python requires manually setting ${var}.")
79 # Make sure lldb extension has "_d" suffix on Windows in Debug mode.
80 if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL Debug)
81 string(SUBSTRING ${LLDB_PYTHON_EXT_SUFFIX} 0 2 FIRST_2_CHARS)
82 # Add "_d" manually if LLDB_PYTHON_EXT_SUFFIX lacks it due to release Python configuration.
83 if(NOT FIRST_2_CHARS STREQUAL "_d")
84 set(LLDB_PYTHON_EXT_SUFFIX "_d${LLDB_PYTHON_EXT_SUFFIX}")
90 set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
91 set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
92 CACHE STRING "Path where Lua modules are installed, relative to install prefix")
95 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
96 add_subdirectory(bindings)
99 # We need the headers generated by intrinsics_gen before we can compile
100 # any source file in LLDB as the imported Clang modules might include
101 # some of these generated headers. This approach is copied from Clang's main
102 # CMakeLists.txt, so it should kept in sync the code in Clang which was added
103 # in llvm-svn 308844.
104 if(LLVM_ENABLE_MODULES)
105 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
108 if(CMAKE_CROSSCOMPILING AND LLDB_BUILT_STANDALONE AND NOT LLDB_TABLEGEN_EXE)
109 set(LLVM_USE_HOST_TOOLS ON)
110 include(CrossCompile)
111 if (NOT NATIVE_LLVM_DIR OR NOT NATIVE_Clang_DIR)
113 "Crosscompiling standalone requires the variables NATIVE_{CLANG,LLVM}_DIR
114 for building the native lldb-tblgen used during the build process.")
116 llvm_create_cross_target(lldb NATIVE "" Release
117 -DLLVM_DIR=${NATIVE_LLVM_DIR}
118 -DClang_DIR=${NATIVE_Clang_DIR})
122 add_subdirectory(utils/TableGen)
124 add_subdirectory(source)
125 add_subdirectory(tools)
126 add_subdirectory(docs)
128 if (LLDB_ENABLE_PYTHON)
129 if(LLDB_BUILD_FRAMEWORK)
130 set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
132 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
134 get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
135 finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
139 if(LLDB_BUILD_FRAMEWORK)
140 set(LLDB_LUA_CPATH "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
142 set(LLDB_LUA_CPATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
144 get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
145 finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${LLDB_LUA_CPATH}")
148 set(LLDB_INCLUDE_UNITTESTS ON)
149 if (NOT TARGET llvm_gtest)
150 set(LLDB_INCLUDE_UNITTESTS OFF)
153 if(LLDB_INCLUDE_TESTS)
154 add_subdirectory(test)
155 if (LLDB_INCLUDE_UNITTESTS)
156 add_subdirectory(unittests)
158 add_subdirectory(utils)
161 if(LLDB_BUILT_STANDALONE AND NOT LLVM_ENABLE_IDE)
162 llvm_distribution_add_targets()