@@ -18,46 +18,50 @@ set_property(TARGET manifpy PROPERTY CXX_STANDARD 11)
18
18
set_property (TARGET manifpy PROPERTY CXX_STANDARD_REQUIRED ON )
19
19
set_property (TARGET manifpy PROPERTY CXX_EXTENSIONS OFF )
20
20
21
- # Detect the active site-packages folder instead of using CMAKE_INSTALL_PREFIX
22
- option (
23
- DETECT_ACTIVE_PYTHON_SITEPACKAGES
24
- "Do you want manif to detect and use the active site-package directory? (it could be a system dir)"
25
- FALSE )
26
-
27
- # Installation in the active site-packages folder (could be a system folder)
28
- if (DETECT_ACTIVE_PYTHON_SITEPACKAGES)
29
- set (PYTHON_INSTDIR "${Python3_SITELIB} /manifpy" )
30
- # Installation from the build extension of setup.py
31
- elseif (CALL_FROM_SETUP_PY)
32
- set (PYTHON_INSTDIR "${CMAKE_INSTALL_PREFIX} " )
33
- # Installation in the CMAKE_INSTALL_PREFIX
21
+ if (CALL_FROM_SETUP_PY)
22
+ # cmake-build-extension sets the full absolute path as CMAKE_INSTALL_PREFIX.
23
+ set (MANIFPY_INSTDIR "${CMAKE_INSTALL_PREFIX} " )
34
24
else ()
25
+ # 'distutils.sysconfig.get_python_lib' returns the absolute path of Python
26
+ # by default a global location managed by the distro e.g. /usr/lib/python.
27
+ #
28
+ # pybind11 and FindPython3 set respectively PYTHON_SITE_PACKAGES/Python3_SITELIB
29
+ # from 'distutils.sysconfig.get_python_lib'
30
+ #
31
+ # Those are especially annoying on Ubuntu since it has
32
+ # some hardcoded paths in python3.x/site.py
33
+ #
34
+ # `sysconfig.get_path` may return paths that does not even exists.
35
+ #
36
+ # So below we retrieve the first site-package path from 'site.getsitepackages()'.
37
+
35
38
execute_process (
36
39
COMMAND
37
- ${Python3_EXECUTABLE} -c
38
- "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=True, standard_lib=False, prefix=''))"
39
- OUTPUT_VARIABLE _PYTHON_INSTDIR)
40
- string (STRIP ${_PYTHON_INSTDIR} _PYTHON_INSTDIR_CLEAN)
41
- set (PYTHON_INSTDIR "${_PYTHON_INSTDIR_CLEAN} /manifpy" )
40
+ ${PYTHON_EXECUTABLE} -c "import site; print(site.getsitepackages()[0])"
41
+ OUTPUT_VARIABLE _PYTHON_SITE_PACKAGE OUTPUT_STRIP_TRAILING_WHITESPACE
42
+ )
43
+ set (MANIFPY_INSTDIR "${_PYTHON_SITE_PACKAGE} /manifpy" )
42
44
endif ()
43
45
46
+ message (STATUS "Installing manifpy in ${MANIFPY_INSTDIR} " )
47
+
44
48
# Setup installation path
45
- install (TARGETS manifpy DESTINATION "${PYTHON_INSTDIR } " )
49
+ install (TARGETS manifpy COMPONENT python DESTINATION "${MANIFPY_INSTDIR } " )
46
50
47
51
# Create the Python package in the build tree for testing purposes
48
- set (BUILD_TREE_PYTHON_PACKAGE "${CMAKE_BINARY_DIR} /manifpy" )
52
+ set (MANIFPY_BUILDDIR "${CMAKE_BINARY_DIR} /manifpy" )
49
53
set_target_properties (
50
54
manifpy PROPERTIES
51
55
OUTPUT_NAME _bindings
52
- LIBRARY_OUTPUT_DIRECTORY "${BUILD_TREE_PYTHON_PACKAGE } " )
56
+ LIBRARY_OUTPUT_DIRECTORY "${MANIFPY_BUILDDIR } " )
53
57
54
58
# Create the __init__.py file
55
59
file (
56
60
GENERATE
57
- OUTPUT "${BUILD_TREE_PYTHON_PACKAGE } /__init__.py"
61
+ OUTPUT "${MANIFPY_BUILDDIR } /__init__.py"
58
62
CONTENT "from manifpy._bindings import *\n " )
59
63
60
64
# Install the __init__.py file
61
65
install (
62
- FILES "${BUILD_TREE_PYTHON_PACKAGE } /__init__.py"
63
- DESTINATION ${PYTHON_INSTDIR } )
66
+ FILES "${MANIFPY_BUILDDIR } /__init__.py"
67
+ DESTINATION ${MANIFPY_INSTDIR } )
0 commit comments