Files
waylight/CMakeLists.txt
Slendi 6e86ff41db Initial commit
Signed-off-by: Slendi <slendi@socopon.com>
2025-10-04 23:12:01 +03:00

146 lines
4.8 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(waylight LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND_CLIENT REQUIRED IMPORTED_TARGET wayland-client)
pkg_check_modules(WAYLAND_EGL REQUIRED IMPORTED_TARGET wayland-egl)
pkg_check_modules(EGL REQUIRED IMPORTED_TARGET egl)
pkg_check_modules(GLES2 REQUIRED IMPORTED_TARGET glesv2)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(LIBPORTAL REQUIRED IMPORTED_TARGET libportal)
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
pkg_check_modules(WLR_PROTOCOLS REQUIRED wlr-protocols)
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/slendidev/raylib.git
GIT_TAG "lunar"
GIT_SHALLOW 1
)
set(OPENGL_VERSION "ES 2.0")
set(PLATFORM DRM)
set(BUILD_EXAMPLES OFF)
FetchContent_MakeAvailable(raylib)
find_program(WAYLAND_SCANNER wayland-scanner REQUIRED)
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
if(NOT WAYLAND_PROTOCOLS_DIR OR NOT EXISTS "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
pkg_get_variable(_WP_DATAROOT wayland-protocols datarootdir)
if(_WP_DATAROOT AND EXISTS "${_WP_DATAROOT}/wayland-protocols")
set(WAYLAND_PROTOCOLS_DIR "${_WP_DATAROOT}/wayland-protocols")
endif()
endif()
if(NOT WAYLAND_PROTOCOLS_DIR OR NOT EXISTS "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
find_path(WAYLAND_PROTOCOLS_DIR
NAMES stable/xdg-shell/xdg-shell.xml
HINTS ${CMAKE_SYSTEM_PREFIX_PATH}
PATH_SUFFIXES wayland-protocols share/wayland-protocols
)
endif()
if(NOT WAYLAND_PROTOCOLS_DIR)
message(FATAL_ERROR "Could not locate wayland-protocols datadir (install wayland-protocols?)")
endif()
set(XDG_SHELL_XML
"${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml"
)
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${GEN_DIR}")
pkg_get_variable(WLR_PROTOCOLS_DIR wlr-protocols pkgdatadir)
if(NOT WLR_PROTOCOLS_DIR OR NOT EXISTS "${WLR_PROTOCOLS_DIR}/unstable/wlr-layer-shell-unstable-v1.xml")
find_path(WLR_PROTOCOLS_DIR
NAMES unstable/wlr-layer-shell-unstable-v1.xml
HINTS ${CMAKE_SYSTEM_PREFIX_PATH}
PATH_SUFFIXES wlr-protocols share/wlr-protocols
)
endif()
if(NOT WLR_PROTOCOLS_DIR)
message(FATAL_ERROR "Could not locate wlr-protocols datadir (install wlr-protocols?)")
endif()
set(BACKGROUND_EFFECT_XML
"${WAYLAND_PROTOCOLS_DIR}/staging/ext-background-effect/ext-background-effect-v1.xml"
)
set(WLR_LAYER_SHELL_XML
"${WLR_PROTOCOLS_DIR}/unstable/wlr-layer-shell-unstable-v1.xml"
)
set(GEN_C_HEADERS
"${GEN_DIR}/xdg-shell-client-protocol.h"
"${GEN_DIR}/wlr-layer-shell-unstable-v1-client-protocol.h"
"${GEN_DIR}/ext-background-effect-v1-client-protocol.h"
"${GEN_DIR}/blur-client-protocol.h"
)
set(GEN_C_PRIVATES
"${GEN_DIR}/xdg-shell-protocol.c"
"${GEN_DIR}/wlr-layer-shell-unstable-v1-protocol.c"
"${GEN_DIR}/ext-background-effect-v1-protocol.c"
"${GEN_DIR}/blur-protocol.c"
)
add_custom_command(
OUTPUT ${GEN_C_HEADERS} ${GEN_C_PRIVATES}
COMMAND "${WAYLAND_SCANNER}" client-header "${XDG_SHELL_XML}" "${GEN_DIR}/xdg-shell-client-protocol.h"
COMMAND "${WAYLAND_SCANNER}" private-code "${XDG_SHELL_XML}" "${GEN_DIR}/xdg-shell-protocol.c"
# ext-background-effect
COMMAND "${WAYLAND_SCANNER}" client-header "${BACKGROUND_EFFECT_XML}" "${GEN_DIR}/ext-background-effect-v1-client-protocol.h"
COMMAND "${WAYLAND_SCANNER}" private-code "${BACKGROUND_EFFECT_XML}" "${GEN_DIR}/ext-background-effect-v1-protocol.c"
# wlr-layer-shell
COMMAND "${WAYLAND_SCANNER}" client-header "${WLR_LAYER_SHELL_XML}" "${GEN_DIR}/wlr-layer-shell-unstable-v1-client-protocol.h"
COMMAND "${WAYLAND_SCANNER}" private-code "${WLR_LAYER_SHELL_XML}" "${GEN_DIR}/wlr-layer-shell-unstable-v1-protocol.c"
# org-kde-win-blur
COMMAND "${WAYLAND_SCANNER}" client-header "${CMAKE_CURRENT_SOURCE_DIR}/blur.xml" "${GEN_DIR}/blur-client-protocol.h"
COMMAND "${WAYLAND_SCANNER}" private-code "${CMAKE_CURRENT_SOURCE_DIR}/blur.xml" "${GEN_DIR}/blur-protocol.c"
DEPENDS "${XDG_SHELL_XML}" "${WLR_LAYER_SHELL_XML}"
COMMENT "Generating Wayland + wlr-layer-shell client headers and private code"
VERBATIM
)
add_custom_target(generate_protocols ALL
DEPENDS ${GEN_C_HEADERS} ${GEN_C_PRIVATES}
)
add_executable(waylight
${GEN_C_PRIVATES}
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
add_dependencies(waylight generate_protocols)
target_include_directories(waylight PRIVATE
${GEN_DIR}
)
target_link_libraries(waylight PRIVATE
PkgConfig::WAYLAND_CLIENT
PkgConfig::WAYLAND_EGL
PkgConfig::EGL
PkgConfig::GLES2
PkgConfig::GLIB
PkgConfig::LIBPORTAL
raylib
m
dl
pthread
)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(waylight PRIVATE -Wall -Wextra -Wno-unused-parameter)
endif()
install(TARGETS waylight RUNTIME DESTINATION bin)