Skip to content

Commit 78fe7ee

Browse files
authored
Define PYTHON_EXECUTABLE only once in cmake (#10911)
### Summary There is no need to redefine this over and over again. Do it once at the root. Lmk if I'm missing something: ``` $ rg -t cmake -g '!examples' "resolve_python" $ rg -t cmake -g '!examples' "NOT PYTHON_EXECUTABLE" $ rg -t cmake -g '!examples' "python3" $ rg -t cmake -g '!examples' "python\s" ``` ### Test plan CI cc @larryliu0820
1 parent 24789c8 commit 78fe7ee

File tree

20 files changed

+17
-74
lines changed

20 files changed

+17
-74
lines changed

CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ project(executorch)
4848
# MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION --------------------------------------------------
4949

5050
include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake)
51+
include(${PROJECT_SOURCE_DIR}/tools/cmake/Utils.cmake)
52+
include(CMakeDependentOption)
53+
include(ExternalProject)
5154

5255
if(NOT CMAKE_CXX_STANDARD)
5356
set(CMAKE_CXX_STANDARD 17)
@@ -64,10 +67,14 @@ if(NOT CMAKE_BUILD_TYPE)
6467
endif()
6568
announce_configured_options(CMAKE_BUILD_TYPE)
6669

70+
if(NOT PYTHON_EXECUTABLE)
71+
resolve_python_executable()
72+
endif()
73+
announce_configured_options(PYTHON_EXECUTABLE)
74+
6775
announce_configured_options(CMAKE_CXX_COMPILER_ID)
6876
announce_configured_options(CMAKE_TOOLCHAIN_FILE)
6977
announce_configured_options(BUCK2)
70-
announce_configured_options(PYTHON_EXECUTABLE)
7178

7279
load_build_preset()
7380
include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
@@ -77,10 +84,6 @@ print_configured_options()
7784

7885
# MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ----------------------------------------------------
7986

80-
include(tools/cmake/Utils.cmake)
81-
include(CMakeDependentOption)
82-
include(ExternalProject)
83-
8487
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
8588

8689
# Setup RPATH.
@@ -256,11 +259,6 @@ if(EXECUTORCH_BUILD_TESTS)
256259
include(CTest)
257260
endif()
258261

259-
if(NOT PYTHON_EXECUTABLE)
260-
resolve_python_executable()
261-
endif()
262-
message(STATUS "Using python executable '${PYTHON_EXECUTABLE}'")
263-
264262
# TODO(dbort): Fix these warnings and remove this flag.
265263
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
266264

backends/apple/mps/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ endif()
1818

1919
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2020

21-
if(NOT PYTHON_EXECUTABLE)
22-
resolve_python_executable()
23-
endif()
24-
2521
set(_common_compile_options -Wno-deprecated-declarations)
2622
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
2723

backends/cadence/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
3030
if(EXECUTORCH_CADENCE_CPU_RUNNER)
3131
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
3232

33-
if(NOT PYTHON_EXECUTABLE)
34-
resolve_python_executable()
35-
endif()
36-
3733
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
3834

3935
# Find prebuilt libraries. executorch package should contain portable_ops_lib,

backends/cadence/fusion_g3/operators/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ endif()
1414
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1515
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
1616

17-
if(NOT PYTHON_EXECUTABLE)
18-
resolve_python_executable()
19-
endif()
20-
2117
# ATen compliant ops that are needed to run this model.
2218
set(_aten_ops__srcs
2319
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/activation_ops_util.cpp"

backends/cadence/hifi/operators/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ endif()
1414
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1515
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
1616

17-
if(NOT PYTHON_EXECUTABLE)
18-
resolve_python_executable()
19-
endif()
20-
2117
# ATen compliant ops that are needed to run this model.
2218
set(_aten_ops__srcs
2319
"${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_add.cpp"

backends/cadence/reference/operators/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ endif()
1414
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1515
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
1616

17-
if(NOT PYTHON_EXECUTABLE)
18-
resolve_python_executable()
19-
endif()
20-
2117
# ATen compliant ops that are needed to run this model.
2218
set(_aten_ops__srcs
2319
"${CMAKE_CURRENT_SOURCE_DIR}/op_add.cpp"

backends/cortex_m/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ endif()
2323
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2424
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
2525

26-
if(NOT PYTHON_EXECUTABLE)
27-
resolve_python_executable()
28-
endif()
29-
3026
# Cortex-M ops kernel sources
3127
set(_cortex_m_kernels__srcs
3228
${CMAKE_CURRENT_SOURCE_DIR}/ops/op_quantize_per_tensor.cpp

backends/vulkan/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ if(NOT RUNTIME_PATH)
2424
set(RUNTIME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/runtime)
2525
endif()
2626

27-
if(NOT PYTHON_EXECUTABLE)
28-
set(PYTHON_EXECUTABLE python3)
29-
endif()
30-
3127
# Include this file to access target_link_options_shared_lib This is required to
3228
# provide access to target_link_options_shared_lib which allows libraries to be
3329
# linked with the --whole-archive flag. This is required for libraries that

backends/vulkan/test/op_tests/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ find_library(LIB_TORCH torch HINTS ${TORCH_INSTALL_PREFIX}/lib)
4545
find_library(LIB_TORCH_CPU torch_cpu HINTS ${TORCH_INSTALL_PREFIX}/lib)
4646
find_library(LIB_C10 c10 HINTS ${TORCH_INSTALL_PREFIX}/lib)
4747

48-
if(NOT PYTHON_EXECUTABLE)
49-
set(PYTHON_EXECUTABLE python3)
50-
endif()
51-
5248
# Third party include paths
5349

5450
set(VULKAN_THIRD_PARTY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party)

backends/xnnpack/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ endif()
2525

2626
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2727

28-
if(NOT PYTHON_EXECUTABLE)
29-
resolve_python_executable()
30-
endif()
31-
3228
# NB: Enabling this will serialize execution of delegate instances Keeping this
3329
# OFF by default to maintain existing behavior, to be revisited.
3430
option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE

0 commit comments

Comments
 (0)