Until now, on Windows in order to link against Python the user must
manually specify a value for 3 different CMake variables. PYTHON_EXECUTABLE,
PYTHON_LIBRARY, and PYTHON_INCLUDE_DIR. And the user must
manage 4 different sets of values for these variables, depending on whether
he is building debug, release, x86, or x64.
On top of that, the user must update the value of PYTHONHOME and
PYTHONPATH for each of these 4 configurations.
This patch addresses all of these issues. To start with, it deprecates the
three Python CMake variables in favor of a single variable PYTHON_HOME
which points to the root of a python installation. Since building Python from
source doesn't output the files in a structure that is compatible with the
PYTHONHOME environment variable (or the Py_SetPythonHome API), we
also provide a script install_custom_python.py which will copy the output of a
custom python build to the correct directory structure.
Second, it automatically uses the value of PYTHON_HOME as a parameter to
Py_SetPythonHome() on interpreter initialization. Previously this API was not
being called, so Python was attempting to figure out a valid Python home at
runtime, and it was falling back to the system installed Python, which was
leading to errors on x64 builds since it was finding an x86 Python as the system
installed python.
The supported workflow after this patch will be to build python once for each
configuration and architecture {Debug,Release} x {x86,x64} and then run the script.
Then run CMake specifying -DPYTHON_HOME=<path>. The first time you do
this will probably require you to delete your CMake cache first.
The old workflow is still supported during a transitionary period, but a warning is
printed at CMake time, and this will eventually be removed.