[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / lldb / cmake / modules / LLDBConfig.cmake
blobce5e666a6f5e1ac1dc061f248cc8a69cf2e0141d
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 ((NOT MSVC) OR MSVC12)
132   add_definitions( -DHAVE_ROUND )
133 endif()
135 # Check if we libedit capable of handling wide characters (built with
136 # '--enable-widec').
137 if (LLDB_ENABLE_LIBEDIT)
138   set(CMAKE_REQUIRED_LIBRARIES ${LibEdit_LIBRARIES})
139   set(CMAKE_REQUIRED_INCLUDES ${LibEdit_INCLUDE_DIRS})
140   check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
141   set(CMAKE_EXTRA_INCLUDE_FILES histedit.h)
142   check_type_size(el_rfunc_t LLDB_EL_RFUNC_T_SIZE)
143   if (LLDB_EL_RFUNC_T_SIZE STREQUAL "")
144     set(LLDB_HAVE_EL_RFUNC_T 0)
145   else()
146     set(LLDB_HAVE_EL_RFUNC_T 1)
147   endif()
148   set(CMAKE_REQUIRED_LIBRARIES)
149   set(CMAKE_REQUIRED_INCLUDES)
150   set(CMAKE_EXTRA_INCLUDE_FILES)
151 endif()
153 if (LLDB_ENABLE_PYTHON)
154   if(CMAKE_SYSTEM_NAME MATCHES "Windows")
155     set(default_embed_python_home ON)
156   else()
157     set(default_embed_python_home OFF)
158   endif()
159   option(LLDB_EMBED_PYTHON_HOME
160     "Embed PYTHONHOME in the binary. If set to OFF, PYTHONHOME environment variable will be used to to locate Python."
161     ${default_embed_python_home})
163   include_directories(${Python3_INCLUDE_DIRS})
164   if (LLDB_EMBED_PYTHON_HOME)
165     get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
166     set(LLDB_PYTHON_HOME "${PYTHON_HOME}" CACHE STRING
167       "Path to use as PYTHONHOME in lldb. If a relative path is specified, it will be resolved at runtime relative to liblldb directory.")
168   endif()
169 endif()
171 if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
172   include_directories(${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
173 else ()
174   include_directories(${CMAKE_SOURCE_DIR}/tools/clang/include)
175 endif ()
176 include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
178 # GCC silently accepts any -Wno-<foo> option, but warns about those options
179 # being unrecognized only if the compilation triggers other warnings to be
180 # printed. Therefore, check for whether the compiler supports options in the
181 # form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
183 # Disable GCC warnings
184 check_cxx_compiler_flag("-Wdeprecated-declarations" CXX_SUPPORTS_DEPRECATED_DECLARATIONS)
185 append_if(CXX_SUPPORTS_DEPRECATED_DECLARATIONS "-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
187 check_cxx_compiler_flag("-Wunknown-pragmas" CXX_SUPPORTS_UNKNOWN_PRAGMAS)
188 append_if(CXX_SUPPORTS_UNKNOWN_PRAGMAS "-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
190 check_cxx_compiler_flag("-Wstrict-aliasing" CXX_SUPPORTS_STRICT_ALIASING)
191 append_if(CXX_SUPPORTS_STRICT_ALIASING "-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
193 check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)
194 append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)
196 # Disable Clang warnings
197 check_cxx_compiler_flag("-Wdeprecated-register" CXX_SUPPORTS_DEPRECATED_REGISTER)
198 append_if(CXX_SUPPORTS_DEPRECATED_REGISTER "-Wno-deprecated-register" CMAKE_CXX_FLAGS)
200 check_cxx_compiler_flag("-Wvla-extension" CXX_SUPPORTS_VLA_EXTENSION)
201 append_if(CXX_SUPPORTS_VLA_EXTENSION "-Wno-vla-extension" CMAKE_CXX_FLAGS)
203 # Disable MSVC warnings
204 if( MSVC )
205   add_definitions(
206     -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
207     -wd4068 # Suppress 'warning C4068: unknown pragma'
208     -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
209     -wd4201 # Suppress 'warning C4201: nonstandard extension used: nameless struct/union'
210     -wd4251 # Suppress 'warning C4251: T must have dll-interface to be used by clients of class U.'
211     -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
212     -wd4530 # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
213   )
214 endif()
216 # Use the Unicode (UTF-16) APIs by default on Win32
217 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
218     add_definitions( -D_UNICODE -DUNICODE )
219 endif()
221 # If LLDB_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
222 if(NOT DEFINED LLDB_VERSION_MAJOR)
223   set(LLDB_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
224 endif()
225 if(NOT DEFINED LLDB_VERSION_MINOR)
226   set(LLDB_VERSION_MINOR ${LLVM_VERSION_MINOR})
227 endif()
228 if(NOT DEFINED LLDB_VERSION_PATCH)
229   set(LLDB_VERSION_PATCH ${LLVM_VERSION_PATCH})
230 endif()
231 if(NOT DEFINED LLDB_VERSION_SUFFIX)
232   set(LLDB_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
233 endif()
234 set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
235 message(STATUS "LLDB version: ${LLDB_VERSION}")
237 if (LLDB_ENABLE_LZMA)
238   include_directories(${LIBLZMA_INCLUDE_DIRS})
239 endif()
241 if (LLDB_ENABLE_LIBXML2)
242   include_directories(${LIBXML2_INCLUDE_DIR})
243 endif()
245 include_directories(BEFORE
246   ${CMAKE_CURRENT_BINARY_DIR}/include
247   ${CMAKE_CURRENT_SOURCE_DIR}/include
248   )
250 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
251   install(DIRECTORY include/
252     COMPONENT lldb-headers
253     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
254     FILES_MATCHING
255     PATTERN "*.h"
256     PATTERN ".cmake" EXCLUDE
257     )
259   install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
260     COMPONENT lldb-headers
261     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
262     FILES_MATCHING
263     PATTERN "*.h"
264     PATTERN ".cmake" EXCLUDE
265     )
267   add_custom_target(lldb-headers)
268   set_target_properties(lldb-headers PROPERTIES FOLDER "lldb misc")
270   if (NOT CMAKE_CONFIGURATION_TYPES)
271     add_llvm_install_targets(install-lldb-headers
272                              COMPONENT lldb-headers)
273   endif()
274 endif()
276 # Find Apple-specific libraries or frameworks that may be needed.
277 if (APPLE)
278   if(NOT APPLE_EMBEDDED)
279     find_library(CARBON_LIBRARY Carbon)
280     find_library(CORE_SERVICES_LIBRARY CoreServices)
281   endif()
282   find_library(FOUNDATION_LIBRARY Foundation)
283   find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
284   find_library(SECURITY_LIBRARY Security)
285   include_directories(${LIBXML2_INCLUDE_DIR})
286 endif()
288 if( WIN32 AND NOT CYGWIN )
289   set(PURE_WINDOWS 1)
290 endif()
292 if(NOT PURE_WINDOWS)
293   set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
294   find_package(Threads REQUIRED)
295 endif()
297 # Figure out if lldb could use lldb-server.  If so, then we'll
298 # ensure we build lldb-server when an lldb target is being built.
299 if (CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|FreeBSD|Linux|NetBSD|Windows")
300   set(LLDB_CAN_USE_LLDB_SERVER ON)
301 else()
302   set(LLDB_CAN_USE_LLDB_SERVER OFF)
303 endif()
305 # Figure out if lldb could use debugserver.  If so, then we'll
306 # ensure we build debugserver when we build lldb.
307 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
308     set(LLDB_CAN_USE_DEBUGSERVER ON)
309 else()
310     set(LLDB_CAN_USE_DEBUGSERVER OFF)
311 endif()
313 if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
314     ((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
315   add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)
316 endif()
318 include(LLDBGenerateConfig)