Repository: mesonbuild/meson

Issue:
wxWidgets dependency does not forward the modules kwarg
Trying to build a project that uses [`wxStyledTextCtrl`](http://docs.wxwidgets.org/trunk/classwx_styled_text_ctrl.html), defined in the stc "module", does not work. It appears that the dependency does not honor or forward the `modules` kwargs.

The following test project shows the problem:

`src/main.cpp`
```cpp
#include <wx/stc/stc.h>

int main(void) {
    wxStyledTextCtrl *canvas = new wxStyledTextCtrl();
    return 0;
}
```

`meson.build`
```py
project('wx-test', ['c', 'cpp'], license : 'BSD-3-Clause',
        meson_version : '>=0.41.0',
        default_options : ['cpp_std=c++11', 'b_lto=true'])
deps = []
deps += dependency('wxWidgets', version : '>=3.0.0',
                   modules : ['std', 'stc', 'gl'])
src = files('src/main.cpp')
wx_test = executable('wx-test', src,
                     install : true,
                     dependencies : deps)
```

Build output (and command):
```
$ ninja -C builddir
ninja: Entering directory `builddir'
[1/2] Compiling C++ object 'wx-test@exe/src_main.cpp.o'.
../src/main.cpp: In function ‘int main()’:
../src/main.cpp:6:23: warning: unused variable ‘canvas’ [-Wunused-variable]
     wxStyledTextCtrl *canvas = new wxStyledTextCtrl();
                       ^~~~~~
[2/2] Linking target wx-test.
FAILED: wx-test
c++  -o wx-test 'wx-test@exe/src_main.cpp.o' -flto -Wl,--no-undefined -Wl,--as-needed -pthread -Wl,--start-group -lwx_gtk2u_xrc-3.0 -lwx_gtk2u_html-3.0 -lwx_gtk2u_qa-3.0 -lwx_gtk2u_adv-3.0 -lwx_gtk2u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 -Wl,--end-group
/tmp/ccK9XIF8.ltrans0.ltrans.o: In function `wxStyledTextCtrl::wxStyledTextCtrl()':
<artificial>:(.text+0x87a): undefined reference to `vtable for wxStyledTextCtrl'
<artificial>:(.text+0x888): undefined reference to `vtable for wxStyledTextCtrl'
<artificial>:(.text+0x89a): undefined reference to `vtable for wxStyledTextCtrl'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```

```
$ objdump -TC /usr/lib/libwx_gtk2u_stc-3.0.so.0.3.0  | grep '~wxStyledTextCtrl'
000000000002f170 g    DF .text  0000000000000019  WXU_3.0     wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002ef30 g    DF .text  0000000000000212  WXU_3.0     wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002ef30 g    DF .text  0000000000000212  WXU_3.0     wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002f1a0 g    DF .text  0000000000000009  WXU_3.0     non-virtual thunk to wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002f150 g    DF .text  000000000000000c  WXU_3.0     non-virtual thunk to wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002f190 g    DF .text  0000000000000009  WXU_3.0     non-virtual thunk to wxStyledTextCtrl::~wxStyledTextCtrl()
000000000002f160 g    DF .text  000000000000000c  WXU_3.0     non-virtual thunk to wxStyledTextCtrl::~wxStyledTextCtrl()
```


Discussion:

Resolving patch:
diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py
--- a/mesonbuild/dependencies/ui.py
+++ b/mesonbuild/dependencies/ui.py
@@ -432,8 +432,8 @@ def __init__(self, environment, kwargs):
         self.requested_modules = self.get_requested(kwargs)
         # wx-config seems to have a cflags as well but since it requires C++,
         # this should be good, at least for now.
-        self.compile_args = self.get_config_value(['--cxxflags'], 'compile_args')
-        self.link_args = self.get_config_value(['--libs'], 'link_args')
+        self.compile_args = self.get_config_value(['--cxxflags'] + self.requested_modules, 'compile_args')
+        self.link_args = self.get_config_value(['--libs'] + self.requested_modules, 'link_args')
 
     def get_requested(self, kwargs):
         if 'modules' not in kwargs:


Test patch:
diff --git a/test cases/frameworks/9 wxwidgets/meson.build b/test cases/frameworks/9 wxwidgets/meson.build
--- a/test cases/frameworks/9 wxwidgets/meson.build	
+++ b/test cases/frameworks/9 wxwidgets/meson.build	
@@ -7,4 +7,9 @@ if wxd.found()
   wp = executable('wxprog', 'wxprog.cpp', dependencies : wxd)
 
   test('wxtest', wp)
+
+  # WxWidgets framework is available, we can use required here
+  wx_stc = dependency('wxwidgets', version : '>=3.0.0', modules : ['std', 'stc'])
+  stc_exe = executable('wxstc', 'wxstc.cpp', dependencies : wx_stc)
+  test('wxstctest', stc_exe)
 endif
diff --git a/test cases/frameworks/9 wxwidgets/wxstc.cpp b/test cases/frameworks/9 wxwidgets/wxstc.cpp
new file mode 100644
--- /dev/null
+++ b/test cases/frameworks/9 wxwidgets/wxstc.cpp	
@@ -0,0 +1,6 @@
+#include <wx/stc/stc.h>
+
+int main() {
+    wxStyledTextCtrl *canvas = new wxStyledTextCtrl();
+    delete canvas;
+}