How to install Python package with CMake

I have a very simple Python 3 package as part of a larger project (which is mostly non-Python) that I want to install on the Python path using CMake. Suppose the following source code directory structure:

|
+---> pypackage
|         |
|         +--> __init__.py
|         |
|         \--> pymodule.py
|
much other stuff

      

For example, on Ubuntu, I would like to have pypackage / end in /usr/lib/python3/dist-packages

. Any Python script containing

from pypackage import pymodule

      

should work fine after installation.

" Finding the python site package directory with CMake " suggests invoking Python from CMake to find out this path and store it in the CMake variable. This looks like a hack to me and the answers are pretty old there. Is there a canonical way to do this (pretty normal thing IMHO) in CMake?

+3


source to share





All Articles