Files
waylight/CMakeLists.txt
Slendi fcf3c612a0 asdf
Signed-off-by: Slendi <slendi@socopon.com>
2025-10-04 19:10:50 +03:00

164 lines
5.9 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(skia_wayland_nodeco LANGUAGES C CXX)
# --- toolchain & opts ---------------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# --- deps (pkg-config) --------------------------------------------------------
find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
pkg_check_modules(WAYLAND_EGL REQUIRED wayland-egl)
pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(GLES2 REQUIRED glesv2)
# Skia package name varies; this works on many distros. Adjust if needed.
pkg_check_modules(SKIA REQUIRED skia)
# The protocol XMLs live here:
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
# --- scanners -----------------------------------------------------------------
find_program(WAYLAND_SCANNER wayland-scanner REQUIRED)
# waylandpp's generator; provided by the waylandpp package
# (typically installed as 'wayland-scanner++')
find_program(WAYLAND_SCANNER_PP wayland-scanner++ REQUIRED)
# --- protocol XML paths -------------------------------------------------------
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
# fallback via datarootdir if needed
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()
# last-resort search (covers odd layouts)
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(XDG_DECOR_XML
"${WAYLAND_PROTOCOLS_DIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
)
# --- generated outputs (into build dir) ---------------------------------------
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${GEN_DIR}")
# waylandpp C++ headers + code (used by the app)
set(GEN_CXX_HEADERS
"${GEN_DIR}/xdg-shell-client-protocol.hpp"
"${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.hpp"
)
set(GEN_CXX_SOURCES
"${GEN_DIR}/xdg-shell-client-protocol.cpp"
"${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.cpp"
)
# (optional) C headers + private impls (not linked, but generated)
set(GEN_C_HEADERS
"${GEN_DIR}/xdg-shell-client-protocol.h"
"${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.h"
)
set(GEN_C_PRIVATES
"${GEN_DIR}/xdg-shell-protocol.c"
"${GEN_DIR}/xdg-decoration-unstable-v1-protocol.c"
)
# --- custom commands: generate C++ (required) ---------------------------------
add_custom_command(
OUTPUT ${GEN_CXX_HEADERS} ${GEN_CXX_SOURCES}
COMMAND "${WAYLAND_SCANNER_PP}" "${XDG_SHELL_XML}" "${GEN_DIR}/xdg-shell-client-protocol.hpp" "${GEN_DIR}/xdg-shell-client-protocol.cpp"
COMMAND "${WAYLAND_SCANNER_PP}" "${XDG_DECOR_XML}" "${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.hpp" "${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.cpp"
DEPENDS "${XDG_SHELL_XML}" "${XDG_DECOR_XML}"
COMMENT "Generating waylandpp C++ protocol headers/sources with wayland-scanner++"
VERBATIM
)
# --- custom commands: generate C (optional) -----------------------------------
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"
COMMAND "${WAYLAND_SCANNER}" client-header "${XDG_DECOR_XML}" "${GEN_DIR}/xdg-decoration-unstable-v1-client-protocol.h"
COMMAND "${WAYLAND_SCANNER}" private-code "${XDG_DECOR_XML}" "${GEN_DIR}/xdg-decoration-unstable-v1-protocol.c"
DEPENDS "${XDG_SHELL_XML}" "${XDG_DECOR_XML}"
COMMENT "Generating C client headers + private code with wayland-scanner (optional)"
VERBATIM
)
add_custom_target(generate_protocols ALL
DEPENDS ${GEN_CXX_HEADERS} ${GEN_CXX_SOURCES} ${GEN_C_HEADERS} ${GEN_C_PRIVATES}
)
# --- executable ---------------------------------------------------------------
add_executable(skia_wayland
${GEN_CXX_HEADERS}
${GEN_CXX_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
add_dependencies(skia_wayland generate_protocols)
# include dirs (system + generated)
target_include_directories(skia_wayland PRIVATE
${WAYLAND_CLIENT_INCLUDE_DIRS}
${WAYLAND_EGL_INCLUDE_DIRS}
${EGL_INCLUDE_DIRS}
${GLES2_INCLUDE_DIRS}
${SKIA_INCLUDE_DIRS}
# waylandpp headers (wayland-client.hpp). If they aren't system-wide, add your path here:
# ${CMAKE_CURRENT_SOURCE_DIR}/external/waylandpp/include
${GEN_DIR}
)
# libs
target_link_libraries(skia_wayland PRIVATE
${WAYLAND_CLIENT_LIBRARIES}
${WAYLAND_EGL_LIBRARIES}
${EGL_LIBRARIES}
${GLES2_LIBRARIES}
${SKIA_LIBRARIES}
# some distros need these as well:
m
dl
pthread
)
# cflags/ldflags from pkg-config
target_compile_options(skia_wayland PRIVATE
${WAYLAND_CLIENT_CFLAGS_OTHER}
${WAYLAND_EGL_CFLAGS_OTHER}
${EGL_CFLAGS_OTHER}
${GLES2_CFLAGS_OTHER}
${SKIA_CFLAGS_OTHER}
)
target_link_options(skia_wayland PRIVATE
${WAYLAND_CLIENT_LDFLAGS_OTHER}
${WAYLAND_EGL_LDFLAGS_OTHER}
${EGL_LDFLAGS_OTHER}
${GLES2_LDFLAGS_OTHER}
${SKIA_LDFLAGS_OTHER}
)
# --- warnings -----------------------------------------------------------------
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_options(skia_wayland PRIVATE -Wall -Wextra -Wno-unused-parameter)
endif()
# --- install (optional) -------------------------------------------------------
install(TARGETS skia_wayland RUNTIME DESTINATION bin)