Repository: spack/spack

Issue:
Installation issue: cmake@3.21.4~ownlibs~ncurses
### Steps to reproduce the issue

```
$ spack install cmake@3.21.4~ownlibs~ncurses

==> Error: ProcessError: Command exited with status 11:
    './bootstrap' (...)

2 errors found in build log:
     359    -- Using system-installed LIBRHASH
     360    -- Using system-installed LIBUV
     361    -- Using system-installed NGHTTP2
     362    -- Using system-installed ZLIB
     363    -- Using system-installed ZSTD
     364    -- Could NOT find LibRHash (missing: LibRHash_LIBRARY)
  >> 365    CMake Error at CMakeLists.txt:440 (message):
     366      CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!
     367    Call Stack (most recent call first):
     368      CMakeLists.txt:777 (CMAKE_BUILD_UTILITIES)
     369
     370
     371    -- Configuring incomplete, errors occurred!
     372    See also "/build/razumov/cms-spack-repo/spack/stage/spack-stage-cmake-3.21.4-py4j4aexfhahe24xpk7y7wjmtnoqwx3f/spack-src/CMakeFiles/CMakeOutput.log".
     373    See also "/build/razumov/cms-spack-repo/spack/stage/spack-stage-cmake-3.21.4-py4j4aexfhahe24xpk7y7wjmtnoqwx3f/spack-src/CMakeFiles/CMakeError.log".
     374    ---------------------------------------------
  >> 375    Error when bootstrapping CMake:
     376    Problem while running initial CMake
     377    ---------------------------------------------

See build log for details:
  /build/razumov/cms-spack-repo/spack/stage/spack-stage-cmake-3.21.4-py4j4aexfhahe24xpk7y7wjmtnoqwx3f/spack-build-out.txt
```

### Information on your system

* **Spack:** 0.17.0
* **Python:** 3.6.8
* **Platform:** linux-centos7-broadwell
* **Concretizer:** clingo


### Additional information

Spack logs: https://gist.github.com/iarspider/fea199199cfe2fd9c94f1db5030875a2

Reason: CMake looks for `librhash.so`, but only `librhash.so.0` is installed by rhash, see https://github.com/rhash/RHash/issues/117 . 

Pinging maintainer @chuckatkins, also @adamjstewart who did rhash recipe.

### 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:
@haampie also made some changes to the cmake package recently

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/rhash/package.py b/var/spack/repos/builtin/packages/rhash/package.py
--- a/var/spack/repos/builtin/packages/rhash/package.py
+++ b/var/spack/repos/builtin/packages/rhash/package.py
@@ -3,6 +3,8 @@
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
+import os
+
 
 class Rhash(MakefilePackage):
     """RHash is a console utility for computing and verifying hash sums of
@@ -13,11 +15,18 @@ class Rhash(MakefilePackage):
     homepage = "https://sourceforge.net/projects/rhash/"
     url      = "https://github.com/rhash/RHash/archive/v1.3.5.tar.gz"
 
+    version('1.4.2', sha256='600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62')
     version('1.3.5', sha256='98e0688acae29e68c298ffbcdbb0f838864105f9b2bd8857980664435b1f1f2e')
 
+    # configure: fix clang detection on macOS
+    # Patch accepted and merged upstream, remove on next release
+    patch('https://github.com/rhash/RHash/commit/4dc506066cf1727b021e6352535a8bb315c3f8dc.patch?full_index=1',
+          when='@1.4.2', sha256='3fbfe4603d2ec5228fd198fc87ff3ee281e1f68d252c1afceaa15cba76e9b6b4')
+
     # For macOS build instructions, see:
     # https://github.com/Homebrew/homebrew-core/blob/master/Formula/rhash.rb
 
+    @when('@:1.3.5')
     def build(self, spec, prefix):
         # Doesn't build shared libraries by default
         make('PREFIX={0}'.format(prefix))
@@ -27,6 +36,11 @@ def build(self, spec, prefix):
         else:
             make('PREFIX={0}'.format(prefix), 'lib-shared')
 
+    @when('@1.3.6:')
+    def build(self, spec, prefix):
+        configure('--prefix=')
+        make()
+
     def check(self):
         # Makefile has both `test` and `check` targets:
         #
@@ -36,12 +50,19 @@ def check(self):
         # Default implmentation is to run both `make test` and `make check`.
         # `test` passes, but `check` fails, so only run `test`.
         make('test')
-        make('test-static-lib')
+        if self.spec.satisfies('@:1.3.5'):
+            make('test-static-lib')
+        else:
+            make('test-lib-static')
 
-        if not self.spec.satisfies('platform=darwin'):
+        if not self.spec.satisfies('@:1.3.5 platform=darwin'):
             make('test-shared')
-            make('test-shared-lib')
+            if self.spec.satisfies('@:1.3.5'):
+                make('test-shared-lib')
+            else:
+                make('test-lib-shared')
 
+    @when('@:1.3.5')
     def install(self, spec, prefix):
         # Some things are installed to $(DESTDIR)$(PREFIX) while other things
         # are installed to $DESTDIR/etc.
@@ -52,3 +73,25 @@ def install(self, spec, prefix):
             install('librhash/*.dylib', prefix.lib)
         else:
             make('install-lib-shared', 'DESTDIR={0}'.format(prefix), 'PREFIX=')
+            os.symlink(join_path(prefix.lib, 'librhash.so.0'),
+                       join_path(prefix.lib, 'librhash.so'))
+
+    @when('@1.3.6:')
+    def install(self, spec, prefix):
+        # Intermittent issues during installation, prefix.bin directory already exists
+        make('install', 'DESTDIR={0}'.format(prefix), parallel=False)
+        make('install-pkg-config', 'DESTDIR={0}'.format(prefix))
+        make('install-lib-so-link', 'DESTDIR={0}'.format(prefix))
+        make('install-lib-headers', 'DESTDIR={0}'.format(prefix))
+
+    @run_after('install')
+    def darwin_fix(self):
+        # The shared library is not installed correctly on Darwin; fix this
+        if self.spec.satisfies('@1.3.6: platform=darwin'):
+            # Fix RPATH for <prefix>/bin/rhash
+            old = '/lib/librhash.0.dylib'
+            new = self.prefix.lib.join('librhash.dylib')
+            install_name_tool = Executable('install_name_tool')
+            install_name_tool('-change', old, new, self.prefix.bin.rhash)
+            # Fix RPATH for <prefix>/lib/librhash.dylib
+            fix_darwin_install_name(self.prefix.lib)


Test patch: