diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index 77918ebbf2e..cb3b85e19ef 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -69,29 +69,12 @@ function(target_link_options_gc_sections target_name) endif() endfunction() -# Sets the value of the PYTHON_EXECUTABLE variable to 'python' if in an active -# (non-base) conda environment, and 'python3' otherwise. This maintains -# backwards compatibility for non-conda users and avoids conda users needing to -# explicitly set PYTHON_EXECUTABLE=python. function(resolve_python_executable) - # Counter-intuitively, CONDA_DEFAULT_ENV contains the name of the active - # environment. - if(DEFINED ENV{CONDA_DEFAULT_ENV} AND NOT $ENV{CONDA_DEFAULT_ENV} STREQUAL - "base" - ) - set(PYTHON_EXECUTABLE - python - PARENT_SCOPE - ) - elseif(DEFINED ENV{VIRTUAL_ENV}) - set(PYTHON_EXECUTABLE - $ENV{VIRTUAL_ENV}/bin/python3 - PARENT_SCOPE - ) - else() + if(NOT PYTHON_EXECUTABLE) + find_package(Python3 REQUIRED COMPONENTS Interpreter) set(PYTHON_EXECUTABLE - python3 - PARENT_SCOPE + ${Python3_EXECUTABLE} + PARENT_SCOPE ) endif() endfunction()