FindPython: relative `SITE{LIB,ARCH}` variables for `install(... DESTINATION ...)`
Hello @marc.chevrier (and others!),
I'd like to request a feature.
When building Python extension with CMake, I'd like to be able to install the extension using a relative path like GNUInstallDirs provides.
GNUInstallDirs has 2 kinds of variables:
CMAKE_INSTALL_<dir>
CMAKE_INSTALL_FULL_<dir>
The first variant is useful for use in install(... DESTINATION ...)
.
And the variable can usually be override from outside, e.g. -DCMAKE_INSTALL_LIBDIR=lib
.
I'd like to have an equivalent variable(s) to install python packages/modules. Right now, there is:
Python_SITELIB
Python_SITEARCH
See https://cmake.org/cmake/help/v3.25/module/FindPython.html?highlight=findpython#result-variables.
These are similar to CMAKE_INSTALL_FULL_<dir>
but there is no CMAKE_INSTALL_<dir>
equivalent.
It it would be useful to have 2 variables (not convinced by these proposed names), e.g.:
-
Python_INSTALL_SITELIB
: e.g. expands tolib/python3.10/site-packages
on Linux -
Python_INSTALL_SITEARCH
: e.g. expands tolib/python3.10/site-packages
on Linux
It would be useful to be able to override it from the CMake command line too, e.g. -DPython_INSTALL_SITELIB=python
.
The value for these variables can be obtained by specifying prefix=''
to the site query functions, e.g.:
>>> from distutils import sysconfig as s
>>> s.get_python_lib(plat_specific=True, prefix='')
'lib/python3.10/site-packages'
Does this feature make sense?
With the recent ABI3 support, this is the remaining not portable part of my CMakeLists.txt (well, that and a function to probe if a python module is available, e.g. pytest
).