Skip to content

Commit 41d7c22

Browse files
committed
[lldb/CMake] Change how we deal with optional dependencies
Recently there has been some discussion about how we deal with optional dependencies in LLDB. The approach in LLVM is to make things work out of the box. If the dependency isn't there, we move on silently. That's not true for LLDB. Unless you explicitly disable the dependency with LLDB_ENABLE_*, you'll get a configuration-time error. The historical reason for this is that LLDB's dependencies have a much broader impact, think about Python for example which is required to run the test suite. The current approach can be frustrating from a user experience perspective. Sometimes you just want to ensure LLDB builds with a change in clang. This patch changes the optional dependencies (with the exception of Python) to a new scheme. The LLDB_ENABLE_* now takes three values: On, Off or Auto, with the latter being the default. On and Off behave the same as today, forcing the dependency to be enabled or disabled. If the dependency is set to On but is not found, it results in a configuration time warning. For Auto we detect if the dependency is there and either enable or disable it depending on whether it's found. Differential revision: https://reviews.llvm.org/D71306 PS: The reason Python isn't included yet is because it's so pervasive that I plan on doing that in a separate patch.
1 parent d1783db commit 41d7c22

File tree

3 files changed

+47
-44
lines changed

3 files changed

+47
-44
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#.rst:
2+
# FindCursesAndPanel
3+
# -----------
4+
#
5+
# Find the curses and panel library as a whole.
6+
7+
if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
8+
set(CURSES_PANEL_FOUND TRUE)
9+
else()
10+
find_package(Curses QUIET)
11+
find_library(PANEL_LIBRARIES NAMES panel DOC "The curses panel library" QUIET)
12+
if(CURSES_FOUND AND PANEL_LIBRARIES)
13+
mark_as_advanced(CURSES_INCLUDE_DIRS CURSES_LIBRARIES PANEL_LIBRARIES)
14+
endif()
15+
endif()
16+

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,43 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
1818
"`CMakeFiles'. Please delete them.")
1919
endif()
2020

21-
set(default_enable_python ON)
22-
set(default_enable_lua OFF) # Experimental
23-
set(default_enable_libedit ON)
24-
set(default_enable_curses ON)
25-
26-
# Temporarily support the old LLDB_DISABLE_* variables
27-
if (DEFINED LLDB_DISABLE_PYTHON)
28-
if (LLDB_DISABLE_PYTHON)
29-
set(default_enable_python OFF)
30-
endif()
21+
set(LLDB_LINKER_SUPPORTS_GROUPS OFF)
22+
if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
23+
# The Darwin linker doesn't understand --start-group/--end-group.
24+
set(LLDB_LINKER_SUPPORTS_GROUPS ON)
3125
endif()
3226

33-
if(DEFINED LLVM_ENABLE_LIBEDIT AND NOT LLVM_ENABLE_LIBEDIT)
34-
set(default_disable_libedit ON)
35-
endif()
27+
function(add_optional_dependency variable description package found)
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(maybe_required)
33+
elseif(${${variable}})
34+
set(maybe_required REQUIRED)
35+
else()
36+
set(${variable} OFF PARENT_SCOPE)
37+
return()
38+
endif()
39+
40+
find_package(${package} ${maybe_required})
41+
set(${variable} ${${found}} PARENT_SCOPE)
42+
endfunction()
43+
44+
add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support." LibEdit libedit_FOUND)
45+
add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support." CursesAndPanel CURSES_PANEL_FOUND)
46+
add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support." LibLZMA LIBLZMA_FOUND)
47+
add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support." Lua LUA_FOUND)
3648

37-
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
38-
set(default_enable_libedit OFF)
39-
set(default_enable_curses OFF)
40-
elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
49+
set(default_enable_python ON)
50+
51+
if(CMAKE_SYSTEM_NAME MATCHES "Android")
4152
set(default_enable_python OFF)
42-
set(default_enable_lua OFF)
43-
set(default_enable_libedit OFF)
44-
set(default_enable_curses OFF)
4553
elseif(IOS)
4654
set(default_enable_python OFF)
47-
set(default_enable_lua OFF)
4855
endif()
4956

