0

I'm developing an application using wxWidgets for the UI. The project can target Windows and Linux, I'm using meson/ninja to build.

Building in General works fine for both platforms, as long as I'm not using a Resource (.rc) file on Windows.

When I add the .rc-File, it fails to compile. I use MSYS2/mingw_w64 on Windows as the toolchain.

For testing purposes, I've created a little sample for testing and reproducing.

This sample involves the following files:

  • cpp-file, with some wxWidgets "Hello World" testcode.
  • .rc-file, defining the Theme & appicon for windows.
  • meson.build-file, configuration for meson
  • Some Icon Files

I run the following command from within MSYS2-MINGW64 CLI in Windows:

meson build_win && cd build_win && ninja

Some files/folders are generated, but the build process fails. Output from Terminal:

The Meson build system
Version: 0.53.0
Source dir: //192.168.122.1/VMShare_1/Tests/meson-test
Build dir: //192.168.122.1/VMShare_1/Tests/meson-test/build_win
Build type: native build
Project name: TestWXApp
Project version: undefined
C compiler for the host machine: cc (gcc 9.2.0 "cc (Rev2, Built by MSYS2 project) 9.2.0")
C linker for the host machine: cc GNU ld.bfd 2.33.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
C++ compiler for the host machine: c++ (gcc 9.2.0 "c++ (Rev2, Built by MSYS2 project) 9.2.0")
C++ linker for the host machine: c++ GNU ld.bfd 2.33.1
wx-config found: YES (sh C:\msys64\mingw64\bin/wx-config) 3.0.4
Run-time dependency WxWidgets found: YES 3.0.4
Windows resource compiler: GNU windres (GNU Binutils) 2.33.1
Build targets in project: 2

Found ninja.EXE-1.9.0 at C:\msys64\mingw64\bin/ninja.EXE
[1/3] Generating Windows resource for file '._resources_theme_win32.rc' with a custom command.
FAILED: ._resources_theme_win32.rc_theme_win32.o
"C:/msys64/mingw64/bin/windres.EXE" ".././resources/theme_win32.rc" "._resources_theme_win32.rc_theme_win32.o" "--preprocessor-arg=-MD" "--preprocessor-arg=-MQ._resources_theme_win32.rc_theme_win32.o" "--preprocessor-arg=-MF._resources_theme_win32.rc_theme_win32.o.d"
.././resources/theme_win32.rc:2:10: fatal error: wx/msw/wx.rc: No such file or directory
    2 | #include "wx/msw/wx.rc"
      |          ^~~~~~~~~~~~~~
compilation terminated.
C:/msys64/mingw64/bin/windres.EXE: preprocessing failed.
[2/3] Compiling C++ object TestWXApp@exe/src_wxExample.cpp.obj.
ninja: build stopped: subcommand failed.

That looks like I need to add the dependency wxWidgets for the resource compiler, but I don't figure out how.

meson.build:

project('TestWXApp', 'c')

add_languages('cpp', required : true)

src_data = []

if build_machine.system() == 'windows'
    #compile static wxWidgets on windows
    wxDep = dependency('wxwidgets',
                       version : '>=3.0.0',
                       required : true,
                       modules : ['--static', 'std', 'stc'])

    mod_rescomp = import('windows')
    src_data += mod_rescomp.compile_resources('./resources/theme_win32.rc')
else
    #build for linux
    wxDep = dependency('wxwidgets',
                       version : '>=3.0.0',
                       required : true,
                       modules : ['std', 'stc'])
endif

src_data += ['./src/wxExample.cpp']
inc_tool = include_directories('./src')

inc_res = include_directories('./resources')

executable('TestWXApp',
           sources : [src_data],
           include_directories : [inc_res],
           dependencies : wxDep)

I've put a tarball including the whole Project (+the generated build_win-folder) here: https://lots-of.space/s/NLqmJzjcrknKqbX

If more information is required, let me know. I hope someone can point me to the right direction.

Regards,

XXXBold

Update, 26.01.2020

I'm now able to build the project, however, for now it requires hardcoded paths. I've found these paths by running the wx-config within the terminal and manually copying the output:

wx-config --cppflags --static

Documentation for the resourcecompiler on meson can be found here: https://mesonbuild.com/Windows-module.html#page-description

New meson.build-file:

project('TestWXApp', 'c')

add_languages('cpp', required : true)

src_data = []

if build_machine.system() == 'windows'
    #compile static wxWidgets on windows
    wxDep = dependency('wxwidgets',
                       version : '>=3.0.0',
                       required : true,
                       modules : ['--static', 'std', 'stc'])

    mod_rescomp = import('windows')
    src_data += mod_rescomp.compile_resources('./resources/theme_win32.rc',
                                             args : ['-IC:/msys64/mingw64/lib/wx/include/msw-unicode-static-3.0',
                                                     '-IC:/msys64/mingw64/include/wx-3.0',
                                                     '-D_FILE_OFFSET_BITS=64',
                                                     '-D__WXMSW__'])

else
    #build for linux
    wxDep = dependency('wxwidgets',
                       version : '>=3.0.0',
                       required : true,
                       modules : ['std', 'stc'])
endif

src_data += ['./src/wxExample.cpp']
inc_tool = include_directories('./src')

inc_res = include_directories('./resources')

executable('TestWXApp',
           sources : [src_data],
           include_directories : [inc_res],
           dependencies : wxDep)

I'm sure there's a better way doing this...

XXXBold
  • 1
  • 3

3 Answers3

0

I don't know Meson, but you need to provide the path to wxWidgets include directory for the resource compiler (rc.exe) and not just the C++ compiler itself.

VZ.
  • 21,740
  • 3
  • 39
  • 42
0

I'm facing the same problem as you have after the update 26.01.2020.

I posted a related question: How to get the include directories from a dependency in meson build system

One workaround is to get the cppflags variable from wxDep and split it to an array and pass it to the args parameter of compile_resources. But that has the drawback of not working if any of the include paths contains a space. This is a small example:

project('project1', ['cpp'])
windows = import('windows')
src = ['main.cpp']

wxDep = dependency('wxwidgets')
wx_cppflags = wxDep.get_configtool_variable('cppflags')
wx_cppflags_arr = wx_cppflags.split(' ')

src += windows.compile_resources('test.rc', args: wx_cppflags_arr)

executable('testapp',
           sources : src,
           dependencies : wxDep)
foolo
  • 804
  • 12
  • 22
0

This is the way I do it (credit to @dcbaker, github.com/mesonbuild/meson#6897).

Indeed, wx-config has a way of giving us all necessary arguments (this sample is from my MSYS2 installation):

$ wx-config --rescomp
windres --include-dir C:/msys64/mingw64/include/wx-3.0 --define __WIN32__ --define __GNUWIN32__ --define WX_CPU_AMD64

We can run that command, remove the preceding "windres" and use the remaining string as args to compile_resources.

"There is one ugly thing in here that meson arrays don't have a good way to take slices, so I've done a little hack to remove windres from the args list"

wx_dep = dependency('wxwidgets')
raw_wx_windres_args = wx_dep.get_variable(configtool : 'rescomp').split()
wx_windres_args = []
foreach a : raw_wx_windres_args
  if a != 'windres'
    wx_windres_args += a
  endif
endforeach

win = import('windows')
rc_file = win.compile_resources('resources/windows.rc', args : wx_windres_args)