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

configurations/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

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

extension/flat_tensor/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_custom_command(
2222
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
2323
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2424
COMMAND
25-
python -m test.models.export_program --modules "ModuleAddMul"
25+
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
2626
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
2727
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2828
)

extension/llm/custom_ops/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ if(NOT CMAKE_CXX_STANDARD)
1111
set(CMAKE_CXX_STANDARD 17)
1212
endif()
1313

14-
if(NOT PYTHON_EXECUTABLE)
15-
set(PYTHON_EXECUTABLE python3)
16-
endif()
17-
1814
# Source root directory for executorch.
1915
if(NOT EXECUTORCH_ROOT)
2016
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

extension/module/test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ add_custom_command(
2424
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
2525
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2626
COMMAND
27-
python3 -m test.models.export_program --modules "ModuleAdd"
27+
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAdd"
2828
--outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
2929
COMMAND
30-
python3 -m test.models.export_program --modules "ModuleAddMul"
30+
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
3131
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
3232
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
3333
)

extension/runner_util/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include(${EXECUTORCH_ROOT}/tools/cmake/Test.cmake)
1919

2020
add_custom_command(
2121
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
22-
COMMAND python3 -m test.models.export_program --modules "ModuleAdd" --outdir
22+
COMMAND ${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAdd" --outdir
2323
"${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
2424
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2525
)

kernels/optimized/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ list(APPEND _common_compile_options -DET_BUILD_WITH_BLAS)
3636
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
3737
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
3838

39-
if(NOT PYTHON_EXECUTABLE)
40-
resolve_python_executable()
41-
endif()
4239
# Build cpublas.
4340
list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/")
4441
add_library(cpublas STATIC ${_optimized_cpublas__srcs})

kernels/portable/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ set(_common_compile_options -Wno-deprecated-declarations)
2626
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2727
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
2828

29-
if(NOT PYTHON_EXECUTABLE)
30-
resolve_python_executable()
31-
endif()
32-
3329
# Portable kernel sources TODO(larryliu0820): use buck2 to gather the sources
3430
file(GLOB_RECURSE _portable_kernels__srcs
3531
"${CMAKE_CURRENT_SOURCE_DIR}/cpu/*.cpp"

kernels/quantized/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ set(_common_compile_options -Wno-deprecated-declarations)
2929
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
3030
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
3131

32-
if(NOT PYTHON_EXECUTABLE)
33-
resolve_python_executable()
34-
endif()
35-
3632
# Quantized ops kernel sources TODO(larryliu0820): use buck2 to gather the
3733
# sources
3834
list(TRANSFORM _quantized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")

kernels/test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ foreach(kernel ${_kernels})
4242
"${_wrapper_dir}/supported_features.h"
4343
COMMAND mkdir -p ${_wrapper_dir}
4444
COMMAND
45-
python kernels/test/gen_supported_features.py
45+
${PYTHON_EXECUTABLE} kernels/test/gen_supported_features.py
4646
kernels/${kernel}/test/supported_features_def.yaml >
4747
${_wrapper_dir}/supported_features.cpp
4848
COMMAND
49-
python kernels/test/gen_supported_features.py
49+
${PYTHON_EXECUTABLE} kernels/test/gen_supported_features.py
5050
kernels/test/supported_features.yaml >
5151
${_wrapper_dir}/supported_features.h
5252
WORKING_DIRECTORY "${EXECUTORCH_ROOT}"

runtime/executor/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ add_custom_command(
3030
"${CMAKE_CURRENT_BINARY_DIR}/ModuleStateful.pte"
3131
"${CMAKE_CURRENT_BINARY_DIR}/delegated/ModuleAddMul.pte"
3232
COMMAND
33-
python3 -m test.models.export_program --modules
33+
${PYTHON_EXECUTABLE} -m test.models.export_program --modules
3434
"ModuleAdd,ModuleAddHalf,ModuleAddMul,ModuleDynamicCatUnallocatedIO,ModuleIndex,ModuleMultipleEntry,ModuleSimpleTrain,ModuleStateful"
3535
--outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
3636
COMMAND
37-
python3 -m test.models.export_program --modules "ModuleAddMul"
37+
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
3838
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
3939
COMMAND
40-
python3 -m test.models.export_delegated_program --modules "ModuleAddMul"
40+
${PYTHON_EXECUTABLE} -m test.models.export_delegated_program --modules "ModuleAddMul"
4141
--backend_id "StubBackend" --outdir "${CMAKE_CURRENT_BINARY_DIR}/delegated/" || true
4242
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
4343
)

0 commit comments

Comments
 (0)