From e664f4aa7b06e1bf78283773c0b1f7dc4cc61674 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 9 May 2023 21:56:07 -0400 Subject: [PATCH] CMake: fix find_package(Python) when inactive pyenv Python installations are present `find_package(Python)`'s default behavior is to attempt to use any `python3.x` executables it finds before `python3`. This is problematic when using tools such as pyenv, where `python3.x` executables may be present in a user's PATH but not be functional. Setting the `Python_FIND_UNVERSIONED_NAMES` hint to `FIRST` causes `python3` to be attempted first, if it exists. Note that this option was introduced in CMake 3.20: https://cmake.org/cmake/help/latest/module/FindPython.html#hints --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4228f45cd..6d1d4c562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,6 +376,9 @@ endif() #### expose depends #### +# fix for pyenv: default to `python3` before `python3.x` +set(Python_FIND_UNVERSIONED_NAMES FIRST) + if(UNIX) # Rescan for pthread and zlib if the build arch changed if(NOT "${DFHACK_BUILD_ARCH}" STREQUAL "${DFHACK_BUILD_ARCH_PREV}")