5057
option(LLDB_ENABLE_PYTHON "Enable Python scripting integration." ${default_enable_python})
51-
option(LLDB_ENABLE_PYTHON "Enable Lua scripting integration." ${default_enable_lua})
52-
option(LLDB_ENABLE_LIBEDIT "Enable the use of editline." ${default_enable_libedit})
53-
option(LLDB_ENABLE_CURSES "Enable Curses integration." ${default_enable_curses})
5458
option(LLDB_RELOCATABLE_PYTHON "Use the PYTHONHOME environment variable to locate Python." OFF)
5559
option(LLDB_USE_SYSTEM_SIX "Use six.py shipped with system and do not install a copy of it" OFF)
5660
option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
@@ -113,15 +117,9 @@ if ((NOT MSVC) OR MSVC12)
113117
add_definitions( -DHAVE_ROUND )
114118
endif()
115119

116-
if (LLDB_ENABLE_LUA)
117-
find_package(Lua REQUIRED)
118-
endif()
119-
120+
# Check if we libedit capable of handling wide characters (built with
121+
# '--enable-widec').
120122
if (LLDB_ENABLE_LIBEDIT)
121-
find_package(LibEdit REQUIRED)
122-
123-
# Check if we libedit capable of handling wide characters (built with
124-
# '--enable-widec').
125123
set(CMAKE_REQUIRED_LIBRARIES ${libedit_LIBRARIES})
126124
set(CMAKE_REQUIRED_INCLUDES ${libedit_INCLUDE_DIRS})
127125
check_symbol_exists(el_winsertstr histedit.h LLDB_EDITLINE_USE_WCHAR)
@@ -137,7 +135,6 @@ if (LLDB_ENABLE_LIBEDIT)
137135
set(CMAKE_EXTRA_INCLUDE_FILES)
138136
endif()
139137

140-
141138
# On Windows, we can't use the normal FindPythonLibs module that comes with CMake,
142139
# for a number of reasons.
143140
# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself was
@@ -398,12 +395,9 @@ endif()
398395
set(LLDB_VERSION "${LLDB_VERSION_MAJOR}.${LLDB_VERSION_MINOR}.${LLDB_VERSION_PATCH}${LLDB_VERSION_SUFFIX}")
399396
message(STATUS "LLDB version: ${LLDB_VERSION}")
400397

401-
find_package(LibLZMA)
402-
cmake_dependent_option(LLDB_ENABLE_LZMA "Support LZMA compression" ON "LIBLZMA_FOUND" OFF)
403398
if (LLDB_ENABLE_LZMA)
404399
include_directories(${LIBLZMA_INCLUDE_DIRS})
405400
endif()
406-
llvm_canonicalize_cmake_booleans(LLDB_ENABLE_LZMA)
407401

408402
include_directories(BEFORE
409403
${CMAKE_CURRENT_BINARY_DIR}/include
@@ -493,14 +487,6 @@ else()
493487
set(LLDB_CAN_USE_DEBUGSERVER OFF)
494488
endif()
495489

496-
if (LLDB_ENABLE_CURSES)
497-
find_package(Curses REQUIRED)
498-
find_library(CURSES_PANEL_LIBRARY NAMES panel DOC "The curses panel library")
499-
if (NOT CURSES_PANEL_LIBRARY)
500-
message(FATAL_ERROR "A required curses' panel library not found.")
501-
endif ()
502-
endif ()
503-
504490
if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC AND
505491
((ANDROID_ABI MATCHES "armeabi") OR (ANDROID_ABI MATCHES "mips")))
506492
add_definitions(-DANDROID_USE_ACCEPT_WORKAROUND)

lldb/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ endif()
145145
llvm_canonicalize_cmake_booleans(
146146
LLDB_ENABLE_PYTHON
147147
LLDB_ENABLE_LUA
148+
LLDB_ENABLE_LZMA
148149
LLVM_ENABLE_ZLIB
149150
LLVM_ENABLE_SHARED_LIBS
150151
LLDB_IS_64_BITS)

0 commit comments

Comments
 (0)