Repository: mesonbuild/meson

Issue:
CMake: dependency() crashes Meson with old CMake versions
When on a system with an old CMake version, using any Meson `dependency()` statement crashes Meson.
HPC systems typically default to old version of everything, including CMake.

Maybe doing an internal version check on CMake in general would be helpful before assuming we can use CMake inside Meson?

In this particular case, CMake 2.8.12.2 was present, and any `dependency()` statement results in

```sh
Traceback (most recent call last):
  File "mesonbuild/mesonmain.py", line 129, in run
    return options.run_func(options)
  File "mesonbuild/msetup.py", line 244, in run
    app.generate()
  File "mesonbuild/msetup.py", line 159, in generate
    self._generate(env)
  File "mesonbuild/msetup.py", line 191, in _generate
    intr.run()
  File "mesonbuild/interpreter.py", line 3985, in run
    super().run()
  File "mesonbuild/interpreterbase.py", line 412, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "mesonbuild/interpreterbase.py", line 436, in evaluate_codeblock
    raise e
  File "mesonbuild/interpreterbase.py", line 430, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "mesonbuild/interpreterbase.py", line 443, in evaluate_statement
    return self.assignment(cur)
  File "mesonbuild/interpreterbase.py", line 1053, in assignment
    value = self.evaluate_statement(node.value)
  File "mesonbuild/interpreterbase.py", line 441, in evaluate_statement
    return self.function_call(cur)
  File "mesonbuild/interpreterbase.py", line 778, in function_call
    return func(node, posargs, kwargs)
  File "mesonbuild/interpreterbase.py", line 285, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "mesonbuild/interpreterbase.py", line 285, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "mesonbuild/interpreterbase.py", line 285, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "mesonbuild/interpreterbase.py", line 155, in wrapped
    ret = f(*wrapped_args, **wrapped_kwargs)
  File "mesonbuild/interpreterbase.py", line 174, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "mesonbuild/interpreter.py", line 3079, in func_dependency
    d = self.dependency_impl(name, display_name, kwargs)
  File "mesonbuild/interpreter.py", line 3126, in dependency_impl
    dep = dependencies.find_external_dependency(name, self.environment, kwargs)
  File "mesonbuild/dependencies/base.py", line 2094, in find_external_dependency          d = c()
  File "mesonbuild/dependencies/misc.py", line 55, in __init__
    cmakedep = CMakeDependency('OpenCoarrays', environment, kwargs)
  File "mesonbuild/dependencies/base.py", line 1014, in __init__
    self.cmakebin = CMakeExecutor(environment, CMakeDependency.class_cmake_version, self.for_machine, silent=self.silent)
  File "mesonbuild/cmake/executor.py", line 48, in __init__
    'The version of CMake', mlog.bold(self.cmakebin.get_path()),
AttributeError: 'NoneType' object has no attribute 'get_path'
```

```
$ cmake --version
cmake version 2.8.12.2
```



Discussion:
The version should already be checked. There should be at least a log entry. Is this the case?

Resolving patch:
diff --git a/mesonbuild/cmake/executor.py b/mesonbuild/cmake/executor.py
--- a/mesonbuild/cmake/executor.py
+++ b/mesonbuild/cmake/executor.py
@@ -43,11 +43,11 @@ def __init__(self, environment: Environment, version: str, for_machine: MachineC
             return
 
         if not version_compare(self.cmakevers, self.min_version):
-            self.cmakebin = None
             mlog.warning(
                 'The version of CMake', mlog.bold(self.cmakebin.get_path()),
                 'is', mlog.bold(self.cmakevers), 'but version', mlog.bold(self.min_version),
                 'is required')
+            self.cmakebin = None
             return
 
     def find_cmake_binary(self, environment: Environment, silent: bool = False) -> Tuple['ExternalProgram', str]:


Test patch: