Repository: mesonbuild/meson

Issue:
BSD detect_cmake: _INCLUDED_FILE "NOTFOUND"
Hi.

On at least OpenBSD and FreeBSD, the cmake module fails to determine the compilerpath. This is because it looks at the _INCLUDED_FILE value:
```
$ cmake --system-information -G Ninja | grep _INCLUDED_FILE
```
On BSD, the output is:
```
_INCLUDED_FILE "NOTFOUND"
```
On Linux, the output is:
```
_INCLUDED_FILE "/usr/share/cmake-3.12/Modules/Platform/Linux-GNU-CXX.cmake"
```

I wonder is we could maybe use something like _INCLUDED_SYSTEM_INFO_FILE which has the following output (according to the OS):
```
/usr/local/share/cmake/Modules/Platform/OpenBSD.cmake
/usr/share/cmake-3.12/Modules/Platform/Linux.cmake"
```


Discussion:
@mensinda, you're the most knowledgable about the cmake backend I think.
Is this even an issue? I mean does the dependency detection fail because of this? The CMake dependency should avoid the entire compiler detection by presenting CMake with a "fake" build directory.

Is there an easy way to reproduce the error (I have never worked with any BSD)?
@mensinda I am not sure whether this has real world consequences. I run into this when running the meson regress tests on BSD.
To reproduce on Linux, just edit the CmakeModule class in mesonbuild/modules/cmake.py and replace _INCLUDED_FILE with some random garbage (e.g. _FOOBAR).
@ajacoutot I thought you were talking about the CMake dependency backend... I didn't even know that this module exists. It looks like `_INCLUDED_FILE` can be replaced with `CMAKE_ROOT` anyway, since only the CMake path is stored.

Would you mind posting the results of `cmake --system-information -G Ninja | grep CMAKE_ROOT`? This should work on every platform.
Sorry I wasn't clear in my original post @mensinda :-)
Here's the output:
```
$ cmake --system-information -G Ninja | grep CMAKE_ROOT
CMAKE_ROOT "/usr/local/share/cmake"
```


Looks good to me, it should be possible to change it to `CMAKE_ROOT` then. It looks like this module was written by @hardening. Were there any special reasons for choosing `_INCLUDED_FILE` over `CMAKE_ROOT`?
Sorry for the late reply, using `CMAKE_ROOT` looks perfectly fine.

Resolving patch:
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -72,20 +72,12 @@ def detect_cmake(self):
             mlog.log('error retrieving cmake informations: returnCode={0} stdout={1} stderr={2}'.format(p.returncode, stdout, stderr))
             return False
 
-        match = re.search('\n_INCLUDED_FILE \\"([^"]+)"\n', stdout.strip())
+        match = re.search('\nCMAKE_ROOT \\"([^"]+)"\n', stdout.strip())
         if not match:
             mlog.log('unable to determine cmake root')
             return False
 
-        # compilerpath is something like '/usr/share/cmake-3.5/Modules/Platform/Linux-GNU-CXX.cmake'
-        # or 'C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-MSVC-CXX.cmake' under windows
-        compilerpath = match.group(1)
-        pos = compilerpath.find('/Modules/Platform/')
-        if pos < 0:
-            mlog.log('unknown _INCLUDED_FILE path scheme')
-            return False
-
-        cmakePath = pathlib.PurePath(compilerpath[0:pos])
+        cmakePath = pathlib.PurePath(match.group(1))
         self.cmake_root = os.path.join(*cmakePath.parts)
         self.cmake_detected = True
         return True


Test patch: