From 95372f3f37e6f3e391112881111203d1c59099f2 Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Sun, 25 Nov 2018 22:11:08 +0100 Subject: [PATCH] Switch to Meson This makes it easier to extend in the future. Also, it will make it easier to add (un)install targets and eventually, distribute files such as systemd services. --- .gitignore | 3 --- Makefile | 32 ------------------------- README.md | 21 +++++++++++------ cage.c | 3 +++ meson.build | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 42 deletions(-) delete mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 meson.build diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 37f212c..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -xdg-shell-protocol.c -xdg-shell-protocol.h -cage diff --git a/Makefile b/Makefile deleted file mode 100644 index cb74b91..0000000 --- a/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# WAYLAND_PROTOCOLS=/usr/share/wayland-protocols - -# # wayland-scanner is a tool which generates C headers and rigging for Wayland -# # protocols, which are specified in XML. wlroots requires you to rig these up -# # to your build system yourself and provide them in the include path. -# xdg-shell-protocol.h: -# wayland-scanner server-header \ -# $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ - -# xdg-shell-protocol.c: xdg-shell-protocol.h -# wayland-scanner private-code \ -# $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ - -debug: cage.c - $(CC) $(CFLAGS) -g -Werror -Wall -I. -DWLR_USE_UNSTABLE -DDEBUG \ - $(shell pkg-config --cflags --libs wlroots) \ - $(shell pkg-config --cflags --libs wayland-server) \ - $(shell pkg-config --cflags --libs xkbcommon) \ - -o cage $< - -release: cage.c - $(CC) $(CFLAGS) -Werror -Wall -I. -DWLR_USE_UNSTABLE \ - $(shell pkg-config --cflags --libs wlroots) \ - $(shell pkg-config --cflags --libs wayland-server) \ - $(shell pkg-config --cflags --libs xkbcommon) \ - -o cage $< - -clean: - rm -f cage - -.DEFAULT_GOAL=debug -.PHONY: debug release clean diff --git a/README.md b/README.md index 03a0501..13f5263 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,21 @@ Notable omissions from Cage, to be added in a future version: ## Building and running Cage -You can build Cage by simply running `make`. It requires wayland, -wlroots and xkbcommon to be installed. +You can build Cage with the [meson](https://mesonbuild.com/) build +system. It requires wayland, wlroots and xkbcommon to be +installed. Simply execute the following steps to build Cage: -You can run Cage by running `./cage APPLICATION`. If you run it from -within an existing X11 or Wayland session, wlroots will open a virtual -output as a window in your existing session. If you run it at a TTY, -it'll run with the KMS+DRM backend. In debug mode (`make debug`), -press Alt+Esc to quit. +``` +$ meson build +$ ninja -C build +``` + +You can run Cage by running `./build/cage APPLICATION`. If you run it +from within an existing X11 or Wayland session, it will open in a +virtual output as a window in your existing session. If you run it at +a TTY, it'll run with the KMS+DRM backend. In debug mode (default +build type with Meson), press Alt+Esc to quit. To build a release +build, use `meson build --buildtype=release`. Cage is based on the annotated source of [TinyWL](https://gist.github.com/ddevault/ae4d1cdcca97ffeb2c35f0878d75dc17). diff --git a/cage.c b/cage.c index 21917d0..ffc4e09 100644 --- a/cage.c +++ b/cage.c @@ -5,6 +5,9 @@ * * See the LICENSE file accompanying this file. */ + +#define _POSIX_C_SOURCE 200112L + #include #include #include diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4b342a5 --- /dev/null +++ b/meson.build @@ -0,0 +1,68 @@ +project('cage', 'c', + version: '0.0.1', + license: 'MIT', + default_options: [ + 'c_std=c11', + 'warning_level=3', + 'werror=true', + ], +) + +add_project_arguments( + [ + '-DWLR_USE_UNSTABLE', + '-Wall', + '-Werror', + '-Wundef', + '-Wno-unused-parameter', + ], + language: 'c', +) + +if get_option('buildtype').startswith('debug') + add_project_arguments('-DDEBUG', language : 'c') +endif + +wlroots = dependency('wlroots') +wayland_protos = dependency('wayland-protocols', version: '>=1.14') +wayland_server = dependency('wayland-server') +xkbcommon = dependency('xkbcommon') + +wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir') +wayland_scanner = find_program('wayland-scanner') +wayland_scanner_server = generator( + wayland_scanner, + output: '@BASENAME@-protocol.h', + arguments: ['server-header', '@INPUT@', '@OUTPUT@'], +) + +server_protocols = [ + [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], +] + +server_protos_headers = [] + +foreach p : server_protocols + xml = join_paths(p) + server_protos_headers += wayland_scanner_server.process(xml) +endforeach + +server_protos = declare_dependency( + sources: server_protos_headers, +) + +cage_sources = [ + 'cage.c' +] + +executable( + meson.project_name(), + cage_sources, + dependencies: [ + server_protos, + wayland_server, + wlroots, + xkbcommon, + ], + install: true, +)