Repository: mesonbuild/meson

Issue:
[frameworks: 15 llvm] fails with llvm/clang 14.0.0
As pointed out here: https://github.com/mesonbuild/meson/pull/10248#issuecomment-1092454817

The error I see in the logs (`check_source_compiles: C: needs to be enabled before use.`) suggest it is https://github.com/llvm/llvm-project/issues/53950

And indeed

```diff
diff --git a/mesonbuild/dependencies/data/CMakeListsLLVM.txt b/mesonbuild/dependencies/data/CMakeListsLLVM.txt
index 9d3e41234..4084597d3 100644
--- a/mesonbuild/dependencies/data/CMakeListsLLVM.txt
+++ b/mesonbuild/dependencies/data/CMakeListsLLVM.txt
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${C
 
 set(PACKAGE_FOUND FALSE)
 
+project(MesonTemp LANGUAGES C CXX)
+
 while(TRUE)
   find_package(LLVM REQUIRED CONFIG QUIET)
```

seems to make it work here.

I see that the generic CMakeLists file has some logic to inject the language, so I'm not sure if that should be extended or if the above patch is enough.

based on the file history -> pinging @mensinda


Discussion:

Resolving patch:
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -76,10 +76,10 @@ def _original_module_name(self, module: str) -> str:
         # one module
         return module
 
-    def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None) -> None:
+    def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None, force_use_global_compilers: bool = False) -> None:
         # Gather a list of all languages to support
         self.language_list = []  # type: T.List[str]
-        if language is None:
+        if language is None or force_use_global_compilers:
             compilers = None
             if kwargs.get('native', False):
                 compilers = environment.coredata.compilers.build
diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py
--- a/mesonbuild/dependencies/dev.py
+++ b/mesonbuild/dependencies/dev.py
@@ -404,7 +404,18 @@ class LLVMDependencyCMake(CMakeDependency):
     def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]) -> None:
         self.llvm_modules = stringlistify(extract_as_list(kwargs, 'modules'))
         self.llvm_opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules'))
-        super().__init__(name, env, kwargs, language='cpp')
+
+        compilers = None
+        if kwargs.get('native', False):
+            compilers = env.coredata.compilers.build
+        else:
+            compilers = env.coredata.compilers.host
+        if not compilers or not all(x in compilers for x in ('c', 'cpp')):
+            self.is_found = False
+            mlog.warning('The LLVM dependency was not found via CMake since both a C and C++ compiler are required.')
+            return
+
+        super().__init__(name, env, kwargs, language='cpp', force_use_global_compilers=True)
 
         # Cmake will always create a statically linked binary, so don't use
         # cmake if dynamic is required


Test patch: