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...