Repository: mesonbuild/meson

Issue:
Recursive declare_dependency()
Hi Jussi,

This is somewhat related to #304 - should this work? I ran into this the other day. I have a library that depends on another library and there is a `declare_dependency` for both of them.

```
opencl_inc = include_directories('/usr/local/opencl12', '/opt/AMDAPP/include')
opencl_dep = declare_dependency(
    include_directories: opencl_inc,
    dependencies: find_library('OpenCL', dirs:'/usr/lib64'),
)

another_dep = declare_dependency(
    include_directories: another_inc,
    dependencies: opencl_dep
)

foo = executable('foo', src,
    dependencies:[another_dep],
)
```

This is the error:

```
Dependencies must be external deps
```



Discussion:
+1. I'm also running into this issue.

The workaround for this would be

```
another_dep = [declare_dependency(
    include_directories: another_inc,
), opencl_dep]
```

or (which I think I like better)

```
opencl_dep = declare_dependency(
    include_directories: opencl_inc,
    dependencies: find_library('OpenCL', dirs:'/usr/lib64'),
)

another_dep = declare_dependency(
    include_directories: another_inc,
)

another_deps = [opencl_dep, another_dep]
```

Obviously, recursive deps is by far the most ideal.

I'll try to get this fixed this weekend.


Resolving patch:
diff --git a/interpreter.py b/interpreter.py
--- a/interpreter.py
+++ b/interpreter.py
@@ -1123,7 +1123,7 @@ def func_declare_dependency(self, node, args, kwargs):
                 d = d.held_object
             except Exception:
                 pass
-            if not isinstance(d, (dependencies.Dependency, dependencies.ExternalLibrary)):
+            if not isinstance(d, (dependencies.Dependency, dependencies.ExternalLibrary, dependencies.InternalDependency)):
                 raise InterpreterException('Dependencies must be external deps')
             final_deps.append(d)
         dep = dependencies.InternalDependency(incs, libs, sources, final_deps)


Test patch:
diff --git a/test cases/linuxlike/1 pkg-config/meson.build b/test cases/linuxlike/1 pkg-config/meson.build
--- a/test cases/linuxlike/1 pkg-config/meson.build	
+++ b/test cases/linuxlike/1 pkg-config/meson.build	
@@ -7,6 +7,11 @@ exe = executable('zlibprog', 'prog.c', dependencies : dep)
 
 test('zlibtest', exe)
 
+# Test that dependencies of dependencies work.
+dep2 = declare_dependency(dependencies : dep)
+exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2)
+test('zlibtest2', exe2)
+
 # Try to find a nonexistant library to ensure requires:false works.
 
 dep = dependency('nvakuhrabnsdfasdf', required : false)
diff --git a/test cases/linuxlike/2 external library/meson.build b/test cases/linuxlike/2 external library/meson.build
--- a/test cases/linuxlike/2 external library/meson.build	
+++ b/test cases/linuxlike/2 external library/meson.build	
@@ -27,3 +27,8 @@ test('libtest', e)
 intdep = declare_dependency(dependencies : zlib)
 exe2 = executable('zprog2', 'prog.c', dependencies : intdep)
 test('libtest2', exe2)
+
+# Test that deps that use find_library deps work.
+depdep = declare_dependency(dependencies : intdep)
+exe3 = executable('zprog3', 'prog.c', dependencies : depdep)
+test('libtest3', exe3)