Yes that is the issue want to fix as well, to install python module targets with a relative DESTINATION
directory for use with the install
command.
I want these directories to have a good defaults but to also be overridable from the command line, like dirs from GNUInstallDirs.
Taking your PR as an example, I want to be able to use the proposed variables to do:
install(
TARGETS nvdiffrast_plugin nvdiffrast_plugin_gl
COMPONENT python
DESTINATION ${Python_INSTALL_SITEARCH}/nvdiffrast)
install(
FILES nvdiffrast/__init__.py
COMPONENT python
DESTINATION ${Python_INSTALL_SITELIB}/nvdiffrast)
Thank you this looks great!
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 to lib/python3.10/site-packages
on LinuxPython_INSTALL_SITEARCH
: e.g. expands to lib/python3.10/site-packages
on LinuxIt 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
).
I would also be interested in official support for ABI3 by FindPython3
(and FindPython
?).
Right now I use:
Python3_add_library(foo MODULE "")
target_compile_definitions(foo PRIVATE Py_LIMITED_API=0x03070000)
set_target_properties(foo PROPERTIES SUFFIX ".abi3${CMAKE_SHARED_MODULE_SUFFIX}")
Seems to work ok for me on Linux but I'm under the impression that it's not very portable.
The original post seems to cover my needs, I could use it like this IIUC:
Python3_add_library(foo MODULE ABI3 WITH_SOABI "")
target_compile_definitions(foo PRIVATE Py_LIMITED_API=0x03070000)