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