Repository: mesonbuild/meson

Issue:
Selection of wrong IMPORTED_LOCATION_<CONFIG> 
**Describe the bug**
```
                if 'IMPORTED_CONFIGURATIONS' in tgt.properties:
                    cfgs = [x for x in tgt.properties['IMPORTED_CONFIGURATIONS'] if x]
                    cfg = cfgs[0]
                if 'RELEASE' in cfgs:
                    cfg = 'RELEASE'
                if 'IMPORTED_IMPLIB_{}'.format(cfg) in tgt.properties:
                    libraries += [x for x in tgt.properties['IMPORTED_IMPLIB_{}'.format(cfg)] if x]
```
Always selects RELEASE configuration. (which breaks every native debug build on windows.....)

**To Reproduce**
Have a CMake config which includes IMPORTED_LOCATION_DEBUG and IMPORTED_LOCATION_RELEASE and see the build break in debug builds due to mismatching ITERATOR_DEBUG_LEVELS since meson always links the RELEASE library. 

**Expected behavior**
Selecting the correct CMake library configuration depending on some variable (maybe debug option or buildtype or another variable like CXXFLAGS if /MTd or /MDd is set)

**system parameters**
doesn't matter



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
@@ -355,9 +355,16 @@ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, sub
                 if 'CONFIGURATIONS' in tgt.properties:
                     cfgs += [x for x in tgt.properties['CONFIGURATIONS'] if x]
                     cfg = cfgs[0]
-
-                if 'RELEASE' in cfgs:
-                    cfg = 'RELEASE'
+                
+                is_debug = self.env.coredata.get_builtin_option('debug');
+                if is_debug:
+                    if 'DEBUG' in cfgs:
+                        cfg = 'DEBUG'
+                    elif 'RELEASE' in cfgs:
+                        cfg = 'RELEASE'
+                else:
+                    if 'RELEASE' in cfgs:
+                        cfg = 'RELEASE'
 
                 if 'IMPORTED_IMPLIB_{}'.format(cfg) in tgt.properties:
                     libraries += [x for x in tgt.properties['IMPORTED_IMPLIB_{}'.format(cfg)] if x]
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1443,8 +1443,15 @@ def _detect_dep(self, name: str, modules: T.List[T.Tuple[str, bool]], components
                     cfgs = [x for x in tgt.properties['IMPORTED_CONFIGURATIONS'] if x]
                     cfg = cfgs[0]
 
-                if 'RELEASE' in cfgs:
-                    cfg = 'RELEASE'
+                is_debug = self.env.coredata.get_builtin_option('debug');
+                if is_debug:
+                    if 'DEBUG' in cfgs:
+                        cfg = 'DEBUG'
+                    elif 'RELEASE' in cfgs:
+                        cfg = 'RELEASE'
+                else:
+                    if 'RELEASE' in cfgs:
+                        cfg = 'RELEASE'
 
                 if 'IMPORTED_IMPLIB_{}'.format(cfg) in tgt.properties:
                     libraries += [x for x in tgt.properties['IMPORTED_IMPLIB_{}'.format(cfg)] if x]


Test patch: