Skip to content

Commit fc6f15d

Browse files
committed
[lldb/CMake] Only auto-enable Python when SWIG is found
As correctly pointed out by Martin on the mailing list, Python should only be auto-enabled if SWIG is found as well. This moves the logic of finding SWIG into FindPythonInterpAndLibs to make that possible. To make diagnosing easier I've included a status message to convey why Python support is disabled.
1 parent adee645 commit fc6f15d

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

lldb/cmake/modules/FindPythonInterpAndLibs.cmake

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,47 @@
44
#
55
# Find the python interpreter and libraries as a whole.
66

7-
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE)
7+
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS AND PYTHON_EXECUTABLE AND SWIG_EXECUTABLE)
88
set(PYTHONINTERPANDLIBS_FOUND TRUE)
99
else()
10-
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
11-
find_package(Python3 COMPONENTS Interpreter Development QUIET)
12-
if (Python3_FOUND AND Python3_Interpreter_FOUND)
13-
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
14-
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
15-
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
16-
mark_as_advanced(
17-
PYTHON_LIBRARIES
18-
PYTHON_INCLUDE_DIRS
19-
PYTHON_EXECUTABLE)
20-
endif()
21-
else()
22-
find_package(PythonInterp QUIET)
23-
find_package(PythonLibs QUIET)
24-
if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND)
25-
if (NOT CMAKE_CROSSCOMPILING)
26-
string(REPLACE "." ";" pythonlibs_version_list ${PYTHONLIBS_VERSION_STRING})
27-
list(GET pythonlibs_version_list 0 pythonlibs_major)
28-
list(GET pythonlibs_version_list 1 pythonlibs_minor)
10+
find_package(SWIG 2.0 QUIET)
11+
if (SWIG_FOUND)
12+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
13+
find_package(Python3 COMPONENTS Interpreter Development QUIET)
14+
if (Python3_FOUND AND Python3_Interpreter_FOUND)
15+
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
16+
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
17+
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
18+
mark_as_advanced(
19+
PYTHON_LIBRARIES
20+
PYTHON_INCLUDE_DIRS
21+
PYTHON_EXECUTABLE
22+
SWIG_EXECUTABLE)
23+
endif()
24+
else()
25+
find_package(PythonInterp QUIET)
26+
find_package(PythonLibs QUIET)
27+
if(PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND)
28+
if (NOT CMAKE_CROSSCOMPILING)
29+
string(REPLACE "." ";" pythonlibs_version_list ${PYTHONLIBS_VERSION_STRING})
30+
list(GET pythonlibs_version_list 0 pythonlibs_major)
31+
list(GET pythonlibs_version_list 1 pythonlibs_minor)
2932

30-
# Ignore the patch version. Some versions of macOS report a different
31-
# patch version for the system provided interpreter and libraries.
32-
if (CMAKE_CROSSCOMPILING OR (PYTHON_VERSION_MAJOR VERSION_EQUAL pythonlibs_major AND
33-
PYTHON_VERSION_MINOR VERSION_EQUAL pythonlibs_minor))
34-
mark_as_advanced(
35-
PYTHON_LIBRARIES
36-
PYTHON_INCLUDE_DIRS
37-
PYTHON_EXECUTABLE)
33+
# Ignore the patch version. Some versions of macOS report a different
34+
# patch version for the system provided interpreter and libraries.
35+
if (CMAKE_CROSSCOMPILING OR (PYTHON_VERSION_MAJOR VERSION_EQUAL pythonlibs_major AND
36+
PYTHON_VERSION_MINOR VERSION_EQUAL pythonlibs_minor))
37+
mark_as_advanced(
38+
PYTHON_LIBRARIES
39+
PYTHON_INCLUDE_DIRS
40+
PYTHON_EXECUTABLE
41+
SWIG_EXECUTABLE)
42+
endif()
3843
endif()
3944
endif()
4045
endif()
46+
else()
47+
message(STATUS "SWIG 2 or later is required for Python support in LLDB but could not be found")
4148
endif()
4249

4350
include(FindPackageHandleStandardArgs)
@@ -47,5 +54,6 @@ else()
4754
REQUIRED_VARS
4855
PYTHON_LIBRARIES
4956
PYTHON_INCLUDE_DIRS
50-
PYTHON_EXECUTABLE)
57+
PYTHON_EXECUTABLE
58+
SWIG_EXECUTABLE)
5159
endif()

lldb/scripts/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ if(LLDB_BUILD_FRAMEWORK)
1515
set(framework_arg --framework --target-platform Darwin)
1616
endif()
1717

18-
find_package(SWIG REQUIRED)
19-
set(SWIG_MIN_VERSION "2.0.0")
20-
if (${SWIG_VERSION} VERSION_LESS ${SWIG_MIN_VERSION})
21-
message(FATAL_ERROR "LLDB requires swig ${SWIG_MIN_VERSION}, your version is ${SWIG_VERSION}.")
22-
endif()
23-
2418
if(APPLE)
2519
set(DARWIN_EXTRAS "-D__APPLE__")
2620
else()
@@ -38,7 +32,6 @@ set(SWIG_COMMON_FLAGS
3832
-outdir ${CMAKE_CURRENT_BINARY_DIR}
3933
)
4034

41-
4235
if (LLDB_ENABLE_PYTHON)
4336
add_custom_command(
4437
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp

0 commit comments

Comments
 (0)