Skip to content

Commit

Permalink
[cmake] Respect Python virtualenv on macOS
Browse files Browse the repository at this point in the history
Fix issue where CMake ignores the Python interpreter specified by a
virtual environment by default. This results in the generate targets
failing when the Python package requirements are installed in a virtual
environment but the system interpreter is found by CMake.

This patch replaces the use of `CMAKE_FIND_FRAMEWORK` with the more
precise `Python3_FIND_FRAMEWORK`. It also sets the
`Python3_FIND_STRATEGY` to `LOCATION` which stops searching once the
first Python interpreter is found, i.e. the interpreter from an
activated virtual environment, or the system interpreter otherwise.
  • Loading branch information
kbenzie committed Sep 19, 2023
1 parent e40a321 commit 28ac2e1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(helpers)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_FIND_FRAMEWORK NEVER)
set(Python3_FIND_FRAMEWORK NEVER)
set(Python3_FIND_STRATEGY LOCATION)
endif()

find_package(Python3 COMPONENTS Interpreter REQUIRED)
Expand Down

0 comments on commit 28ac2e1

Please sign in to comment.