cmake: break out bar stuff to separate CMakeLists.txt

This commit is contained in:
Daniel Eklöf 2019-02-07 12:06:16 +01:00
parent 76655bc944
commit ae5029826b
19 changed files with 95 additions and 89 deletions

64
bar/CMakeLists.txt Normal file
View file

@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.7)
# X11/XCB bar backend
if (ENABLE_X11)
add_library(bar-xcb STATIC EXCLUDE_FROM_ALL xcb.c xcb.h)
target_link_libraries(bar-xcb xcb-stuff PkgConfig::cairo)
endif ()
# Wayland/wlroots bar backend
if (ENABLE_WAYLAND)
function (wayland_protocol _deps)
set(deps "")
foreach (xml_file ${ARGN})
get_filename_component(base ${xml_file} NAME_WE)
set(out_c ${base}.c)
set(out_h ${base}.h)
add_custom_command(
OUTPUT ${out_h}
COMMAND wayland-scanner client-header < ${xml_file} > ${out_h}
VERBATIM
MAIN_DEPENDENCY ${xml_file}
)
add_custom_command(
OUTPUT ${out_c}
COMMAND wayland-scanner private-code < ${xml_file} > ${out_c}
VERBATIM
MAIN_DEPENDENCY ${xml_file}
)
list(APPEND deps ${out_h})
list(APPEND deps ${out_c})
endforeach ()
set(${_deps} ${deps} PARENT_SCOPE)
endfunction ()
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
OUTPUT_VARIABLE WAYLAND_PROTOCOLS
OUTPUT_STRIP_TRAILING_WHITESPACE)
wayland_protocol(
wayland_protos
${PROJECT_SOURCE_DIR}/external/wlroots/protocol/wlr-layer-shell-unstable-v1.xml
${WAYLAND_PROTOCOLS}/stable/xdg-shell/xdg-shell.xml
${WAYLAND_PROTOCOLS}/unstable/xdg-output/xdg-output-unstable-v1.xml
)
add_library(wayland-protocols STATIC EXCLUDE_FROM_ALL ${wayland_protos})
target_include_directories(wayland-protocols PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
add_library(bar-wayland STATIC EXCLUDE_FROM_ALL wayland.c wayland.h)
target_compile_definitions(bar-wayland PRIVATE _GNU_SOURCE)
target_link_libraries(
bar-wayland wayland-protocols PkgConfig::wayland PkgConfig::cairo)
endif ()
add_library(bar STATIC EXCLUDE_FROM_ALL bar.c bar.h private.h backend.h)
target_link_libraries(bar
$<$<BOOL:${ENABLE_X11}>:bar-xcb>
$<$<BOOL:${ENABLE_WAYLAND}>:bar-wayland>
)

View file

@ -2,7 +2,7 @@
#include <stdbool.h>
#include "../bar.h"
#include "bar.h"
struct backend {
bool (*setup)(struct bar *bar);

View file

@ -1,4 +1,4 @@
#include "../bar.h"
#include "bar.h"
#include "private.h"
#include <stdlib.h>

47
bar/bar.h Normal file
View file

@ -0,0 +1,47 @@
#pragma once
#include "../color.h"
#include "../module.h"
struct bar {
int abort_fd;
void *private;
int (*run)(struct bar *bar);
void (*destroy)(struct bar *bar);
void (*refresh)(const struct bar *bar);
void (*set_cursor)(struct bar *bar, const char *cursor);
};
enum bar_location { BAR_TOP, BAR_BOTTOM };
struct bar_config {
const char *monitor;
enum bar_location location;
int height;
int left_spacing, right_spacing;
int left_margin, right_margin;
struct rgba background;
struct {
int width;
struct rgba color;
} border;
struct {
struct module **mods;
size_t count;
} left;
struct {
struct module **mods;
size_t count;
} center;
struct {
struct module **mods;
size_t count;
} right;
};
struct bar *bar_new(const struct bar_config *config);

View file

@ -3,7 +3,7 @@
#include <cairo.h>
#include <cairo-xcb.h>
#include "../bar.h"
#include "../bar/bar.h"
#include "backend.h"
struct private {