Repository: spack/spack

Issue:
Installation issue: pygmo
### Steps to reproduce the issue

`spack install pygmo`

fails like:

```
==> Installing pygmo-2.18.0-d66arqjll2nuvebkwgtqcb3mbgobh5i4
==> No binary for pygmo-2.18.0-d66arqjll2nuvebkwgtqcb3mbgobh5i4 found: installing from source
==> Using cached archive: /home/wspear/bin/SPACK/spack/var/spack/cache/_source-cache/archive/9f/9f081cc973297894af09f713f889870ac452bfb32b471f9f7ba08a5e0bb9a125.tar.gz
==> No patches needed for pygmo
==> pygmo: Executing phase: 'cmake'
==> pygmo: Executing phase: 'build'
==> pygmo: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16' 'install'

2 errors found in build log:
     158    make[1]: Entering directory '/tmp/wspear/spack-stage/spack-stage-pygmo-2.18.0-d66arqjll2nuvebkwgtqcb3mbgobh5i4/spack-build-d66arqj'
     159    make[1]: Nothing to be done for 'preinstall'.
     160    make[1]: Leaving directory '/tmp/wspear/spack-stage/spack-stage-pygmo-2.18.0-d66arqjll2nuvebkwgtqcb3mbgobh5i4/spack-build-d66arqj'
     161    Install the project...
     162    /home/wspear/bin/SPACK/spack/opt/spack/linux-ubuntu20.04-westmere/gcc-9.3.0/cmake-3.22.2-x3cl7tdot2jjqtkxedz3v2i7xjgfwstl/bin/cmake -P cmake_install.cmake
     163    -- Install configuration: "RelWithDebInfo"
  >> 164    CMake Error at pygmo/plotting/cmake_install.cmake:54 (file):
     165      file cannot create directory:
     166      /usr/lib/python3/dist-packages/pygmo/plotting.  Maybe need administrative
     167      privileges.
     168    Call Stack (most recent call first):
     169      pygmo/cmake_install.cmake:47 (include)
     170      cmake_install.cmake:47 (include)
     171
     172
  >> 173    make: *** [Makefile:103: install] Error 1

See build log for details:
  /tmp/wspear/spack-stage/spack-stage-pygmo-2.18.0-d66arqjll2nuvebkwgtqcb3mbgobh5i4/spack-build-out.txt
```

Also note: the cmake dependency is incorrect. The package needs cmake@3.17:, not @3.1:

### Information on your system

* **Spack:** 0.17.1-1011-3b64ca30c7
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-westmere
* **Concretizer:** clingo


### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/7974742/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/7974744/spack-build-out.txt)
@liuyangzhuan 

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
I don't see a CMake flag to specify where the Python libs get installed. I think we're going to need to add a patch to the build system to install to a different location. But I don't know CMake well enough to write this.
It looks like it uses the non-standard `PYGMO_INSTALL_PATH` instead of `CMAKE_INSTALL_PREFIX`: https://github.com/esa/pygmo2/blob/master/pygmo/CMakeLists.txt#L112-L118

If you do not set `PYGMO_INSTALL_PATH`, it looks like it tries to install in your python interpreter prefix.

Because why not? We were clearly bored having solved the few remaining problems with standard python packaging -- we needed another one! 🤪
Also it looks like you wouldn't see this normally; the install location is marked as "advanced":

https://github.com/esa/pygmo2/blob/master/CMakeLists.txt#L143-L144

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/pygmo/package.py b/var/spack/repos/builtin/packages/pygmo/package.py
--- a/var/spack/repos/builtin/packages/pygmo/package.py
+++ b/var/spack/repos/builtin/packages/pygmo/package.py
@@ -19,17 +19,23 @@ class Pygmo(CMakePackage):
     version('master', branch='master')
     version('2.18.0', sha256='9f081cc973297894af09f713f889870ac452bfb32b471f9f7ba08a5e0bb9a125')
 
-    depends_on('pagmo2', type=('build', 'link'))
-    depends_on('mpi', type='build')
-    depends_on('py-pybind11@2.6.0:2.6.2', type='build')
-    depends_on('cmake@3.1:', type='build')
-
     variant('shared', default=True, description='Build shared libraries')
 
-    def cmake_args(self):
+    # Run-time dependencies
+    # https://github.com/esa/pygmo2/blob/master/doc/install.rst#dependencies
+    extends('python@3.4:')
+    depends_on('pagmo2@2.18:')
+    depends_on('boost@1.60:')
+    depends_on('py-numpy', type=('build', 'run'))
+    depends_on('py-cloudpickle', type=('build', 'run'))
+
+    # Build-time dependencies
+    # https://github.com/esa/pygmo2/blob/master/doc/install.rst#installation-from-source
+    depends_on('py-pybind11@2.6:', type='build')
+    depends_on('cmake@3.17:', type='build')
 
-        args = [
+    def cmake_args(self):
+        return [
+            self.define('PYGMO_INSTALL_PATH', python_platlib),
             self.define_from_variant('BUILD_SHARED_LIBS', 'shared'),
         ]
-
-        return args


Test patch: