Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions tools/cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading