Repository: spack/spack

Issue:
Installation issue: spglib cmake fails with cmake<3.24
### Steps to reproduce the issue

```console
$ spack spec -I spglib@2.2.0 ^cmake@3.23.4
Concretized
--------------------------------
 -   spglib@2.2.0%gcc@12.3.0+fortran~ipo+openmp build_system=cmake build_type=Release generator=make arch=linux-ubuntu22.04-skylake
[+]      ^cmake@3.23.4%gcc@12.3.0~doc+ncurses+ownlibs build_system=generic build_type=Release arch=linux-ubuntu22.04-skylake
[+]          ^curl@8.4.0%gcc@12.3.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-ubuntu22.04-skylake
[+]              ^nghttp2@1.57.0%gcc@12.3.0 build_system=autotools arch=linux-ubuntu22.04-skylake
[+]              ^openssl@3.1.3%gcc@12.3.0~docs+shared build_system=generic certs=mozilla arch=linux-ubuntu22.04-skylake
[+]                  ^ca-certificates-mozilla@2023-05-30%gcc@12.3.0 build_system=generic arch=linux-ubuntu22.04-skylake
[+]                  ^perl@5.38.0%gcc@12.3.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=linux-ubuntu22.04-skylake
[+]                      ^berkeley-db@18.1.40%gcc@12.3.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-ubuntu22.04-skylake
[+]                      ^bzip2@1.0.8%gcc@12.3.0~debug~pic+shared build_system=generic arch=linux-ubuntu22.04-skylake
[e]                          ^diffutils@3.8%gcc@12.3.0 build_system=autotools arch=linux-ubuntu22.04-skylake
[+]                      ^gdbm@1.23%gcc@12.3.0 build_system=autotools arch=linux-ubuntu22.04-skylake
[+]                          ^readline@8.2%gcc@12.3.0 build_system=autotools patches=bbf97f1 arch=linux-ubuntu22.04-skylake
[+]              ^pkgconf@1.9.5%gcc@12.3.0 build_system=autotools arch=linux-ubuntu22.04-skylake
[+]          ^ncurses@6.4%gcc@12.3.0~symlinks+termlib abi=none build_system=autotools arch=linux-ubuntu22.04-skylake
[+]          ^zlib-ng@2.1.5%gcc@12.3.0+compat+opt build_system=autotools arch=linux-ubuntu22.04-skylake
[+]      ^gcc-runtime@12.3.0%gcc@12.3.0 build_system=generic arch=linux-ubuntu22.04-skylake
[+]      ^gmake@4.4.1%gcc@12.3.0~guile build_system=generic arch=linux-ubuntu22.04-skylake
```


### Error message

<details><summary>Error message</summary>

<pre>
==> Installing spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42 [9/9]
==> No binary for spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42 found: installing from source
==> Using cached archive: /home/lercole/src/spack-dev/var/spack/cache/_source-cache/archive/ac/ac929e20ec9d4621411e2cdec59b1442e02506c1e546005bbe2c7f781e9bd49a.tar.gz
==> No patches needed for spglib
==> spglib: Executing phase: 'cmake'
==> Error: ProcessError: Command exited with status 1:
    '/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb/bin/cmake' '-G' 'Unix Makefiles' '-DCMAKE_INSTALL_PREFIX:STRING=/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42' '-DCMAKE_BUILD_TYPE:STRING=Release' '-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF' '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=ON' '-DCMAKE_INSTALL_RPATH:STRING=/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/lib;/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/lib64;/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/gcc-runtime-12.3.0-pvfklhweoh6sjj3mrb2q5prmepkvwqiy/lib' '-DCMAKE_PREFIX_PATH:STRING=/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb;/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/gmake-4.4.1-454qjr4n5agjmypsynkbdfwn5mslmmi2;/home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/gcc-runtime-12.3.0-pvfklhweoh6sjj3mrb2q5prmepkvwqiy' '-DSPGLIB_USE_OMP:BOOL=ON' '-DSPGLIB_WITH_Fortran:BOOL=ON' '/tmp/lercole/spack-stage/spack-stage-spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/spack-src'

