Windows / Find_Python / Python_USE_ABI problems

CMake 3.20 from MSVC, building on Windows, with Python 3.9 and 3.10 installed as (C:/Python39, eg), complete with dev and debug binaries/etc.

It can find Python OK unless I specify FIND_ABI "OFF" "ANY" "ANY".

Unfortunately, the Debug lib/dll are incompatible with compiled modules like psutil, numpy, cython, etc (try using python_d -m pip install psutil then try import psutil from release python).

CMAKE_MINIMUM_REQUIRED(VERSION 3.18)
PROJECT(CMakeTest)
LIST(INSERT CMAKE_PREFIX_PATH 0 "C:\\Python39")
SET(Python_IMPLEMENTATIONS      CPython)
IF (USE_FIND_ABI)
        SET(Python_FIND_ABI "OFF" "ANY" "ANY")
ENDIF ()
FIND_PACKAGE(Python 3.9.7 EXACT REQUIRED COMPONENTS Development.Embed)

I can do:

> cmake -B build -DUSE_FIND_ABI=OFF -DCMAKE_BUILD_TYPE=Release

works ok, but

> cmake -B build -DUSE_FIND_ABI=ON -DCMAKE_BUILD_TYPE=Debug
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python (missing: Development.Embed) (found suitable exact
  version "3.9.7")
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPython/Support.cmake:3165 (find_package_handle_standard_args)
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPython.cmake:514 (include)
  CMakeLists.txt:10 (FIND_PACKAGE)


-- Configuring incomplete, errors occurred!

The CMakeOutput.log only contains information about identifying the compiler, nothing at all about looking for Python, and I could not find a way to surface the Python_REASON_FAILURE variable or its friends.

As specified in the documentation of FindPython in the note at the end of the description of this HINT, Python_FIND_ABI is not usable for distributions from python.org, except if specifying ANY for all three parameters. Where comes from your python environment?

Anyway, on Windows, both versions are searched. The target Python::Python or the variable Python_LIBRARIES can be used with Debug and Release compilations. The right version of the library will be selected.

Well, duh-on-me. Turns out, just repacked binaries from python.org. :frowning: