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