5 errors found in build log:
     19    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
     20    -- Found Threads: TRUE
     21    [ 11%] Creating directories for 'gtest-populate'
     22    [ 22%] Performing download step (git clone) for 'gtest-populate'
     23    -- Avoiding repeated git clone, stamp file is up to date: '/tmp/lercole/spack-stage/spack-stage-spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/spack-build-kjdh2zl/_deps/gtest-subbuild/gtest-populate-prefix/src/gtest-populate-stamp/gtest-populate-gitinfo.txt'
     24    [ 33%] Performing update step for 'gtest-populate'
  >> 25    CMake Error at /tmp/lercole/spack-stage/spack-stage-spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/spack-build-kjdh2zl/_deps/gtest-subbuild/gtest-populate-prefix/tmp/gtest-populate-gitupdate.cmake:25 (message):
     26      Failed to get the hash for HEAD:
     27
     28
     29
  >> 30    gmake[2]: *** [CMakeFiles/gtest-populate.dir/build.make:136: gtest-populate-prefix/src/gtest-populate-stamp/gtest-populate-update] Error 1
  >> 31    gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/gtest-populate.dir/all] Error 2
  >> 32    gmake: *** [Makefile:91: all] Error 2
     33
  >> 34    CMake Error at /home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb/share/cmake-3.22/Modules/FetchContent.cmake:1087 (message):
     35      Build step for gtest failed: 2
     36    Call Stack (most recent call first):
     37      /home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb/share/cmake-3.22/Modules/FetchContent.cmake:1216:EVAL:2 (__FetchContent_directPopulate)
     38      /home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb/share/cmake-3.22/Modules/FetchContent.cmake:1216 (cmake_language)
     39      /home/lercole/src/spack-dev/opt/spack/linux-ubuntu22.04-skylake/gcc-12.3.0/cmake-3.22.1-tifrz6pqgt4ckxerucqldqx3wpnt4fcb/share/cmake-3.22/Modules/FetchContent.cmake:1259 (FetchContent_Populate)
     40      CMakeLists.txt:142 (FetchContent_MakeAvailable)

See build log for details:
  /tmp/lercole/spack-stage/spack-stage-spglib-2.2.0-kjdh2zl3kgvxhpplhrxsq5imjateho42/spack-build-out.txt
</pre></details>


### Information on your system

* **Spack:** 0.22.0.dev0 (3a1fa0c359dad8c545094b40eca3a575c59b0675)
* **Python:** 3.10.10
* **Platform:** linux-ubuntu22.04-skylake
* **Concretizer:** clingo

### Additional information

It seems to me that spglib 2.1.0+ needs cmake 3.24+. I will open a PR with this fix.
@RemiLacroix-IDRIS

### 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:
@lorisercole : Are you sure the problem is with CMake? The CMakeList mentions version 3.15 as the minimum version.

The error message seems to be Git related.
> @lorisercole : Are you sure the problem is with CMake? The CMakeList mentions version 3.15 as the minimum version.
> 
> The error message seems to be Git related.

(Sorry @RemiLacroix-IDRIS I wanted to tag @RMeli as he is the maintainer of spglib, copy-paste error...)

I tried to use different versions of CMake, and only versions 3.24+ did not show this problem.
Also, this does not happen with older versions <=2.0.2 . It is due to tests that are built by default.
I can reproduce this locally (on macOS, with `spglib@2.2~0openmp`). It appears the issue has already been reported upstream: https://github.com/spglib/spglib/issues/312.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/spglib/package.py b/var/spack/repos/builtin/packages/spglib/package.py
--- a/var/spack/repos/builtin/packages/spglib/package.py
+++ b/var/spack/repos/builtin/packages/spglib/package.py
@@ -52,6 +52,10 @@ class Spglib(CMakePackage):
 
     variant("openmp", default=True, description="Build with OpenMP support", when="@1.16.2:")
     variant("fortran", default=True, description="Build Fortran interface", when="@1.16.4:")
+    variant("tests", default=False, description="Build with tests", when="@2.1.0:")
+
+    depends_on("cmake@3.15:", type="build", when="@2.1.0:")
+    depends_on("cmake@3.24:", type="build", when="+tests")
 
     @property
     def libs(self):
@@ -62,4 +66,5 @@ def cmake_args(self):
         return [
             self.define_from_variant(pfx + "USE_OMP", "openmp"),
             self.define_from_variant(pfx + "WITH_Fortran", "fortran"),
+            self.define_from_variant(pfx + "WITH_TESTS", "tests"),
         ]


Test patch: