Debian Codegraph @

lldb/cmake/modules/LLDBConfig.cmake

raw
1 include(CheckCXXSymbolExists)
2 include(CheckTypeSize)
3
4 set(LLDB_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
5 set(LLDB_SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/source")
6 set(LLDB_INCLUDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/include")
7
8 set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10 set(LLDB_OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR})
11
12 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
13 message(FATAL_ERROR
14 "In-source builds are not allowed. CMake would overwrite the makefiles "
15 "distributed with LLDB. Please create a directory and run cmake from "
16 "there, passing the path to this source directory as the last argument. "
17 "This process created the file `CMakeCache.txt' and the directory "
18 "`CMakeFiles'. Please delete them.")
19 endif()
20
21 macro(add_optional_dependency variable description package found)
22 cmake_parse_arguments(ARG
23 "QUIET"
24 "VERSION"
25 ""
26 ${ARGN})
27
28 set(${variable} "Auto" CACHE STRING "${description} On, Off or Auto (default)")
29 string(TOUPPER "${${variable}}" ${variable})
30
31 if("${${variable}}" STREQUAL "AUTO")
32 set(find_package TRUE)
33 set(maybe_required)
34 elseif(${${variable}})
35 set(find_package TRUE)
36 set(maybe_required REQUIRED)
37 else()
38 set(find_package FALSE)
39 set(${variable} FALSE)
40 endif()
41
42 if(${find_package})
43 set(maybe_quiet)
44 if(ARG_QUIET)
45 set(maybe_quiet QUIET)
46 endif()
47 find_package(${package} ${ARG_VERSION} ${maybe_required} ${maybe_quiet})
48 set(${variable} "${${found}}")
49 endif()
50
51 message(STATUS "${description}: ${${variable}}")
52 endmacro()
53
54 add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 4)
55 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)
56 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
57 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
58 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
59 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
60 add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
61 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
62
63 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
64 option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
65 option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
66 option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
67 option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)
68 option(LLDB_SKIP_DSYM "Whether to skip generating a dSYM when installing lldb." OFF)
69 option(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS
70 "Fail to configure if certain requirements are not met for testing." OFF)
71
72 set(LLDB_GLOBAL_INIT_DIRECTORY "" CACHE STRING
73 "Path to the global lldbinit directory. Relative paths are resolved relative to the
74 directory containing the LLDB library.")
75
76 if (LLDB_USE_SYSTEM_DEBUGSERVER)
77 # The custom target for the system debugserver has no install target, so we
78 # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list.
79 if (LLVM_DISTRIBUTION_COMPONENTS)
80 list(REMOVE_ITEM LLVM_DISTRIBUTION_COMPONENTS debugserver)
81 set(LLVM_DISTRIBUTION_COMPONENTS ${LLVM_DISTRIBUTION_COMPONENTS} CACHE STRING "" FORCE)
82 endif()
83 endif()
84
85 if(LLDB_BUILD_FRAMEWORK)
86 if(NOT APPLE)
87 message(FATAL_ERROR "LLDB.framework can only be generated when targeting Apple platforms")
88 endif()
89
90 set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
91 set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")
92 set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework")
93
94 get_filename_component(LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR ${LLDB_FRAMEWORK_BUILD_DIR} ABSOLUTE
95 BASE_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
96
97 # Essentially, emit the framework's dSYM outside of the framework directory.
98 set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING
99 "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)")
100
101 # Custom target to remove the targets (binaries, directories) that were
102 # copied into LLDB.framework in the build tree.
103 #
104 # These targets need to be removed before the install phase because otherwise
105 # because otherwise they may overwrite already installed binaries with the
106 # wrong RPATH (i.e. build RPATH instead of install RPATH).
107 #
108 # This target needs to be created here (rather than in API/CMakeLists.txt)
109 # because add_lldb_tool creates the custom rules to copy the binaries before
110 # the framework target exists and that's the only place where this is
111 # tracked.
112 add_custom_target(lldb-framework-cleanup
113 COMMENT "Cleaning up build-tree frameworks in preparation for install")
114 endif()
115
116 if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)
117 if(NOT LLDB_EXPLICIT_XCODE_CACHE_USED)
118 message(WARNING
119 "When building with Xcode, we recommend using the corresponding cache script. "
120 "If this was a mistake, clean your build directory and re-run CMake with:\n"
121 " -C ${CMAKE_SOURCE_DIR}/cmake/caches/Apple-lldb-Xcode.cmake\n"
122 "See: https://lldb.llvm.org/resources/build.html#cmakegeneratedxcodeproject\n")
123 endif()
124 endif()
125
126 set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
127 "Causes lldb to export some private symbols when building liblldb. See lldb/source/API/liblldb-private.exports for the full list of symbols that get exported.")
128
129 set(LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE "" CACHE PATH
130 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the exports file to use when building liblldb.")
131
132 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
133 set(LLDB_EXPORT_ALL_SYMBOLS_PLUGINS "" CACHE STRING
134 "When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the plugins whose symbols should be exported.")
135 endif()
136
137 if ((NOT MSVC) OR MSVC12)
138 add_definitions( -DHAVE_ROUND )
139 endif()
140
141 # Check if we libedit capable of handling wide characters (built with
142 # '--enable-widec').
143 if (LLDB_ENABLE_LIBEDIT)
144 set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
145 set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
146 check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
147 set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)
148 check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)
149 if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")
150 set(LLDB_HAVE_EL_RFUNC_T 0)
151 else()
152 set(LLDB_HAVE_EL_RFUNC_T 1)
153 endif()
154 set(CMAKE_REQUIRED_LIBRARIES)
155 set(CMAKE_REQUIRED_INCLUDES)
156 set(CMAKE_EXTRA_INCLUDE_FILES)
157 endif()
158
159 if (LLDB_ENABLE_PYTHON)
160 if(CMAKE_SYSTEM_NAME MATCHES "Windows")
161 set(default_embed_python_home ON)
162 else()
163 set(default_embed_python_home OFF)
164 endif()
165 option(LLDB_EMBED_PYTHON_HOME
166 "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."
167 ${default_embed_python_home})
168
169 include_directories(${Python3_INCLUDE_DIRS})
170 if (LLDB_EMBED_PYTHON_HOME)
171 get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
172 set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
173 "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")
174 endif()
175 endif()
176
177 if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
178 include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
179 else ()
180 include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)
181 endif ()
182 include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
183
184 # GCC silently accepts any -Wno-<foo> option, but warns about those options
185 # being unrecognized only if the compilation triggers other warnings to be
186 # printed. Therefore, check for whether the compiler supports options in the
187 # form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
188
189 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
190 # Disable GCC warnings
191 append("-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
192 append("-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
193 append("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
194
195 check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)
196 append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)
197 endif()
198
199 # Disable Clang warnings
200 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
201 append("-Wno-deprecated-register" CMAKE_CXX_FLAGS)
202 append("-Wno-vla-extension" CMAKE_CXX_FLAGS)
203 endif()
204
205 # Disable MSVC warnings
206 if( MSVC )
207 add_definitions(
208 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
209 -wd4068 # Suppress 'warning C4068: unknown pragma'
210 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
211 -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union'
212 -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'
213 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
214 -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
215 -wd4589 # Suppress 'warning C4589: Constructor of abstract class 'lldb_private::NativeRegisterContextDBReg_x86' ignores initializer for virtual base class 'lldb_private::NativeRegisterContextRegisterInfo''
216 )
217 endif()
218
219 # Use the Unicode (UTF-16) APIs by default on Win32
220 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
221 add_definitions( -D_UNICODE -DUNICODE )
222 endif()
223
224 # If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
225 if(NOT DEFINED LLDB_VERSION_MAJOR)
226 set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
227 endif()
228 if(NOT DEFINED LLDB_VERSION_MINOR)
229 set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR})
230 endif()
231 if(NOT DEFINED LLDB_VERSION_PATCH)
232 set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH})
233 endif()
234 if(NOT DEFINED LLDB_VERSION_SUFFIX)
235 set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
236 endif()
237 set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
238 message(STATUS "LLDB version: ${LLDB_VERSION}")
239
240 if (LLDB_ENABLE_LZMA)
241 include_directories(${LIBLZMA_INCLUDE_DIRS})
242 endif()
243
244 if (LLDB_ENABLE_LIBXML2)
245 include_directories(${LIBXML2_INCLUDE_DIR})
246 endif()
247
248 include_directories(BEFORE
249 ${CMAKE_CURRENT_BINARY_DIR}/include
250 ${CMAKE_CURRENT_SOURCE_DIR}/include
251 )
252
253 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
254 install(DIRECTORY include/
255 COMPONENT lldb-headers
256 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
257 FILES_MATCHING
258 PATTERN "*.h"
259 PATTERN ".cmake" EXCLUDE
260 )
261
262 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
263 COMPONENT lldb-headers
264 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
265 FILES_MATCHING
266 PATTERN "*.h"
267 PATTERN ".cmake" EXCLUDE
268 )
269
270 add_custom_target(lldb-headers)
271 set_target_properties(lldb-headers PROPERTIES FOLDER "LLDB/Resources")
272
273 if (NOT CMAKE_CONFIGURATION_TYPES)
274 add_llvm_install_targets(install-lldb-headers
275 COMPONENT lldb-headers)
276 endif()
277 endif()
278
279 # Find Apple-specific libraries or frameworks that may be needed.
280 if (APPLE)
281 if(NOT APPLE_EMBEDDED)
282 find_library(CARBON_LIBRARY Carbon)
283 find_library(CORE_SERVICES_LIBRARY CoreServices)
284 endif()
285 find_library(FOUNDATION_LIBRARY Foundation)
286 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
287 find_library(SECURITY_LIBRARY Security)
288 include_directories(${LIBXML2_INCLUDE_DIR})
289 endif()
290
291 if( WIN32 AND NOT CYGWIN )
292 set(PURE_WINDOWS 1)
293 endif()
294
295 if(NOT PURE_WINDOWS)
296 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
297 find_package(Threads REQUIRED)
298 endif()
299
300 # Figure out if lldb could use lldb-server. If so, then we'll
301 # ensure we build lldb-server when an lldb target is being built.
302 if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows")
303 set(LLDB_CAN_USE_LLDB_SERVER ON)
304 else()
305 set(LLDB_CAN_USE_LLDB_SERVER OFF)
306 endif()
307
308 # Figure out if lldb could use debugserver. If so, then we'll
309 # ensure we build debugserver when we build lldb.
310 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
311 set(LLDB_CAN_USE_DEBUGSERVER ON)
312 else()
313 set(LLDB_CAN_USE_DEBUGSERVER OFF)
314 endif()
315
316 if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
317 ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
318 add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)
319 endif()
320
321 include(LLDBGenerateConfig)