Skip to content

Commit 2e922e0

Browse files
committed
[build] refactor Python detection code
Move detection of Python code into dedicate CMake module, so it can be reused for workflows that do not rely on reading the main `CMakeLists.txt`. Builds upon #30992, #31020 Addresses rdar://62245784 (cherry picked from commit 7bc15b8)
1 parent e8c3927 commit 2e922e0

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
892892
endif()
893893
endif()
894894

895-
find_package(Python2 COMPONENTS Interpreter REQUIRED)
896-
find_package(Python3 COMPONENTS Interpreter)
897-
if(NOT Python3_Interpreter_FOUND)
898-
message(WARNING "Python3 not found, using python2 as a fallback")
899-
add_executable(Python3::Interpreter IMPORTED)
900-
set_target_properties(Python3::Interpreter PROPERTIES
901-
IMPORTED_LOCATION ${Python2_EXECUTABLE})
902-
endif()
895+
include(FindPython)
903896

904897
#
905898
# Find optional dependencies.

cmake/modules/FindPython.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
find_package(Python2 COMPONENTS Interpreter REQUIRED)
2+
find_package(Python3 COMPONENTS Interpreter)
3+
if(NOT Python3_Interpreter_FOUND)
4+
message(WARNING "Python3 not found, using python2 as a fallback")
5+
add_executable(Python3::Interpreter IMPORTED)
6+
set_target_properties(Python3::Interpreter PROPERTIES
7+
IMPORTED_LOCATION ${Python2_EXECUTABLE})
8+
endif()

cmake/modules/StandaloneOverlay.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ include(SwiftHandleGybSources)
114114
include(SwiftConfigureSDK)
115115
include(SwiftComponents)
116116
include(DarwinSDKs)
117+
include(FindPython)
117118

118119

119120
# Without this line, installing components is broken. This needs refactoring.

0 commit comments

Comments
 (0)