Repository: mesonbuild/meson

Issue:
CMake inputs/dependencies cycle error with libzmq subproject.
**Describe the bug**

Attempting to use [libzmq 4.3.2](https://github.com/zeromq/libzmq/releases/tag/v4.3.2) as a CMake subproject results in an error.

```
||-- Configuring done
||-- Generating done
||-- Build files have been written to: /home/llm96/zmqtest/build/subprojects/libzmq/__CMake_build
|
|CMake configuration: SUCCEEDED
|WARNING: CMake: path /home/llm96/zmqtest/subprojects/libzmq/../include does not exist.
|WARNING:  --> Ignoring. This can lead to build errors.
|WARNING: CMake: path /home/llm96/zmqtest/subprojects/libzmq/../include does not exist.
|WARNING:  --> Ignoring. This can lead to build errors.
 ... repeats several times ...
|WARNING: CMake: path /home/llm96/zmqtest/subprojects/libzmq/../include does not exist.
|WARNING:  --> Ignoring. This can lead to build errors.
|WARNING: CMake: path /home/llm96/zmqtest/subprojects/libzmq/../include does not exist.
|WARNING:  --> Ignoring. This can lead to build errors.
|CMake project ZeroMQ has 119 build targets.

meson.build:5:0: ERROR: Cycle in CMake inputs/dependencies detected
```

**To Reproduce**

[With this example project:](https://github.com/mesonbuild/meson/files/4395533/zmqtest.zip)
```
$ meson build
```

**Expected behavior**

Configuration runs without errors.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)?

> Native, but the same happens using the default [linux-mingw-w64-64bit](https://github.com/mesonbuild/meson/blob/master/cross/linux-mingw-w64-64bit.txt) cross-file.

* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
> Arch Linux

* what Python version are you using e.g. 3.8.0
> Python 3.8.2

* what `meson --version`
> 0.53.2

* what `ninja --version` if it's a Ninja build
> 1.10.0



Discussion:

Resolving patch:
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -163,6 +163,14 @@ def _return_first_valid_key(self, keys: T.List[str]) -> T.Optional[T.Union['Conv
     def target(self, name: str) -> T.Optional[T.Union['ConverterTarget', 'ConverterCustomTarget']]:
         return self._return_first_valid_key([self._target_key(name)])
 
+    def executable(self, name: str) -> T.Optional['ConverterTarget']:
+        tgt = self.target(name)
+        if tgt is None or not isinstance(tgt, ConverterTarget):
+            return None
+        if tgt.meson_func() != 'executable':
+            return None
+        return tgt
+
     def artifact(self, name: str) -> T.Optional[T.Union['ConverterTarget', 'ConverterCustomTarget']]:
         keys = []
         candidates = [name, OutputTargetMap.rm_so_version.sub('', name)]
@@ -659,7 +667,7 @@ def ensure_absolute(x: Path) -> Path:
             for j in i:
                 if not j:
                     continue
-                target = output_target_map.target(j)
+                target = output_target_map.executable(j)
                 cmd += [target] if target else [j]
 
             commands += [cmd]
@@ -725,7 +733,7 @@ def get_ref(self, fname: str) -> T.Optional[CustomTargetReference]:
             return None
 
     def log(self) -> None:
-        mlog.log('Custom Target', mlog.bold(self.name))
+        mlog.log('Custom Target', mlog.bold(self.name), '({})'.format(self.cmake_name))
         mlog.log('  -- command:      ', mlog.bold(str(self.command)))
         mlog.log('  -- outputs:      ', mlog.bold(str(self.outputs)))
         mlog.log('  -- conflict_map: ', mlog.bold(str(self.conflict_map)))


Test patch:
diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
--- a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt	
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt	
@@ -125,5 +125,9 @@ add_custom_target(args_test_cmd
 )
 add_custom_target(macro_name_cmd COMMAND macro_name)
 
+# Only executable targets are replaced in the command
+# all other target names are kept as is
+add_custom_target(clang-format COMMAND clang-format -i cmMod.cpp)
+
 add_dependencies(cmModLib args_test_cmd tgtCpyTest4)
 add_dependencies(args_test_cmd macro_name_cmd;gen;mycpy)