Skip to content

Commit

Permalink
Create a "build systems" section
Browse files Browse the repository at this point in the history
The goal is to describe how to use them to build/cross compile,
how to detect mingw if needed, and point out differences to MSVC,
maybe even differences to Linux while at it.
  • Loading branch information
lazka committed Jan 18, 2025
1 parent fc1c2cd commit 2585142
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ nav:
- getting-started/debian.md
- getting-started/archlinux.md
- getting-started/msys2.md
- Build Systems:
- build-systems/meson.md
- contribute.md
- support.md
- donate.md
Expand Down
59 changes: 59 additions & 0 deletions web/build-systems/meson.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Meson

## Detect mingw-w64 at Configuration Time

```meson
# meson.build
cc = meson.get_compiler('c')
is_windows = host_machine.system() == 'windows'
is_mingw = is_windows and cc.get_define('__MINGW32__') != ''
if is_mingw
message('Building with mingw-w64')
else
message('Not building with mingw-w64')
endif
```

## Cross compiling on Linux

```c
// hello.c
#include <stdio.h>

int main(void) {
printf("Hello, Windows!\n");
return 0;
}
```
```ini
# cross-mingw64.txt
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
ld = 'x86_64-w64-mingw32-ld'
objcopy = 'x86_64-w64-mingw32-objcopy'
strip = 'x86_64-w64-mingw32-strip'
pkg-config = 'x86_64-w64-mingw32-pkg-config'
windres = 'x86_64-w64-mingw32-windres'
```

```meson
# meson.build
project('hello', 'c')
executable('hello', 'hello.c')
```

```console
$ meson setup builddir --cross-file cross-mingw64.txt
$ meson compile -C builddir
$ wine builddir/hello.exe
Hello, Windows!
```

0 comments on commit 2585142

Please sign in to comment.