From b0567a569b2e7475e9e0e11e2ded50f8164a88e1 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 20 Feb 2024 03:12:05 -0800 Subject: [PATCH] build(wayland): setup cmake for wayland module --- CMakeLists.txt | 13 +++++++++- shell.nix | 6 +++++ src/core/CMakeLists.txt | 5 +--- src/wayland/CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/wayland/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 12894163..29b4413b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) option(LAYERSHELL "Enable wayland layershell support" ON) +option(WAYLAND "Enable wayland support" ON) + add_compile_options(-Wall -Wextra) # nix workaround @@ -19,8 +21,17 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() -find_package(Qt6 REQUIRED COMPONENTS Gui Qml Quick QuickControls2) +set(QT_DEPS Qt6::Gui Qt6::Qml Qt6::Quick Qt6::QuickControls2) +set(QT_FPDEPS Gui Qml Quick QuickControls2) + +if (WAYLAND) + list(APPEND QT_DEPS Qt6::WaylandClient Qt6::WaylandClientPrivate) + list(APPEND QT_FPDEPS WaylandClient) +endif() + +find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS}) qt_standard_project_setup(REQUIRES 6.6) +add_subdirectory(src/wayland) add_subdirectory(src/core) diff --git a/shell.nix b/shell.nix index 3325fc5d..fab7084c 100644 --- a/shell.nix +++ b/shell.nix @@ -20,6 +20,9 @@ in pkgs.mkShell { clang-tools_17 cmake + pkg-config + wayland-scanner + qt6.wrapQtAppsHook makeWrapper ]; @@ -29,8 +32,11 @@ in pkgs.mkShell { qt6.qtdeclarative qt6.qtwayland qtlayershell + wayland + wayland-protocols ]; + QTWAYLANDSCANNER = "${pkgs.qt6.qtwayland}/libexec/qtwaylandscanner"; TIDYFOX = "${tidyfox}/lib/libtidyfox.so"; shellHook = '' diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d5cd27de..54b9fe26 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -16,10 +16,7 @@ qt_add_executable(quickshell qt_add_qml_module(quickshell URI QuickShell) -# qml type registration requires this -target_include_directories(quickshell PRIVATE src/core) - -target_link_libraries(quickshell PRIVATE Qt6::Gui Qt6::Qml Qt6::Quick Qt6::QuickControls2) +target_link_libraries(quickshell PRIVATE ${QT_DEPS} quickshell-wayland) if (LAYERSHELL) find_package(LayerShellQt REQUIRED) diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt new file mode 100644 index 00000000..89a34f18 --- /dev/null +++ b/src/wayland/CMakeLists.txt @@ -0,0 +1,52 @@ +qt_add_library(quickshell-wayland STATIC) + +qt_add_qml_module(quickshell-wayland URI QuickShell.Wayland) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protocols) + +find_package(Qt6 REQUIRED COMPONENTS WaylandClient) + +target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client) +message(STATUS Qt6::WaylandClient) + +# wayland protocols + +if (DEFINED ENV{QTWAYLANDSCANNER}) + set(qtwaylandscanner $ENV{QTWAYLANDSCANNER}) +else() + find_program(qtwaylandscanner NAMES qtwaylandscanner) +endif() + +if (qtwaylandscanner STREQUAL "qtwaylandscanner-NOTFOUND") + message(FATAL_ERROR "qtwaylandscanner not found. Set the QTWAYLANDSCANNER environment variable to specify its path explicity.") +endif() + +message(STATUS "Found qtwaylandscanner at ${qtwaylandscanner}") + +find_program(waylandscanner NAMES wayland-scanner) +message(STATUS "Found wayland-scanner at ${waylandscanner}") + +execute_process( + COMMAND pkg-config --variable=pkgdatadir wayland-protocols + OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}") + +set(PROTO_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/wl-proto) +set(PROTO_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/wl-proto) +make_directory(${PROTO_BUILD_PATH}) + +function (wl_proto name path) + execute_process(COMMAND ${waylandscanner} client-header ${path} ${PROTO_BUILD_PATH}/wayland-${name}-client-protocol.h) + execute_process(COMMAND ${waylandscanner} private-code ${path} ${PROTO_BUILD_PATH}/wayland-${name}.c) + execute_process(COMMAND ${qtwaylandscanner} client-header ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.h) + execute_process(COMMAND ${qtwaylandscanner} client-code ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) + + target_sources(quickshell-wayland PRIVATE ${PROTO_BUILD_PATH}/wayland-${name}.c) + target_sources(quickshell-wayland PRIVATE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) +endfunction() + +target_include_directories(quickshell-wayland PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/wl-proto)