Repository: spack/spack

Issue:
Installation issue: dd4hep fails at cmake stage
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue
Trying to install `dd4hep` on my Ubuntu 20.04 machine fails with a rather weird error message from cmake

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install dd4hep+assimp+geant4+lcio+xercesc+hepmc3 ^podio@master
```

which leads to the following error
```console
1 error found in build log:
     219    --    /home/tmadlener/tmp/spack_docker_install/spack/opt/spack/linux-ubuntu20.04-skylake/gcc-9.3.0/zstd-1.5.0-tlupiwbfa7kzhv6lznimpr5t52jaah4w;
     220    -- CMAKE_MODULE_PATH =
     221    --    /tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/cmake;
     222    -- -------------------------------------------------------------------------------
     223    --
     224    -- Configuring done
  >> 225    CMake Error in DDCAD/CMakeLists.txt:
     226      No known features for C compiler
     227    
     228      ""
     229    
     230      version .
     231    
```

It looks like cmake "forgets" about the compiler while it is configuring. However, to me this looks weird because the error seems to happen **after** cmake has successfully configured dd4hep. I have tried this with the default `cmake@3.16.3` that comes with Ubuntu 20.04, and also with `cmake@3.18.4` but the error remains unchanged. I don't think it is a problem in dd4heps cmake setup, because I can build it outside of spack. Just to make sure that it is not my spack setup that is causing any problems here, I have run everything in a fresh spack installation with default settings, but the problem remains.

Pinging the maintainers: @vvolkl, @drbenmorgan 

### Information on your system

<!-- Please include the output of `spack debug report` -->
```
* **Spack:** 0.16.2-3076-849943c63d
* **Python:** 3.8.5
* **Platform:** linux-ubuntu20.04-skylake
* **Concretizer:** original
```
<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

The `packages.yaml` as populated via `spack external find`. The only change that I added is the following, which is needed to get around a concretization conflict that appears with the original concretizer.
```
packages:
  all:
    variants: cxxstd=17
```

[packages.yaml.txt](https://github.com/spack/spack/files/6630885/packages.yaml.txt)

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
[spack-build-env.txt](https://github.com/spack/spack/files/6630873/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/6630874/spack-build-out.txt)


<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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:
Could you add `--trace` in the cmake call to maybe see more information about where the error comes from?
I don't know if there is a way to tell spack itself to run `cmake --trace`, but I did the following which is I hope more or less equivalent:

```bash
cd <spack-stage>
source spack-build-env.txt
mkdir test_build && cd test_build
cmake --trace $(cat ../spack-configure-args.txt) ../spack-src
```

Here are the final lines of the output
```console
/usr/share/cmake-3.16/Modules/WriteBasicConfigVersionFile.cmake(37):  if(NOT EXISTS ${versionTemplateFile} )
/usr/share/cmake-3.16/Modules/WriteBasicConfigVersionFile.cmake(41):  if(${CVF_VERSION} STREQUAL  )
/usr/share/cmake-3.16/Modules/WriteBasicConfigVersionFile.cmake(49):  configure_file(${versionTemplateFile} ${_filename} @ONLY )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/cmake/DD4hepMacros.cmake(96):  INSTALL(FILES ${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake DESTINATION ./cmake )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(276):  if(APPLE )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(278):  else()
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(279):  SET(ENV{DD4HEP_LIBRARY_PATH} ${LD_LIBRARY_PATH} )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(280):  SET(DD4HEP_LIBRARY_PATH ${LD_LIBRARY_PATH} )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(287):  if(APPLE )
/tmp/tmadlener/spack-stage/spack-stage-dd4hep-1.16.1-o3ccmwskwx367bllz74ljhxjrl3ddks5/spack-src/CMakeLists.txt(292):  INSTALL(EXPORT DD4hep NAMESPACE DD4hep:: FILE ${CMAKE_PROJECT_NAME}Config-targets.cmake DESTINATION cmake )
-- Configuring done
CMake Error in DDCAD/CMakeLists.txt:
  No known features for C compiler

  ""

  version .


CMake Generate step failed.  Build files cannot be regenerated correctly.
```

Apart from a more verbose cmake output, it seems unchanged to before. I have found [this cmake issue](https://gitlab.kitware.com/cmake/cmake/-/issues/19040), which seems to suffer from a similar problem. And indeed, manually fixing
```diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d800190..16988b0d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
 cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
-PROJECT( DD4hep LANGUAGES NONE)
+PROJECT( DD4hep LANGUAGES CXX C)
 SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DD4hep)
 
 #################
```

makes the whole thing work.

I have no idea at this point why this works outside of spack but does not when building with spack.
Ah... probably related to the compiler wrapper, but maybe also to the specific compiler: I need this patch for `garlic`, but only if I use the compiler from the gentoo-prefix toolchain.

```diff
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
 
 
 # project name
-PROJECT( Garlic CXX )
+PROJECT( Garlic LANGUAGES C CXX)
 
 # project version
 SET( ${PROJECT_NAME}_VERSION_MAJOR 3 ) 
```

The error message was quite explicit in my case though.
I'm guessing dd4hep only sets this for doxygen, the easiest will be to add a patch in the spack recipe, but maybe we can also change it upstream.
Can you try patching ~~this line~~ a line like this to include C
https://github.com/AIDASoft/DD4hep/blob/014222bd422f6606051e6c5a76ad2a75577f51a5/CMakeLists.txt#L48
Applying this patch makes everything work for me.

```diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d800190..121fa7fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@ ENDIF()
 #############################################################
 
 ENABLE_LANGUAGE(CXX)
+ENABLE_LANGUAGE(C)
 
 # Set C++ standard
 set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard used for compiling")
```

The only question now is: Fix it upstream in dd4hep, or include this patch in the spack recipe?
Should be no problem adding this to DD4hep.
this line 
https://github.com/AIDASoft/DD4hep/blob/014222bd422f6606051e6c5a76ad2a75577f51a5/cmake/DD4hepBuild.cmake#L202
actually enables the default languages (C CXX) when it is called, except apparently not in this case here.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/dd4hep/package.py b/var/spack/repos/builtin/packages/dd4hep/package.py
--- a/var/spack/repos/builtin/packages/dd4hep/package.py
+++ b/var/spack/repos/builtin/packages/dd4hep/package.py
@@ -24,6 +24,7 @@ class Dd4hep(CMakePackage):
     tags = ['hep']
 
     version('master', branch='master')
+    version('1.17', sha256='e56071ce5497517fe56af813828b1a5fab90f0b602b86961a277ca22be215232')
     version('1.16.1', sha256='c8b1312aa88283986f89cc008d317b3476027fd146fdb586f9f1fbbb47763f1a')
     version('1.16', sha256='ea9755cd255cf1b058e0e3cd743101ca9ca5ff79f4c60be89f9ba72b1ae5ec69')
     version('1.15', sha256='992a24bd4b3dfaffecec9d1c09e8cde2c7f89d38756879a47b23208242f4e352')
@@ -44,6 +45,9 @@ class Dd4hep(CMakePackage):
     # See https://github.com/AIDASoft/DD4hep/pull/613 .
     patch('tbb-workarounds.patch', when='@1.11')
     patch('tbb2.patch', when='@1.12.1')
+    # Workaround for failing build file generation in some cases
+    # See https://github.com/spack/spack/issues/24232
+    patch('cmake_language.patch', when='@:1.17')
 
     variant('xercesc', default=False, description="Enable 'Detector Builders' based on XercesC")
     variant('geant4', default=False, description="Enable the simulation part based on Geant4")
@@ -68,6 +72,10 @@ class Dd4hep(CMakePackage):
     depends_on('lcio', when="+lcio")
     depends_on('edm4hep', when="+edm4hep")
 
+    # See https://github.com/AIDASoft/DD4hep/pull/771
+    conflicts('^cmake@3.16:3.17.0', when='@1.15',
+              msg='cmake version with buggy FindPython breaks dd4hep cmake config')
+
     def cmake_args(self):
         spec = self.spec
         cxxstd = spec['root'].variants['cxxstd'].value


Test patch: